org.safs.android
Class LocalControlRunner

java.lang.Object
  extended by org.safs.sockets.AbstractProtocolRunner
      extended by org.safs.android.LocalControlRunner
All Implemented Interfaces:
java.lang.Runnable, ConnectionListener, DebugListener, NamedListener

public class LocalControlRunner
extends AbstractProtocolRunner

This class is the "local" controller side implementation of an AbstractSocketRunner. The class provides the SocketProtocol implementation needed by the DJavaHook to communicate with the SAFS Messenger Service on an Android device or emulator.

When using the Android Emulator, the emulator must be configured to "see" Socket requests on its local port 2410 coming from the controller on port 2411. Do this with the adb forwarding command to the running emulator as follows:

adb forward tcp:2411 tcp:2410

There is an initial handshake or verification that occurs between this remote controller server and the on-device Service to confirm the device port owner is a SAFS TCP Messenger Service.

See Also:
DJavaHook, MessengerService, DroidEngine

Field Summary
 
Fields inherited from class org.safs.sockets.AbstractProtocolRunner
_debugEnabled, protocolserver, runnerlisteners
 
Constructor Summary
LocalControlRunner()
          Default no-op constructor setting the Runner to use all defaults.
LocalControlRunner(LocalControlListener listener)
          Constructor setting Runner to use all defaults while registering a LocalControlListener.
 
Method Summary
 void processProtocolMessage(java.lang.String message)
          Routine called by the asynchronous run loop when a message has been received from the remote SocketProtocol.
 boolean sendDispatchFile(java.lang.String filepath)
          Send the remote client a DISPATCHFILE message with the filepath to a file suitable for Properties loading.
 boolean sendDispatchProps(java.util.Properties trd)
          Send the remote client a DISPATCHPROPS message containing a Serialized Properties object containing all the testRecordData and other data needed for the execution of the Dispatch.
 boolean sendMessage(java.lang.String message)
          Send the remote client and arbitrary MESSAGE content.
 boolean sendShutdown()
          Send the remote client a shutdown command
 
Methods inherited from class org.safs.sockets.AbstractProtocolRunner
addListener, debug, getListenerName, onReceiveConnection, onReceiveDebug, onReceiveLocalShutdown, onReceiveRemoteShutdown, removeListener, run, sendProtocolMessage, setListenerName, shutdownThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalControlRunner

public LocalControlRunner()
Default no-op constructor setting the Runner to use all defaults. The user should change any desired remote hostname/port settings and add any DebugListeners, ConnectionListeners, and LocalControlListeners prior to starting the Runnable thread.


LocalControlRunner

public LocalControlRunner(LocalControlListener listener)
Constructor setting Runner to use all defaults while registering a LocalControlListener. The user should change any desired remote hostname/port settings prior to starting the Runnable thread.

Parameters:
listener - to register with the new instance.
Method Detail

sendDispatchProps

public boolean sendDispatchProps(java.util.Properties trd)
Send the remote client a DISPATCHPROPS message containing a Serialized Properties object containing all the testRecordData and other data needed for the execution of the Dispatch.

"dispatchprops:char[]data"

Specified by:
sendDispatchProps in class AbstractProtocolRunner
Parameters:
Properties - trd to serialize with properties.store
Returns:
true if the message was sent successfully.
See Also:
Properties.store(OutputStream, String), RemoteClientRunner.notifyDispatchProps(char[]), MessengerService.onReceiveDispatchProps(char[]), DroidEngine.onRemoteDispatchProps(java.util.Properties)

sendDispatchFile

public boolean sendDispatchFile(java.lang.String filepath)
Send the remote client a DISPATCHFILE message with the filepath to a file suitable for Properties loading.

"dispatchfile:filpath"

The remote client is expected to receive the Dispatch and forward the filepath info to the actual remote engine.

Specified by:
sendDispatchFile in class AbstractProtocolRunner
Parameters:
filepath -
Returns:
true if the message was successfully sent.
See Also:
RemoteClientRunner.notifyDispatchFile(String), MessengerService.onReceiveDispatchFile(String), DroidEngine.onRemoteDispatchFile(String)

sendMessage

public boolean sendMessage(java.lang.String message)
Send the remote client and arbitrary MESSAGE content.

The remote client is expected to forward the message to the remote engine with the "message:" prefix stripped off. These messages are NOT part of the standard SAFS protocol and it is up to the local and remote engines to know what to do with them.

Parameters:
message -
Returns:
true if the message was successfully sent.
See Also:
RemoteClientRunner.notifyMessage(String), MessengerService.onReceiveMessage(String), DroidEngine.onRemoteMessage(String)

sendShutdown

public boolean sendShutdown()
Send the remote client a shutdown command

Specified by:
sendShutdown in class AbstractProtocolRunner
Returns:
response from sendClient. false if sendClient throws an InvalidObjectException.
See Also:
RemoteClientRunner.notifyMessage(String), MessengerService.onReceiveRemoteShutdown(int), DroidEngine.onRemoteShutdown()

processProtocolMessage

public void processProtocolMessage(java.lang.String message)
Routine called by the asynchronous run loop when a message has been received from the remote SocketProtocol. This routine is used to parse and then route the message to the appropriate LocalControlListener callback functions.

Specified by:
processProtocolMessage in class AbstractProtocolRunner
See Also:
LocalControlListener