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 RemoteScriptingEngineHandlerm_RemoteScriptingEngineHandlerthe application context.protected booleanm_Requestwhether 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 voidafterSendRequest(String error)Hook method after sending the request.StringassembleRequest(RemoteCommandProcessor processor)Assembles the command into a string, including any payload.protected PropertiesassembleRequestHeader()Assembles the request header.voidbeforeSendRequest()Hook method before sending the command.protected abstract StringdoHandleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor)Handles the request.RemoteScriptingEngineHandlergetRemoteScriptingEngineHandler()Returns the application context.voidhandleRequest(RemoteScriptingEngine engine, RemoteCommandProcessor processor, RequestHandler handler)Handles the request.protected voidinitialize()Initializes the members.booleanisRequest()Returns whether the command is a request or response.Stringparse(Properties header)Parses the header information.protected voidprepareRequestPayload()Hook method for preparing the request payload,
Default implementation does nothing.voidsetRemoteScriptingEngineHandler(RemoteScriptingEngineHandler value)Sets the application context.voidsetRequest(boolean value)Sets whether the command is a request or response.StringtoString()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:
initializein classAbstractOptionHandler
-
setRemoteScriptingEngineHandler
public void setRemoteScriptingEngineHandler(RemoteScriptingEngineHandler value)
Sets the application context.- Specified by:
setRemoteScriptingEngineHandlerin interfaceRemoteCommand- Parameters:
value- the context
-
getRemoteScriptingEngineHandler
public RemoteScriptingEngineHandler getRemoteScriptingEngineHandler()
Returns the application context.- Specified by:
getRemoteScriptingEngineHandlerin 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:
setRequestin interfaceRemoteCommand- Parameters:
value- true if request
-
isRequest
public boolean isRequest()
Returns whether the command is a request or response.- Specified by:
isRequestin 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:
assembleRequestin 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:
handleRequestin 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:
parsein 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:
beforeSendRequestin interfaceRemoteCommand
-
afterSendRequest
public void afterSendRequest(String error)
Hook method after sending the request.
Default implementation does nothing.- Specified by:
afterSendRequestin interfaceRemoteCommand- Parameters:
error- null if successful, otherwise error message
-
toString
public String toString()
Returns a short description of the request.- Overrides:
toStringin classAbstractOptionHandler- Returns:
- the description
-
-