public abstract class AbstractSequencedAgent<C extends ClientContext,S extends ServerContext> extends AbstractAgent<C,S> implements Sequenced
Note that when sequenced agent generates an error it is always sent as the last one automatically!
Note that the agent, which the client receives directly in his response, always has the sequenceId=0. The first agent received in a message has sequenceId=1. The client may receive more agents until sequenceId=maxSequendId. Finally the server will send a very last agent with the isLast flag set. The latter agent is just a marker which does not contain any valid data, but just tells the client that the sequence is done.
Constructor and Description |
---|
AbstractSequencedAgent(C clientCtx) |
AbstractSequencedAgent(C clientCtx,
int chunkSize) |
Modifier and Type | Method and Description |
---|---|
void |
clearClientParams()
Clears the parameters in the client cache that have been set by this agent.
|
protected AgentId |
createAgentId(SessionId sessId) |
protected NetMessage |
createNetMessage(AbstractSequencedAgent copiedAgent)
By default this method creates a NetMessage of type AGENT_MESSAGE
which is set to be session-private an thus sent back to the calling client only.
|
boolean |
equals(java.lang.Object obj)
Evaluates equality by comparing the AgentId object.
|
SequencedAgentId |
getAgentId()
Returns a server side unique identifier.
|
java.lang.Object |
getArgument()
Returns the optional argument of this agent.
|
int |
getChunkSize()
Returns the chunk size 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.
|
int |
getMaxSequenceId()
Returns the maximum sequenceId.
|
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
|
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
|
int |
getSequenceId()
Returns the sequence id of the agent
|
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 |
isLast()
Tells whether this is the very last agent of a sequence.
|
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.
|
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 |
processLast()
This method is called on client side, when the client receives the last agent of a sequence.
|
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 |
sendLast()
Creates and sends the very last agent of a sequence.
|
void |
sendNextSequence()
Creates and sends the next agent of a sequence with an incremented sequenceId
|
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 |
setChunkSize(int size)
Sets the chunk size, which typically is the amount of data transferred
by this agent.
|
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 |
setMaxSequenceId(int maxSequenceId) |
void |
setName(java.lang.String agentName)
Sets a meaningful name for debugging purposes.
|
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.
|
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
|
checkCancelled, checkPermission, doFinallyOnClient, doFinallyOnServer, doInitiallyOnClient, doInitiallyOnServer, doOnClientSideCancellation, doOnMessageError, doOnMessageReceived, doOnResponseConfirmed, doOnResponseError, doOnResponseReceived, doOnServerSideCancellation, executeForResponse, getKillerSessionId, getMessageTimeout, getRenderColor, getRenderIcon, getRenderText, isAsync, isIgnoreMessageError, isNoReturn, isTimedOut, setAsync, setCancelledBy, setIgnoreMessageError, setMessageTimeout, setNoReturn, sleepChecked, wasCancelled
checkOnClient, checkOnServer, getClientContext, getLogChannel, getServerContext, isLogDebug, isLogVerbose, isOnClient, isOnServer, setClientContext, setLogChannel
clone, deepClone
configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
clearClientParams, executeOnServer, 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, setTargetServer
isOnClient, isOnServer, setClientContext, setServerContext
getClientContext
getServerContext
toDumpString, toString
deepClone
getProcessingDuration, getReceivedTime, getSentTime, getTotalDuration, getTransferDuration, setReceivedTime, setSentTime
getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel
public AbstractSequencedAgent(C clientCtx)
public AbstractSequencedAgent(C clientCtx, int chunkSize)
public SequencedAgentId getAgentId()
Agent
getAgentId
in interface Agent<C extends ClientContext,S extends ServerContext>
public int getMaxSequenceId()
Sequenced
Note that in the very last agent sent (isLast flag set) the server automatically sets the MaxSequenceId to the number of agents that have been sent.
getMaxSequenceId
in interface Sequenced
public void setMaxSequenceId(int maxSequenceId)
setMaxSequenceId
in interface Sequenced
public int getSequenceId()
Sequenced
getSequenceId
in interface Sequenced
public boolean isLast()
Sequenced
isLast
in interface Sequenced
Sequenced.sendLast()
public int getChunkSize()
Sequenced
getChunkSize
in interface Sequenced
public void setChunkSize(int size)
Sequenced
setChunkSize
in interface Sequenced
public final void sendNextSequence()
Sequenced
sendNextSequence
in interface Sequenced
public final void sendLast()
Sequenced
protected NetMessage createNetMessage(AbstractSequencedAgent copiedAgent)
public void processLast()
Sequenced
processLast
in interface Sequenced
public ToString toString(ToString s)
toString
in interface Dumpable
toString
in class AbstractAgent<C extends ClientContext,S extends ServerContext>
public DumpString toDumpString(DumpString s)
toDumpString
in interface Dumpable
toDumpString
in class AbstractAgent<C extends ClientContext,S extends ServerContext>
public final java.util.Map getClientParams()
Agent
getClientParams
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)
Agent
getClientParam
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.getClientParams()
public final boolean hasClientParam(java.lang.String key)
Agent
hasClientParam
in interface Agent<C extends ClientContext,S extends ServerContext>
public final void clearClientParams()
Agent
clearClientParams
in interface Agent<C extends ClientContext,S extends ServerContext>
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public final TaskId getTaskId()
TaskIdHolder
TaskId
.getTaskId
in interface TaskIdHolder
public final SessionId getSessionId()
getSessionId
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.setSessionId(SessionId)
,
Agent.getOwnerSessionId()
public final void setSessionId(SessionId sessId)
Agent
setSessionId
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.getSessionId()
public final void setServerContext(S serverCtx)
CrossPlatformObject
setServerContext
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()
Agent
isPartialResultsEnabled
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.setPartialResultsEnabled(boolean)
public final void setPartialResultsEnabled(boolean isEnabled)
Agent
setPartialResultsEnabled
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.isPartialResultsEnabled()
public final void setRejectable(boolean state)
Agent
setRejectable
in interface Agent<C extends ClientContext,S extends ServerContext>
public final boolean isRejectable()
Agent
isRejectable
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)
Agent
setOwnerSessionId
in interface Agent<C extends ClientContext,S extends ServerContext>
public final java.lang.String getTargetServer()
Agent
getTargetServer
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.setTargetServer(String)
public final void setTargetServer(java.lang.String targetServer)
Agent
Note 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)
Agent
setName
in interface Agent<C extends ClientContext,S extends ServerContext>
public final java.lang.String getName()
Agent
getName
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()
Agent
getResponseTimeout
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.setResponseTimeout(int)
public final boolean hasRun()
Agent
hasRun
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.hasError()
public final boolean hasError()
Agent
hasError
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.getError()
public final java.lang.Exception getError()
Agent
Agent.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()
Agent
setFinished
in interface Agent<C extends ClientContext,S extends ServerContext>
CrossPlatformObject.setServerContext(ServerContext ctx)
public final void setFailed(java.lang.Exception error)
Agent
setFailed
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.getError()
,
Agent.hasError()
public final boolean isReceivedInResponse()
Agent
isReceivedInResponse
in interface Agent<C extends ClientContext,S extends ServerContext>
public final boolean isReceivedInMessage()
Agent
isReceivedInMessage
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.setReceivedInMessage(boolean)
public final void setReceivedInMessage(boolean isReceivedInMessage)
Agent
setReceivedInMessage
in interface Agent<C extends ClientContext,S extends ServerContext>
Agent.isReceivedInMessage()
public final int getPriority()
Agent
getPriority
in interface Agent<C extends ClientContext,S extends ServerContext>
public final void setPriority(int priority)
Agent
setPriority
in interface Agent<C extends ClientContext,S extends ServerContext>
public final void setSentTime(long sentTime)
TimeMeasurable
setSentTime
in interface TimeMeasurable
public final long getSentTime()
TimeMeasurable
getSentTime
in interface TimeMeasurable
public final void setReceivedTime(long receivedTime)
TimeMeasurable
setReceivedTime
in interface TimeMeasurable
public final long getReceivedTime()
TimeMeasurable
getReceivedTime
in interface TimeMeasurable
public final boolean isReceived()
Agent
isReceived
in interface Agent<C extends ClientContext,S extends ServerContext>
public final long getProcessingDuration()
TimeMeasurable
getProcessingDuration
in interface TimeMeasurable
public final long getTotalDuration()
TimeMeasurable
getTotalDuration
in interface TimeMeasurable
public final long getTransferDuration()
TimeMeasurable
getTransferDuration
in interface TimeMeasurable
public final void setArgument(java.lang.Object arg, boolean doZip)
Agent
setArgument
in interface Agent<C extends ClientContext,S extends ServerContext>
public final void setArgument(java.lang.Object arg)
Agent
setArgument
in interface Agent<C extends ClientContext,S extends ServerContext>
public final java.lang.Object getArgument()
Agent
getArgument
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
Agent
sendForExecution
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()
Agent
Agent.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()
Agent
Agent.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 SimpleLogSupport
logFatal
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logError(java.lang.String message, java.lang.Exception error)
logError
in interface SimpleLogSupport
logError
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logError(java.lang.String message)
logError
in interface SimpleLogSupport
logError
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logWarning(java.lang.String message)
logWarning
in interface SimpleLogSupport
logWarning
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logInfo(java.lang.String message)
logInfo
in interface SimpleLogSupport
logInfo
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logVerbose(java.lang.String message)
logVerbose
in interface SimpleLogSupport
logVerbose
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logDebug(java.lang.String message)
logDebug
in interface SimpleLogSupport
logDebug
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
public final void logDump(java.lang.String message)
logDump
in interface SimpleLogSupport
logDump
in class AbstractCrossPlatformObject<C extends ClientContext,S extends ServerContext>
Copyright © 2014 EsprIT-Systems. All Rights Reserved.