Package adams.scripting.command
Class AbstractCommand
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.scripting.command.AbstractCommand
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,RemoteCommand
,Serializable
- Direct Known Subclasses:
AbstractCommandWithFlowStopping
,AbstractCommandWithResponse
,AbstractFlowAwareCommand
,DeregisterWorker
,Kill
,KillWorkers
,RegisterWorker
,SendFile
public abstract class AbstractCommand extends AbstractOptionHandler implements RemoteCommand
Ancestor for remote commands.- Version:
- $Revision$
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected RemoteScriptingEngineHandler
m_RemoteScriptingEngineHandler
the application context.protected boolean
m_Request
whether the command is a request or response.-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.scripting.command.RemoteCommand
KEY_COMMAND, KEY_TYPE, VALUE_REQUEST, VALUE_RESPONSE
-
-
Constructor Summary
Constructors Constructor Description AbstractCommand()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
afterSendRequest(String error)
Hook method after sending the request.String
assembleRequest(RemoteCommandProcessor processor)
Assembles the command into a string, including any payload.protected Properties
assembleRequestHeader()
Assembles the request header.void
beforeSendRequest()
Hook method before sending the command.protected abstract String
doHandleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor)
Handles the request.RemoteScriptingEngineHandler
getRemoteScriptingEngineHandler()
Returns the application context.void
handleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor, RequestHandler handler)
Handles the request.protected void
initialize()
Initializes the members.boolean
isRequest()
Returns whether the command is a request or response.String
parse(Properties header)
Parses the header information.protected void
prepareRequestPayload()
Hook method for preparing the request payload,
Default implementation does nothing.void
setRemoteScriptingEngineHandler(RemoteScriptingEngineHandler value)
Sets the application context.void
setRequest(boolean value)
Sets whether the command is a request or response.String
toString()
Returns a short description of the request.-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, defineOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, defineOptions, getOptionManager, toCommandLine
-
Methods inherited from interface adams.scripting.command.RemoteCommand
getRequestPayload, getRequestPayloadObjects, setRequestPayload
-
-
-
-
Field Detail
-
m_RemoteScriptingEngineHandler
protected RemoteScriptingEngineHandler m_RemoteScriptingEngineHandler
the application context.
-
m_Request
protected boolean m_Request
whether the command is a request or response.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractOptionHandler
-
setRemoteScriptingEngineHandler
public void setRemoteScriptingEngineHandler(RemoteScriptingEngineHandler value)
Sets the application context.- Specified by:
setRemoteScriptingEngineHandler
in interfaceRemoteCommand
- Parameters:
value
- the context
-
getRemoteScriptingEngineHandler
public RemoteScriptingEngineHandler getRemoteScriptingEngineHandler()
Returns the application context.- Specified by:
getRemoteScriptingEngineHandler
in interfaceRemoteCommand
- Returns:
- the context, null if none set
-
setRequest
public void setRequest(boolean value)
Sets whether the command is a request or response.- Specified by:
setRequest
in interfaceRemoteCommand
- Parameters:
value
- true if request
-
isRequest
public boolean isRequest()
Returns whether the command is a request or response.- Specified by:
isRequest
in interfaceRemoteCommand
- Returns:
- true if request
-
assembleRequestHeader
protected Properties assembleRequestHeader()
Assembles the request header.- Returns:
- the request header
-
prepareRequestPayload
protected void prepareRequestPayload()
Hook method for preparing the request payload,
Default implementation does nothing.
-
assembleRequest
public String assembleRequest(RemoteCommandProcessor processor)
Assembles the command into a string, including any payload.- Specified by:
assembleRequest
in interfaceRemoteCommand
- Parameters:
processor
- the processor for formatting/parsing- Returns:
- the generated string, null if failed to assemble
-
doHandleRequest
protected abstract String doHandleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor)
Handles the request.- Parameters:
engine
- the remote engine handling the request- Returns:
- null if successful, otherwise error message
-
handleRequest
public void handleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor, RequestHandler handler)
Handles the request.- Specified by:
handleRequest
in interfaceRemoteCommand
- Parameters:
engine
- the remote engine handling the requesthandler
- for handling the requestprocessor
- the command processor to use for formatting
-
parse
public String parse(Properties header)
Parses the header information.- Specified by:
parse
in interfaceRemoteCommand
- Parameters:
header
- the header- Returns:
- null if successfully parsed, otherwise error message
-
beforeSendRequest
public void beforeSendRequest()
Hook method before sending the command.
Default implementation does nothing.- Specified by:
beforeSendRequest
in interfaceRemoteCommand
-
afterSendRequest
public void afterSendRequest(String error)
Hook method after sending the request.
Default implementation does nothing.- Specified by:
afterSendRequest
in interfaceRemoteCommand
- Parameters:
error
- null if successful, otherwise error message
-
toString
public String toString()
Returns a short description of the request.- Overrides:
toString
in classAbstractOptionHandler
- Returns:
- the description
-
-