public abstract class AbstractProtocolRunner extends java.lang.Object implements java.lang.Runnable, ConnectionListener, DebugListener
SocketProtocol
.
The class provides the implementation needed by processes running on
Windows, *nix, or Mac to control a remote client complying with this SocketProtocol.
Concrete subclasses must implement the abstract processProtocolMessage(String) in order to parse and process the messages received.
Currently, this server expects remote TCP services to be accepting connections on port 2410 as required by the underlying SocketProtocol.
Currently, this server uses port 2411 to contact and attempt a connection to those remote TCP services as required by the underlying SocketProtocol.
Both sides eventually need to be able to use a broader range of ports to prevent conflicts with other system resources.
There is an initial handshake or verification that occurs between this remote controller server and the on-device Service to confirm the device port owners conform to the SocketProtocol.
Modifier and Type | Field and Description |
---|---|
boolean |
_debugEnabled
set to false to disable debug logging and improve performance.
|
SocketProtocol |
protocolserver
The underlying SocketProtocol instance performing the actual TCP communication.
|
protected java.util.Vector |
runnerlisteners
All Listeners registered with this instance--whether they be simple NamedListeners,
DebugListeners, or ConnectionListeners.
|
Constructor and Description |
---|
AbstractProtocolRunner()
Default no-op constructor setting using all defaults.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addListener(NamedListener listener)
Add any class or subclass of NamedListener to the registered Listeners list.
|
protected void |
debug(java.lang.String text)
Convenience routine to route internal debug messages to registered DebugListeners.
|
java.lang.String |
getListenerName()
|
void |
onReceiveConnection()
Notify all registered ConnectionListeners a 2-way SocketProtocol connection has been established.
|
void |
onReceiveDebug(java.lang.String message)
Send all registered DebugListeners a Debug message received from a remote source.
|
void |
onReceiveLocalShutdown(int cause)
Notify all registered ConnectionListeners the 2-way SocketProtocol connection is shutting down
on our local side.
|
void |
onReceiveRemoteShutdown(int cause)
Notify all registered ConnectionListeners the 2-way SocketProtocol connection is shutting down
from the remote side.
|
abstract void |
processProtocolMessage(java.lang.String message)
Concrete implementations must insert the parsing and processing of the messages
received from the underlying SocketProtocol.
|
boolean |
removeListener(NamedListener listener)
Remove a Listener from the list of registered Listeners for this instance.
|
void |
run()
Required Runnable interface for the Threaded execution of the underlying SocketProtocol.
|
abstract boolean |
sendDispatchFile(java.lang.String filepath)
Send the remote client a dispatch file message with the filepath to a file that
should be readable by the remote client.
|
abstract boolean |
sendDispatchProps(java.util.Properties trd)
Send the remote client a dispatch Properties message containing a Serialized
Properties object containing all the data needed for
the execution of the Dispatch.
|
boolean |
sendProtocolMessage(java.lang.String message)
Send an arbitrary message through our SocketProtocol.
|
abstract boolean |
sendShutdown()
Send a shutdown command to the remote client.
|
void |
setListenerName(java.lang.String name)
NamedListener#setListenerName(String) |
void |
shutdownThread()
Command the ProtocolRunner thread to shutdown.
|
public boolean _debugEnabled
protected java.util.Vector runnerlisteners
public SocketProtocol protocolserver
public AbstractProtocolRunner()
Subclass implementation should change any desired remote hostname/port settings and add any other Listeners prior to starting the Runnable thread.
protected void debug(java.lang.String text)
text
- public boolean addListener(NamedListener listener)
listener
- NamedListener
,
DebugListener
,
ConnectionListener
public boolean removeListener(NamedListener listener)
listener
- NamedListener
,
DebugListener
,
ConnectionListener
public void run()
Subclasses of this abstract class would not normally change or override this method regardless of being local controllers or remote clients. This routine handles both through the SocketProtocol object.
The thread constantly loops performing the following tasks:
processProtocolMessage(String)
When exiting the loop due to a shutdown, all registered ConnectionListeners will be notified
via ConnectionListener.onReceiveLocalShutdown(int)
that a "normal" shutdown has occurred.
The thread will then attempt to finish by closing the SocketProtocol communication channels.
Note that sending messages from the local SocketProtocol to the remote SocketProtocol is
NOT handled in this thread. Once the remote connection is made, registered ConnectionListeners
are notified via ConnectionListener.onReceiveConnection()
. Messages sent from the local
using class to the remote SocketProtocol are sent via sendProtocolMessage(String)
and
usually from a different Thread.
Consequently, the two-way communication should be considered asynchronous. Though it is expected
the local and remote clients will attempt to maintain whatever "synchronous" communication is
appropriate for their shared protocol implementation.
run
in interface java.lang.Runnable
sendProtocolMessage(String)
,
SocketProtocol.closeProtocolRunners()
,
shutdownThread()
public void shutdownThread()
run()
public java.lang.String getListenerName()
getListenerName
in interface NamedListener
public void setListenerName(java.lang.String name)
NamedListener#setListenerName(String)
public void onReceiveDebug(java.lang.String message)
onReceiveDebug
in interface DebugListener
message
- _debugEnabled
,
DebugListener.onReceiveDebug(String)
public void onReceiveConnection()
onReceiveConnection
in interface ConnectionListener
ConnectionListener.onReceiveConnection()
public void onReceiveLocalShutdown(int cause)
onReceiveLocalShutdown
in interface ConnectionListener
caus
- -- whether "normal", or not.ConnectionListener.onReceiveLocalShutdown(int)
,
SocketProtocol.STATUS_SHUTDOWN_NORMAL
,
SocketProtocol.STATUS_SHUTDOWN_REMOTE_CLIENT
public void onReceiveRemoteShutdown(int cause)
onReceiveRemoteShutdown
in interface ConnectionListener
caus
- -- whether "normal", or not.ConnectionListener.onReceiveRemoteShutdown(int)
,
SocketProtocol.STATUS_SHUTDOWN_NORMAL
,
SocketProtocol.STATUS_SHUTDOWN_REMOTE_CLIENT
public boolean sendProtocolMessage(java.lang.String message) throws java.io.InvalidObjectException
message
- java.io.InvalidObjectException
- from the underlying SocketProtocol if no connection has
yet been made.SocketProtocol.sendResponse(String)
public abstract void processProtocolMessage(java.lang.String message)
message
- public abstract boolean sendShutdown()
A remote client Protocol Runner would implement this as a do-nothing method.
public abstract boolean sendDispatchProps(java.util.Properties trd)
A remote client Protocol Runner would implement this as a do-nothing method.
Properties
- trd to sendpublic abstract boolean sendDispatchFile(java.lang.String filepath)
A remote client Protocol Runner would implement this as a do-nothing method.
filepath
- path to a remote client readable file.Copyright © SAS Institute. All Rights Reserved.