public class SoloRemoteControl extends java.lang.Object implements SocketProtocolListener, DebugListener
Modifier and Type | Field and Description |
---|---|
int |
controllerPort |
boolean |
enableProtocolDebug |
boolean |
enableRunnerDebug |
static java.lang.String |
listenername |
protected java.util.Vector |
listeners |
(package private) boolean |
localShutdown |
(package private) java.lang.Object |
lock |
protected LogsInterface |
log |
boolean |
portForwarding |
(package private) boolean |
remoteConnected |
(package private) boolean |
remoteException |
(package private) boolean |
remoteMessage |
(package private) java.lang.String |
remoteMessageString |
(package private) boolean |
remoteReady |
(package private) boolean |
remoteResult |
(package private) int |
remoteResultCode |
(package private) java.lang.String |
remoteResultInfo |
(package private) java.util.Properties |
remoteResultProperties |
(package private) boolean |
remoteRunning |
(package private) boolean |
remoteShutdown |
static java.lang.String |
ROOT_DROID_SDK_DIR
Default: C:\Program Files\Android\android-sdk\
Set to the root directory where the Droid Development SDK is located. |
static java.lang.String |
ROOT_DROID_SDK_TOOLS
Default: C:\Program Files\Android\android-sdk\tools
Set to the directory where the Droid Development SDK Tools are located. |
protected SoloRemoteControlRunner |
runner |
protected java.lang.Thread |
runnerThread |
static AndroidTools |
sdk |
(package private) int |
shutdownCause |
DEFAULT_NAME
Constructor and Description |
---|
SoloRemoteControl()
No-arg constructor to instantiate and use all defaults.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(NamedListener listen)
Add a listener to this Runner.
|
protected void |
checkExceptions()
Throw a ShutdownInvocationException only *IF* we have received a localShutdown
or remoteShutdown message.
|
protected java.util.Properties |
consolidateResults()
Consolidates the remoteResult, remoteResultCode, and remoteResultInfo into any remoteResultProperties.
|
protected boolean |
createProtocolRunner()
Invoked from start().
|
void |
debug(java.lang.String message) |
java.lang.String |
getListenerName()
Unique name to identify the listener.
|
void |
initAndroidTools()
Set our static sdk tool to the one appropriate for the OS (Windows or Unix).
|
protected void |
modifyEmbeddedProtocol()
In this method, we can modify some properties of the embedded protocol
DroidSocketProtocol .Note: this method MUST be called after createProtocolRunner()
and before startProtocolRunner() . |
protected void |
notifyConnectionListeners() |
protected void |
notifyExceptionListeners(java.lang.String message) |
protected void |
notifyLocalShutdownListeners(int cause) |
protected void |
notifyMessageListeners(java.lang.String message) |
protected void |
notifyReadyListeners() |
protected void |
notifyRemoteShutdownListeners(int cause) |
protected void |
notifyResultPropsListeners(java.util.Properties props) |
protected void |
notifyResultsListeners(int rc,
java.lang.String info) |
protected void |
notifyRunningListeners() |
void |
onReceiveConnection()
Called when a 2-way sockets connection has been established.
|
void |
onReceiveDebug(java.lang.String message)
A remote client has sent a Debug message to be logged by the listener.
|
void |
onReceiveException(java.lang.String message)
Remote client has thrown/issued an Exception message.
|
void |
onReceiveLocalShutdown(int shutdownCause)
A local source has issued a SHUTDOWN event/command.
|
void |
onReceiveMessage(java.lang.String message)
Remote client has sent an arbitrary message.
|
void |
onReceiveReady()
Remote client has issued the READY event
|
void |
onReceiveRemoteShutdown(int shutdownCause)
A remote source has issued a SHUTDOWN event/command.
|
void |
onReceiveResult(int rc,
java.lang.String info)
Implemented here, but not currently used by this implementation.
|
void |
onReceiveResultProperties(java.util.Properties result)
Remote client has issued the RESULT event and is returning result information in Properties.
|
void |
onReceiveRunning()
Remote client has issued the RUNNING event--usually resulting from a DISPATCH event.
|
java.util.Properties |
performRemoteFileCommand(java.lang.String filepath,
int secsWaitReady,
int secsWaitRunning,
int secsWaitResult)
Default implementation performs the following:
|
void |
performRemoteMessageCommand(java.lang.String message,
int secsWaitReady,
int secsWaitRunning)
Default implementation performs the following:
|
java.util.Properties |
performRemotePropsCommand(java.util.Properties props,
int secsWaitReady,
int secsWaitRunning,
int secsWaitResult)
Default implementation performs the following:
|
void |
performRemoteShutdown(int secsWaitReady,
int secsWaitRunning,
int secsWaitShutdown)
Default implementation performs the following:
|
void |
removeListener(NamedListener listen)
Remove a previously added listener from this Runner.
|
protected void |
resetReady()
Used internally.
|
void |
resetResults()
reset the results fields and properties prior to dispatching a request.
|
void |
resetRunningState() |
void |
setControllerPort(int controllerPort)
Set the 'controller port' where we will connect for messenger service.
The 'controller port' should be an available port, if it is not, it will be modified to an available one in method modifyEmbeddedProtocol() |
void |
setLogsInterface(LogsInterface ilog)
Set the LogsInterface to be used by the class instance.
|
void |
setPortForwarding(boolean portForwarding)
Set if we will forward 'controller port' to remote messenger service's port.
|
void |
shutdown()
Command the RemoteControl infrastructure to shutdown.
|
void |
start()
Creates and Starts the asynchronous RemoteControl runner.
|
protected boolean |
startProtocolRunner()
Invoked from start().
|
void |
waitForRemoteConnected(int sTimeout)
Wait for the remote client to get connected.
|
void |
waitForRemoteReady(int sTimeout)
Wait for the remote client to signal Ready for a new command.
|
java.util.Properties |
waitForRemoteResult(int sTimeout)
Wait for the remote client to signal results are available and return those results.
|
void |
waitForRemoteRunning(int sTimeout)
Wait for the remote client to signal Running a new command.
|
void |
waitForRemoteShutdown(int sTimeout)
Wait for the remote client to signal its shutdown.
|
public static final java.lang.String listenername
public static java.lang.String ROOT_DROID_SDK_DIR
public static java.lang.String ROOT_DROID_SDK_TOOLS
protected java.util.Vector listeners
protected LogsInterface log
protected SoloRemoteControlRunner runner
protected java.lang.Thread runnerThread
public int controllerPort
public boolean portForwarding
public static AndroidTools sdk
public boolean enableProtocolDebug
public boolean enableRunnerDebug
boolean remoteException
boolean remoteMessage
java.lang.String remoteMessageString
boolean remoteReady
boolean remoteConnected
boolean remoteRunning
boolean remoteResult
int remoteResultCode
java.lang.String remoteResultInfo
java.util.Properties remoteResultProperties
boolean localShutdown
boolean remoteShutdown
int shutdownCause
java.lang.Object lock
public SoloRemoteControl()
setLogsInterface(LogsInterface)
public void initAndroidTools()
DUtilities#getAndroidTools()
public void setLogsInterface(LogsInterface ilog)
ilog
- public void addListener(NamedListener listen)
listen
- NamedListener
,
ConnectionListener
,
SoloRemoteControlListener
public void removeListener(NamedListener listen)
listen
- protected boolean createProtocolRunner()
start()
protected boolean startProtocolRunner()
start()
public void start() throws java.lang.IllegalThreadStateException
java.lang.IllegalThreadStateException
- if we were unable to create and run the protocol runner.protected void modifyEmbeddedProtocol()
DroidSocketProtocol
.createProtocolRunner()
and before startProtocolRunner()
. Just like in start()
.SocketProtocol.setControllerPort(int)
DroidSocketProtocol.setPortForwarding(boolean)
DroidSocketProtocol.adjustControllerPort()
to choose an available port for 'controller'.public void setControllerPort(int controllerPort)
modifyEmbeddedProtocol()
controllerPort
- int, an available port numbermodifyEmbeddedProtocol()
public void setPortForwarding(boolean portForwarding)
start()
is called to have affect.portForwarding
- set true if the controller should attempt port forwarding
before starting the runner thread.public void shutdown()
AbstractProtocolRunner.shutdownThread()
public void resetResults()
protected void resetReady()
protected java.util.Properties consolidateResults()
public void resetRunningState()
public void onReceiveConnection()
ConnectionListener
onReceiveConnection
in interface ConnectionListener
public void onReceiveReady()
SocketProtocolListener
onReceiveReady
in interface SocketProtocolListener
public void onReceiveRunning()
SocketProtocolListener
onReceiveRunning
in interface SocketProtocolListener
public void onReceiveResult(int rc, java.lang.String info)
onReceiveResult
in interface SocketProtocolListener
rc
- -- int statuscodeinfo
- -- String statusinfo. Can be null. Can be an empty string.onReceiveResultProperties(Properties)
public void onReceiveResultProperties(java.util.Properties result)
SocketProtocolListener
onReceiveResultProperties
in interface SocketProtocolListener
public void onReceiveException(java.lang.String message)
SocketProtocolListener
onReceiveException
in interface SocketProtocolListener
public void onReceiveMessage(java.lang.String message)
SocketProtocolListener
onReceiveMessage
in interface SocketProtocolListener
public void onReceiveLocalShutdown(int shutdownCause)
ConnectionListener
onReceiveLocalShutdown
in interface ConnectionListener
shutdownCause
- is used to indicate whether the shutdown is due to normal
or abnormal circumstances.SocketProtocol.STATUS_SHUTDOWN_NORMAL
,
SocketProtocol.STATUS_SHUTDOWN_REMOTE_CLIENT
public void onReceiveRemoteShutdown(int shutdownCause)
ConnectionListener
onReceiveRemoteShutdown
in interface ConnectionListener
shutdownCause
- is used to indicate whether the shutdown is due to normal
or abnormal circumstances.SocketProtocol.STATUS_SHUTDOWN_NORMAL
,
SocketProtocol.STATUS_SHUTDOWN_REMOTE_CLIENT
public java.lang.String getListenerName()
NamedListener
getListenerName
in interface NamedListener
public void onReceiveDebug(java.lang.String message)
DebugListener
onReceiveDebug
in interface DebugListener
public void debug(java.lang.String message)
protected void checkExceptions() throws RemoteException, ShutdownInvocationException
ShutdownInvocationException
- if localShutdown or remoteShutdown have been
received.RemoteException
- if remoteException has been received.public void waitForRemoteConnected(int sTimeout) throws java.util.concurrent.TimeoutException, RemoteException, ShutdownInvocationException
sTimeout
- in seconds to wait for connection.
If timeout is < 1 then the there is no wait.java.util.concurrent.TimeoutException
- if connection was not made in the timeout period.RemoteException
- if we received an unexpected remote exception instead.ShutdownInvocationException
- if either a local or remote shutdown has been
initiated.protected void notifyConnectionListeners()
public void waitForRemoteReady(int sTimeout) throws java.util.concurrent.TimeoutException, RemoteException, ShutdownInvocationException
sTimeout
- in seconds to wait for ready. If timeout is < 1 then there
is no wait.java.util.concurrent.TimeoutException
- if Ready was not seen in the timeout period.RemoteException
- if we received an unexpected remote exception instead.ShutdownInvocationException
- if either a local or remote shutdown has been
initiated.protected void notifyReadyListeners()
public java.util.Properties performRemotePropsCommand(java.util.Properties props, int secsWaitReady, int secsWaitRunning, int secsWaitResult) throws java.lang.IllegalThreadStateException, RemoteException, java.util.concurrent.TimeoutException, ShutdownInvocationException
resetResults(); waitForRemoteReady(secsWaitReady); runner.sendDispatchProps(props); waitForRemoteRunning(secsWaitRunning); return waitForRemoteResult(secsWaitResult);
props
- - the Dispatch Properties object containing all required command parameters for the remote client.secsWaitRead
- -- timeout in seconds to detect remoteReady.secsWaitRunning
- -- timeout in seconds to detect remoteRunning following the dispatch.secsWaitResults
- -- timeout in seconds to wait for results from the remote client.ShutdownInvocationException
java.util.concurrent.TimeoutException
RemoteException
java.lang.IllegalThreadStateException
- -- if the attempt to send the properties failed for some unknown reason.SoloRemoteControlRunner.sendDispatchProps(Properties)
public java.util.Properties performRemoteFileCommand(java.lang.String filepath, int secsWaitReady, int secsWaitRunning, int secsWaitResult) throws java.lang.IllegalThreadStateException, RemoteException, java.util.concurrent.TimeoutException, ShutdownInvocationException
resetResults(); waitForRemoteReady(secsWaitReady); runner.sendDispatchFile(filepath); waitForRemoteRunning(secsWaitRunning); return waitForRemoteResult(secsWaitResult);
filepath
- - the filepath to the File to process.secsWaitRead
- -- timeout in seconds to detect remoteReady.secsWaitRunning
- -- timeout in seconds to detect remoteRunning following the dispatch.secsWaitResults
- -- timeout in seconds to wait for results from the remote client.ShutdownInvocationException
java.util.concurrent.TimeoutException
RemoteException
java.lang.IllegalThreadStateException
- -- if the attempt to send failed for some unknown reason.SoloRemoteControlRunner.sendDispatchProps(Properties)
public void performRemoteMessageCommand(java.lang.String message, int secsWaitReady, int secsWaitRunning) throws java.lang.IllegalThreadStateException, RemoteException, java.util.concurrent.TimeoutException, ShutdownInvocationException
resetResults(); waitForRemoteReady(secsWaitReady); runner.sendMessage(message); waitForRemoteRunning(secsWaitRunning);
The routine does NOT waitForResults. This allows arbitrary messaging not always expecting a response.
message
- to send to remote clientsecsWaitRead
- -- timeout in seconds to detect remoteReady.secsWaitRunning
- -- timeout in seconds to detect remoteRunning following the dispatch.secsWaitResults
- -- timeout in seconds to wait for results from the remote client.ShutdownInvocationException
java.util.concurrent.TimeoutException
RemoteException
java.lang.IllegalThreadStateException
- -- if the attempt to send the message failed for some unknown reason.SoloRemoteControlRunner.sendDispatchProps(Properties)
public void performRemoteShutdown(int secsWaitReady, int secsWaitRunning, int secsWaitShutdown) throws java.lang.IllegalThreadStateException, RemoteException, java.util.concurrent.TimeoutException, ShutdownInvocationException
resetResults(); waitForRemoteReady(secsWaitReady); runner.sendShutdown(); waitForRemoteRunning(secsWaitRunning);
The routine does NOT waitForResults. This allows arbitrary messaging not always expecting a response.
message
- to send to remote clientsecsWaitRead
- -- timeout in seconds to detect remoteReady.secsWaitRunning
- -- timeout in seconds to detect remoteRunning following the dispatch.secsWaitShutdown
- -- timeout in seconds to wait to receive shutdown confirmation.java.util.concurrent.TimeoutException
RemoteException
java.lang.IllegalThreadStateException
- -- if the attempt to send the message failed for some unknown reason.ShutdownInvocationException
SoloRemoteControlRunner.sendDispatchProps(Properties)
public void waitForRemoteRunning(int sTimeout) throws java.util.concurrent.TimeoutException, RemoteException, ShutdownInvocationException
sTimeout
- in seconds to wait for Running. If timeout is < 1 then there
is no wait.java.util.concurrent.TimeoutException
- if Running was not seen in the timeout period.RemoteException
- if we received an unexpected remote exception instead.ShutdownInvocationException
- if either a local or remote shutdown has been
initiated.protected void notifyRunningListeners()
public java.util.Properties waitForRemoteResult(int sTimeout) throws java.util.concurrent.TimeoutException, RemoteException, ShutdownInvocationException
When a valid remote result has been received it is first checked for the presence of a special property . If that key is present then the property value is processed for a new timeout value and the routine waits for a new remote result using the new timeout value. If no new timeout is provided, or the format is non-numeric, the routine will simply wait again using the original sTimeout value.
sTimeout
- in seconds to wait for Results. If timeout is < 1 then there
is no wait.java.util.concurrent.TimeoutException
- if Results was not seen in the timeout period.RemoteException
- if we received an unexpected remote exception instead.ShutdownInvocationException
- if either a local or remote shutdown has been
initiated.consolidateResults()
protected void notifyResultsListeners(int rc, java.lang.String info)
protected void notifyResultPropsListeners(java.util.Properties props)
public void waitForRemoteShutdown(int sTimeout) throws java.util.concurrent.TimeoutException, RemoteException
sTimeout
- in seconds to wait for shutdown. If timeout is < 1 then there
is no wait.java.util.concurrent.TimeoutException
- if shutdown was not seen in the timeout period.RemoteException
- if we received an unexpected remote exception instead.protected void notifyRemoteShutdownListeners(int cause)
protected void notifyLocalShutdownListeners(int cause)
protected void notifyExceptionListeners(java.lang.String message)
protected void notifyMessageListeners(java.lang.String message)
Copyright © SAS Institute. All Rights Reserved.