public abstract class AbstractAgent<C extends ClientContext,S extends ServerContext> extends AbstractCrossPlatformObject<C,S> implements AsyncAgent<C,S>
isAsync() flag. Because the agent always contains a SessionId the server
knows who the actor is.
The Agent's main work is done by the method Agent.executeOnServer() which must be overridden accordingly.
In case of async execution you may also override executeForResponse() as well. This method
is executed synchronously before async execution is started. In fact the client receives the agent twice -
once in the response (having executeForResponse() executed) and a second time in a message
having Agent.executeOnServer() executed.
During async execution the agent should be reactive to cancellation. You achieve this by calling the method
checkCancelled() in regular time frames.
| Constructor and Description |
|---|
AbstractAgent(C clientCtx) |
AbstractAgent(C clientCtx,
boolean isAsync) |
AbstractAgent(ClientConnector conn) |
AbstractAgent(ClientConnector conn,
boolean isAsync) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkCancelled()
Throws a
CancellationException when the agent was cancelled. |
protected void |
checkPermission(PermissionControlled obj,
EspritPermission permission)
Checks whether the current user has permission on the given object for the given action.
|
void |
clearClientParams()
Clears the parameters in the client cache that have been set by this agent.
|
protected AgentId |
createAgentId(SessionId sessId) |
void |
doFinallyOnClient()
This method is called on the client, after the agent has completely been processed.
|
void |
doFinallyOnServer()
This method is called on the server, just before the agent is sent backt to the client.
|
void |
doInitiallyOnClient()
Is executed just before the agent is being sent to the server.
|
void |
doInitiallyOnServer()
This method is called on the server, when the agent is received by the server.
|
void |
doOnClientSideCancellation()
Is called by the
TaskManager when an AgentId is being cancelled. |
void |
doOnMessageError()
Is called on the client when the received agent contains an error.
|
void |
doOnMessageReceived()
Is called on the client side when the agent has been received in a message.
|
void |
doOnResponseConfirmed()
Is called on an agent when it was received in a
NetResponse AFTER the response
has been confirmed to the server. |
void |
doOnResponseError()
Is called when the returned agent contains an error.
|
void |
doOnResponseReceived()
Is called when the agent is received in a response.
|
void |
doOnServerSideCancellation()
Is called by the
AgentExecutorTask when a cancellation has been detected. |
boolean |
equals(java.lang.Object obj)
Evaluates equality by comparing the AgentId object.
|
void |
executeForResponse()
This method is called on an asynchronous agent only, before it is returned within the
NetResponse.
|
AgentId |
getAgentId()
Returns a server side unique identifier.
|
java.lang.Object |
getArgument()
Returns the optional argument of this agent.
|
<T> T |
getClientParam(java.lang.String key)
Fetches an agent specific parameter from the client cache.
|
java.util.Map |
getClientParams()
Allows an async agent to store an Agent-specific parameter in a client cache.
|
java.lang.Exception |
getError()
Returns the Exception that may have been raised during agent execution on the server.
|
SessionId |
getKillerSessionId()
Tells which foreign user has cancelled the agent
|
int |
getMessageTimeout()
Returns the async execution timeout
|
java.lang.String |
getName()
Returns a meaningful name for debugging purposes.
|
SessionId |
getOwnerSessionId()
Returns session id of the actual originator client
(which cannot be a CoClient, but just a normal client)
|
int |
getPriority()
Returns the thread priority which is used to execute this agent
|
long |
getProcessingDuration()
Returns the time (in millis) it has taken to process the agent on server side.
|
long |
getReceivedTime()
Tells when the agent was received by the client
|
java.awt.Color |
getRenderColor() |
javax.swing.Icon |
getRenderIcon() |
java.lang.String |
getRenderText() |
int |
getResponseTimeout()
Returns the desired timeout (in seconds) that should apply to this agent, or 0 if no timeout
should be used.
|
long |
getSentTime()
Tells when the agent was sent by the client
|
SessionId |
getSessionId()
Returns the SessionId of the owner of this agent
|
java.lang.String |
getTargetServer()
Returns the target server if one is set.
|
TaskId |
getTaskId()
Returns the unique identifier for this task.
|
long |
getTotalDuration()
Returns the time (in millis) it has taken from sending to finishing postprocessing of the agent.
|
long |
getTransferDuration()
Returns the time (in millis) it has taken from sending to receiving the agent.
|
protected int |
getZippedArgumentLength() |
boolean |
hasClientParam(java.lang.String key)
Checks whether an agent specific parameter exists in the client cache.
|
boolean |
hasError()
Tells whether the agent had an Exception during execution on server side.
|
int |
hashCode() |
boolean |
hasRun()
Tells whether this agent has been executed on the server.
|
boolean |
isAsync()
Tells whether the agent should be executed asynchronously on the server
in which case it is sent back to the client via a NetMessage.
|
boolean |
isIgnoreMessageError()
Tells whether errors are being ignored by the client when the agent is
received in a message.
|
boolean |
isNoReturn()
Tells whether this async agent should never be returned to the sender within a NetMessage.
|
boolean |
isPartialResultsEnabled()
Tells whether the agent supports partial results.
|
boolean |
isReceived()
Tells whether this agent yet has been received by the client.
|
boolean |
isReceivedInMessage()
Returns true if the agent has been received within a message.
|
boolean |
isReceivedInResponse()
Returns true if the agent has been received within a response.
|
boolean |
isRejectable()
Tells whether this agent can be rejected when the server is on heavy load.
|
boolean |
isTimedOut()
Tells whether the agent has been cancelled due to an async execution timeout on server side.
|
void |
logDebug(java.lang.String message) |
void |
logDump(java.lang.String message) |
void |
logError(java.lang.String message) |
void |
logError(java.lang.String message,
java.lang.Exception error) |
void |
logFatal(java.lang.String message,
java.lang.Exception error) |
void |
logInfo(java.lang.String message) |
void |
logVerbose(java.lang.String message) |
void |
logWarning(java.lang.String message) |
void |
putClientParam(java.lang.String key,
java.lang.Object value)
Putting a null value results in removing the key
|
boolean |
sendForBooleanExecution()
Same as
Agent.sendForExecution() but does not return the agent, rather it returns true if
the agent has successfully being processed, false otherwise. |
<A extends Agent<C,S>> |
sendForExecution()
Sends the agent to the server for execution and returns the readily processed agent.
|
<A extends Agent<C,S>> |
sendForSilentExecution()
Same as
Agent.sendForExecution() just without throwing an Exception. |
void |
setArgument(java.lang.Object arg)
Besides any internal variables the agent may optionally carry an arbitrary argument.
|
void |
setArgument(java.lang.Object arg,
boolean doZip)
Same as setArgument(Object) but compresses the argument to a zipped byte array.
|
void |
setAsync(boolean isAsync)
If this flag is set the agent is executed asynchronously on the server.
|
void |
setCancelledBy(SessionId killerSessId)
Marks the agent to be cancelled without performing any further
cancel action.
|
void |
setFailed(java.lang.Exception error)
Sets the internal Exception of the Agent.
|
void |
setFinished()
Is called by the server to mark this agent as being processed and stores the processing
duration.
|
void |
setIgnoreMessageError(boolean isIgnoreError)
Allows for suppressing automatic error handling.
|
void |
setMessageTimeout(int seconds)
Defines a timeout in seconds for asynchronous execution on server side before the agent is
returned in a message.
|
void |
setName(java.lang.String agentName)
Sets a meaningful name for debugging purposes.
|
void |
setNoReturn(boolean isNoReturn)
Tells whether this async agent should never be returned to the sender within a NetMessage.
|
void |
setOwnerSessionId(SessionId ownerSessId)
Sets the sessionId of the user who creates the agent
|
void |
setPartialResultsEnabled(boolean isEnabled)
Tells whether the agent supports partial results.
|
void |
setPriority(int priority)
Sets the thread priority which is used to execute this agent
|
void |
setReceivedInMessage(boolean isReceivedInMessage)
Is set when this agent has been received within a message
|
void |
setReceivedTime(long receivedTime)
Is called by the client when the agent is received
|
void |
setRejectable(boolean state)
If set to false, then the agent cannot be rejected by the server even if the server is on
heavy load.
|
void |
setResponseTimeout(int seconds)
Sets the response timeout in seconds.
|
void |
setSentTime(long sentTime)
Is called by the client when the agent is sent
|
void |
setServerContext(S serverCtx)
Sets the server runtime environment
|
void |
setSessionId(SessionId sessId)
Allows for setting the SessionId of this agent
|
void |
setTargetServer(java.lang.String targetServer)
Sets the target server.
|
void |
sleepChecked(long millis)
Used to delay async execution.
|
DumpString |
toDumpString(DumpString s)
This method creates a multi line debug output to display the full content of the agent.
|
ToString |
toString(ToString s)
This method creates a single line debug output to display the most important properties of the agent
|
boolean |
wasCancelled()
Tells whether this agent ever has been tried to be cancelled.
|
checkOnClient, checkOnServer, getClientContext, getLogChannel, getServerContext, isLogDebug, isLogVerbose, isOnClient, isOnServer, setClientContext, setLogChannelclone, deepCloneconfigureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitclearClientParams, executeOnServer, getAgentId, getArgument, getClientParam, getClientParams, getError, getName, getOwnerSessionId, getPriority, getResponseTimeout, getSessionId, getTargetServer, hasClientParam, hasError, hasRun, isPartialResultsEnabled, isReceived, isReceivedInMessage, isReceivedInResponse, isRejectable, putClientParam, sendForBooleanExecution, sendForExecution, sendForSilentExecution, setArgument, setArgument, setFailed, setFinished, setName, setOwnerSessionId, setPartialResultsEnabled, setPriority, setReceivedInMessage, setRejectable, setResponseTimeout, setSessionId, setTargetServerisOnClient, isOnServer, setClientContext, setServerContextgetClientContextgetServerContexttoDumpString, toStringdeepClonegetProcessingDuration, getReceivedTime, getSentTime, getTotalDuration, getTransferDuration, setReceivedTime, setSentTimegetLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannelpublic AbstractAgent(C clientCtx)
public AbstractAgent(C clientCtx, boolean isAsync)
public AbstractAgent(ClientConnector conn)
public AbstractAgent(ClientConnector conn, boolean isAsync)
protected final void checkPermission(PermissionControlled obj, EspritPermission permission) throws PermissionException
PermissionExceptionpublic final boolean isIgnoreMessageError()
AsyncAgentisIgnoreMessageError in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.setIgnoreMessageError(boolean)public final void setIgnoreMessageError(boolean isIgnoreError)
AsyncAgentsetIgnoreMessageError in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.isIgnoreMessageError()public final int getMessageTimeout()
AsyncAgentgetMessageTimeout in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public final void setMessageTimeout(int seconds)
AsyncAgentAgentExecutionTimeoutException. A value of zero indicates that infinite execution is allowed.
Note: a default agent async execution timeout may be set as a ServerStartup parameter
setMessageTimeout in interface AsyncAgent<C extends ClientContext,S extends ServerContext>ServerStartup.getDefaultAsyncAgentTimeout()public final boolean isTimedOut()
AsyncAgentAgentExecutionTimeoutException.isTimedOut in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public final boolean isAsync()
AsyncAgentisAsync in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.setAsync(boolean)public final void setAsync(boolean isAsync)
AsyncAgentsetAsync in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.isAsync()public void doInitiallyOnClient()
throws java.lang.Exception
AgentdoInitiallyOnClient in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doOnMessageReceived()
throws java.lang.Exception
doOnMessageReceived in interface AsyncAgent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doOnMessageError()
doOnMessageError in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public void doInitiallyOnServer()
throws java.lang.Exception
AgentdoInitiallyOnServer in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doFinallyOnServer()
throws java.lang.Exception
AgentdoFinallyOnServer in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doFinallyOnClient()
throws java.lang.Exception
AgentNote: If the client has got a GUI, this method runs in the EventDispatcher Thread.
doFinallyOnClient in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doOnResponseReceived()
throws java.lang.Exception
doOnResponseReceived in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doOnResponseConfirmed()
throws java.lang.Exception
AgentNetResponse AFTER the response
has been confirmed to the server.doOnResponseConfirmed in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic void doOnResponseError()
doOnResponseError in interface Agent<C extends ClientContext,S extends ServerContext>public void doOnClientSideCancellation()
AsyncAgentTaskManager when an AgentId is being cancelled.
Within this method the agent may perform any client-side reaction on cancellation.
Note that this method is called BEFORE the cancel-request is sent to the server.doOnClientSideCancellation in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public void doOnServerSideCancellation()
AsyncAgentAgentExecutorTask when a cancellation has been detected.
Within this method the agent may perform any server-side reaction on cancellation.doOnServerSideCancellation in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public void executeForResponse()
throws java.lang.Exception
AsyncAgentNetMessage.
Note that by this way it is possible that an asynchronous agent, which is received in a response, already may have partial results. Further results will be received within a message after the asynchronous execution has finished.
executeForResponse in interface AsyncAgent<C extends ClientContext,S extends ServerContext>java.lang.Exceptionpublic final void sleepChecked(long millis)
CancellationException is thrown just in case.java.util.concurrent.CancellationException - if cancellation was detected during sleeppublic final void checkCancelled()
CancellationException when the agent was cancelled.public boolean wasCancelled()
AsyncAgentwasCancelled in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public void setCancelledBy(SessionId killerSessId)
setCancelledBy in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public final SessionId getKillerSessionId()
AsyncAgentgetKillerSessionId in interface AsyncAgent<C extends ClientContext,S extends ServerContext>public final boolean isNoReturn()
AsyncAgentisNoReturn in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.setNoReturn(boolean)public final void setNoReturn(boolean isNoReturn)
AsyncAgentsetNoReturn in interface AsyncAgent<C extends ClientContext,S extends ServerContext>AsyncAgent.setMessageTimeout(int),
AsyncAgent.isNoReturn()public javax.swing.Icon getRenderIcon()
getRenderIcon in interface Renderablepublic java.lang.String getRenderText()
getRenderText in interface Renderablepublic java.awt.Color getRenderColor()
getRenderColor in interface Renderablepublic ToString toString(ToString s)
public DumpString toDumpString(DumpString s)
toDumpString in interface Dumpablepublic final java.util.Map getClientParams()
AgentgetClientParams in interface Agent<C extends ClientContext,S extends ServerContext>public final void putClientParam(java.lang.String key,
java.lang.Object value)
putClientParam in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getClientParams()public final <T> T getClientParam(java.lang.String key)
AgentgetClientParam in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getClientParams()public final boolean hasClientParam(java.lang.String key)
AgenthasClientParam in interface Agent<C extends ClientContext,S extends ServerContext>public final void clearClientParams()
AgentclearClientParams in interface Agent<C extends ClientContext,S extends ServerContext>public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic AgentId getAgentId()
AgentgetAgentId in interface Agent<C extends ClientContext,S extends ServerContext>public final TaskId getTaskId()
TaskIdHolderTaskId.getTaskId in interface TaskIdHolderpublic final SessionId getSessionId()
getSessionId in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setSessionId(SessionId),
Agent.getOwnerSessionId()public final void setSessionId(SessionId sessId)
AgentsetSessionId in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getSessionId()public final void setServerContext(S serverCtx)
CrossPlatformObjectsetServerContext in interface CrossPlatformObject<C extends ClientContext,S extends ServerContext>setServerContext in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>ServerObject.getServerContext()public final boolean isPartialResultsEnabled()
AgentisPartialResultsEnabled in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setPartialResultsEnabled(boolean)public final void setPartialResultsEnabled(boolean isEnabled)
AgentsetPartialResultsEnabled in interface Agent<C extends ClientContext,S extends ServerContext>Agent.isPartialResultsEnabled()public final void setRejectable(boolean state)
AgentsetRejectable in interface Agent<C extends ClientContext,S extends ServerContext>public final boolean isRejectable()
AgentisRejectable in interface Agent<C extends ClientContext,S extends ServerContext>public final SessionId getOwnerSessionId()
getOwnerSessionId in interface Agent<C extends ClientContext,S extends ServerContext>public void setOwnerSessionId(SessionId ownerSessId)
AgentsetOwnerSessionId in interface Agent<C extends ClientContext,S extends ServerContext>public final java.lang.String getTargetServer()
AgentgetTargetServer in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setTargetServer(String)public final void setTargetServer(java.lang.String targetServer)
AgentNote that target server routing is not supported for async agents.
setTargetServer in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getTargetServer()public void setName(java.lang.String agentName)
AgentsetName in interface Agent<C extends ClientContext,S extends ServerContext>public final java.lang.String getName()
AgentgetName in interface Agent<C extends ClientContext,S extends ServerContext>public final void setResponseTimeout(int seconds)
setResponseTimeout in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getResponseTimeout()public final int getResponseTimeout()
AgentgetResponseTimeout in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setResponseTimeout(int)public final boolean hasRun()
AgenthasRun in interface Agent<C extends ClientContext,S extends ServerContext>Agent.hasError()public final boolean hasError()
AgenthasError in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getError()public final java.lang.Exception getError()
AgentAgent.hasError() whether an Exception exists in the agent.getError in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setFailed(Exception),
Agent.hasError()public final void setFinished()
AgentsetFinished in interface Agent<C extends ClientContext,S extends ServerContext>CrossPlatformObject.setServerContext(ServerContext ctx)public final void setFailed(java.lang.Exception error)
AgentsetFailed in interface Agent<C extends ClientContext,S extends ServerContext>Agent.getError(),
Agent.hasError()public final boolean isReceivedInResponse()
AgentisReceivedInResponse in interface Agent<C extends ClientContext,S extends ServerContext>public final boolean isReceivedInMessage()
AgentisReceivedInMessage in interface Agent<C extends ClientContext,S extends ServerContext>Agent.setReceivedInMessage(boolean)public final void setReceivedInMessage(boolean isReceivedInMessage)
AgentsetReceivedInMessage in interface Agent<C extends ClientContext,S extends ServerContext>Agent.isReceivedInMessage()public final int getPriority()
AgentgetPriority in interface Agent<C extends ClientContext,S extends ServerContext>public final void setPriority(int priority)
AgentsetPriority in interface Agent<C extends ClientContext,S extends ServerContext>public final void setSentTime(long sentTime)
TimeMeasurablesetSentTime in interface TimeMeasurablepublic final long getSentTime()
TimeMeasurablegetSentTime in interface TimeMeasurablepublic final void setReceivedTime(long receivedTime)
TimeMeasurablesetReceivedTime in interface TimeMeasurablepublic final long getReceivedTime()
TimeMeasurablegetReceivedTime in interface TimeMeasurablepublic final boolean isReceived()
AgentisReceived in interface Agent<C extends ClientContext,S extends ServerContext>public final long getProcessingDuration()
TimeMeasurablegetProcessingDuration in interface TimeMeasurablepublic final long getTotalDuration()
TimeMeasurablegetTotalDuration in interface TimeMeasurablepublic final long getTransferDuration()
TimeMeasurablegetTransferDuration in interface TimeMeasurablepublic final void setArgument(java.lang.Object arg,
boolean doZip)
AgentsetArgument in interface Agent<C extends ClientContext,S extends ServerContext>public final void setArgument(java.lang.Object arg)
AgentsetArgument in interface Agent<C extends ClientContext,S extends ServerContext>public final java.lang.Object getArgument()
AgentgetArgument in interface Agent<C extends ClientContext,S extends ServerContext>protected final int getZippedArgumentLength()
public <A extends Agent<C,S>> A sendForExecution() throws java.lang.Exception
AgentsendForExecution in interface Agent<C extends ClientContext,S extends ServerContext>java.lang.Exception - on failureAgent.sendForSilentExecution(),
Agent.sendForBooleanExecution()public final <A extends Agent<C,S>> A sendForSilentExecution()
AgentAgent.sendForExecution() just without throwing an Exception. The returned Agent should be
manually checked if it contains an Exception.sendForSilentExecution in interface Agent<C extends ClientContext,S extends ServerContext>Agent.sendForExecution(),
Agent.sendForBooleanExecution()public final boolean sendForBooleanExecution()
AgentAgent.sendForExecution() but does not return the agent, rather it returns true if
the agent has successfully being processed, false otherwise. In the case of agent processing
failure the error Exception is stored in the original input agent and can be requested from
there.sendForBooleanExecution in interface Agent<C extends ClientContext,S extends ServerContext>Agent.sendForExecution(),
Agent.sendForSilentExecution()public final void logFatal(java.lang.String message,
java.lang.Exception error)
logFatal in interface SimpleLogSupportlogFatal in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logError(java.lang.String message,
java.lang.Exception error)
logError in interface SimpleLogSupportlogError in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logError(java.lang.String message)
logError in interface SimpleLogSupportlogError in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logWarning(java.lang.String message)
logWarning in interface SimpleLogSupportlogWarning in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logInfo(java.lang.String message)
logInfo in interface SimpleLogSupportlogInfo in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logVerbose(java.lang.String message)
logVerbose in interface SimpleLogSupportlogVerbose in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logDebug(java.lang.String message)
logDebug in interface SimpleLogSupportlogDebug in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>public final void logDump(java.lang.String message)
logDump in interface SimpleLogSupportlogDump in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>Copyright © 2014 EsprIT-Systems. All Rights Reserved.