Package emissary.core
Class MobileAgent
- java.lang.Object
-
- emissary.core.MobileAgent
-
- All Implemented Interfaces:
IMobileAgent,MobileAgentMBean,Serializable,Runnable
- Direct Known Subclasses:
HDMobileAgent
public abstract class MobileAgent extends Object implements IMobileAgent, MobileAgentMBean
An autonomous hunk of software- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringAGENT_THREADprotected StringagentIdprotected IServiceProviderPlacearrivalPlacestatic intDEFAULT_MAX_ITINERARY_STEPSstatic intDEFAULT_MAX_MOVE_ERRORSprotected static StringDONE_FORMprotected static StringERROR_FORMprotected AtomicBooleanidleprotected StringlastPlaceProcessedprotected static org.slf4j.Loggerloggerprotected intmaxItineraryStepsprotected intmaxMoveErrorsprotected intmoveErrorsOccurredprotected Deque<DirectoryEntry>nextKeyQueueprotected static StringNO_AGENT_IDprotected IBaseDataObjectpayloadprotected static org.slf4j.LoggerprobeLoggerprotected booleanprocessFirstPlaceprotected Threadthreadprotected booleantimeToQuit
-
Constructor Summary
Constructors Constructor Description MobileAgent()Still have an uncaught exception handler but not really in a true ThreadGroup with other agentsMobileAgent(ThreadGroup threadGroup, String threadName)Create a new reusable Agent
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddParallelTrackingInfo(String t)protected voidagentControl(IServiceProviderPlace currentPlaceArg)The main control loop to determine and go through an itinerary until the payload is finished (no where else to go)StringagentId()Return the IDprotected voidagentReturn()Clean up, idle, and return agent to poolvoidarrive(Object dataObject, IServiceProviderPlace arrivalPlaceArg, int moveErrorCount, List<DirectoryEntry> queuedItineraryItems)This is for an already in process agent arriving at a new place from a "moveTo".protected voidatPlace(IServiceProviderPlace place, IBaseDataObject payloadArg)Do work now that we have arrived at the specified placeprotected voidcheckInterrupt(IServiceProviderPlace place)protected booleancheckParallelTrackingFor(String type)protected voidclear()Clear out the payload and other private stuffprotected voidclearParallelTrackingInfo()voiddumpPlaceStats()DirectoryEntry[]getItineraryQueueItems()Provide access to the itinerary queue for the MoveAdapterintgetMaxItinerarySteps()Get the maximum number of itinerary stepsintgetMaxMoveErrors()Get the number of move errorsintgetMoveErrorCount()Provide access to the move-error counter for the MoveAdapterStringgetName()Report this agents name for logging purposesprotected DirectoryEntrygetNextKey(IServiceProviderPlace place, IBaseDataObject payloadArg)Get the next key from the directory with error handling Can return null if there is no place to handle the formIBaseDataObjectgetPayload()Return a reference to the payload of this agentprotected booleangetProcessFirstPlace()Getter for processFirstPlacevoidgo(Object payloadArg, IServiceProviderPlace arrivalPlaceArg)A little more than the name implies, this method sets the things required for an idle agent to get moving again.protected voidgo(Object dataObject, IServiceProviderPlace arrivalPlaceArg, boolean processAtFirstPlace)Private implementation for both of the above arrive and go methods, uses the setProcessFirstPlace to communicate on which path we entered to the agent's threadbooleanisInUse()Report whether we are busy or notprotected booleanisParallelServiceType(int typeSetPosition)Evaluate parallel attribute of specified type indexvoidkillAgent()Call this method to permanently stop the running thread when we finish what we are doingvoidkillAgentAsync()Kill asynchronouslyprotected voidlogAgentCompletion(IBaseDataObject payloadArg)Make a nice log message when we are done with the payloadprotected DirectoryEntrynextKeyFromDirectory(String dataId, IServiceProviderPlace place, DirectoryEntry lastEntry, IBaseDataObject payloadArg)Communicate with the directory through the current place to get the next place to go.protected static voidpurgeNonFinalForms(IBaseDataObject payloadArg)Delete all forms on the stack that are not final.protected voidrecordHistory(DirectoryEntry placeEntry, IBaseDataObject payloadArg)Record the processing history in the data objectprotected voidrecordHistory(IServiceProviderPlace place, IBaseDataObject payloadArg)Record the processing history in the data objectprotected TimedResourceresourceWatcherStart(IServiceProviderPlace place)voidrun()Runnable interface, starts this agent running on its own thread.protected voidsetAgentId(String theId)Build the unique agent ID for carrying this payload around mostly used in error reportingprotected voidsetArrivalPlace(IServiceProviderPlace p)Set the current place we should kick off withvoidsetMaxItinerarySteps(int value)Set the maximum number of itinerary steps before this instance will turn the workflow into an ERROR conditionvoidsetMaxMoveErrors(int value)Set the maximum number of move attempts that can error out before this instance will quit trying and set the workflow to be an ERROR conditionprotected voidsetPayload(IBaseDataObject p)Set the payloadprotected voidsetProcessFirstPlace(boolean arg)Setter for processFirstPlacestatic inttypeLookup(String s)Get index in typeSet for specified string, 0 if not found-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface emissary.core.IMobileAgent
getLastPlaceProcessed, getPayloadForTransport, interrupt, isZombie, payloadCount
-
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
probeLogger
protected static final org.slf4j.Logger probeLogger
-
thread
@Nullable protected transient Thread thread
-
AGENT_THREAD
public static final String AGENT_THREAD
- See Also:
- Constant Field Values
-
DEFAULT_MAX_MOVE_ERRORS
public static final int DEFAULT_MAX_MOVE_ERRORS
- See Also:
- Constant Field Values
-
maxMoveErrors
protected int maxMoveErrors
-
DEFAULT_MAX_ITINERARY_STEPS
public static final int DEFAULT_MAX_ITINERARY_STEPS
- See Also:
- Constant Field Values
-
maxItinerarySteps
protected int maxItinerarySteps
-
ERROR_FORM
protected static final String ERROR_FORM
- See Also:
- Constant Field Values
-
DONE_FORM
protected static final String DONE_FORM
- See Also:
- Constant Field Values
-
payload
@Nullable protected IBaseDataObject payload
-
idle
protected AtomicBoolean idle
-
arrivalPlace
@Nullable protected transient IServiceProviderPlace arrivalPlace
-
processFirstPlace
protected boolean processFirstPlace
-
lastPlaceProcessed
@Nullable protected String lastPlaceProcessed
-
NO_AGENT_ID
protected static final String NO_AGENT_ID
-
agentId
protected transient String agentId
-
timeToQuit
protected transient volatile boolean timeToQuit
-
nextKeyQueue
protected Deque<DirectoryEntry> nextKeyQueue
-
moveErrorsOccurred
protected int moveErrorsOccurred
-
-
Constructor Detail
-
MobileAgent
public MobileAgent()
Still have an uncaught exception handler but not really in a true ThreadGroup with other agents
-
MobileAgent
public MobileAgent(ThreadGroup threadGroup, String threadName)
Create a new reusable Agent- Parameters:
threadGroup- group we operate itthreadName- symbolic name for this agent thread
-
-
Method Detail
-
getName
public String getName()
Report this agents name for logging purposes- Specified by:
getNamein interfaceIMobileAgent
-
run
public void run()
Runnable interface, starts this agent running on its own thread. It will wait unless it has a payload and a place to start with. You can set both of these items at once using the go method, which will then notify us to come out of the wait state and process the payload
-
killAgent
public void killAgent()
Call this method to permanently stop the running thread when we finish what we are doing- Specified by:
killAgentin interfaceIMobileAgent
-
killAgentAsync
public void killAgentAsync()
Kill asynchronously- Specified by:
killAgentAsyncin interfaceIMobileAgent
-
isInUse
public boolean isInUse()
Report whether we are busy or not- Specified by:
isInUsein interfaceIMobileAgent
-
setArrivalPlace
protected void setArrivalPlace(@Nullable IServiceProviderPlace p)Set the current place we should kick off with
-
setPayload
protected void setPayload(@Nullable IBaseDataObject p)Set the payload
-
agentId
public String agentId()
Return the ID- Specified by:
agentIdin interfaceIMobileAgent
-
clear
protected void clear()
Clear out the payload and other private stuff
-
clearParallelTrackingInfo
protected void clearParallelTrackingInfo()
-
addParallelTrackingInfo
protected void addParallelTrackingInfo(String t)
-
checkParallelTrackingFor
protected boolean checkParallelTrackingFor(String type)
-
getPayload
public IBaseDataObject getPayload()
Return a reference to the payload of this agent- Specified by:
getPayloadin interfaceIMobileAgent
-
agentControl
protected void agentControl(IServiceProviderPlace currentPlaceArg)
The main control loop to determine and go through an itinerary until the payload is finished (no where else to go)- Parameters:
currentPlaceArg- where we are now
-
atPlace
protected void atPlace(IServiceProviderPlace place, IBaseDataObject payloadArg)
Do work now that we have arrived at the specified place- Parameters:
place- the place we are asking to work for uspayloadArg- the data for the place to operate on
-
checkInterrupt
protected final void checkInterrupt(IServiceProviderPlace place)
-
resourceWatcherStart
protected TimedResource resourceWatcherStart(IServiceProviderPlace place)
-
agentReturn
protected void agentReturn()
Clean up, idle, and return agent to pool
-
getNextKey
@Nullable protected DirectoryEntry getNextKey(@Nullable IServiceProviderPlace place, @Nullable IBaseDataObject payloadArg)
Get the next key from the directory with error handling Can return null if there is no place to handle the form- Parameters:
place- the place we will use to access the directorypayloadArg- the current payload we care about- Returns:
- the SDE answer from the directory
-
isParallelServiceType
protected boolean isParallelServiceType(int typeSetPosition)
Evaluate parallel attribute of specified type index
-
typeLookup
public static int typeLookup(String s)
Get index in typeSet for specified string, 0 if not found
-
nextKeyFromDirectory
protected DirectoryEntry nextKeyFromDirectory(String dataId, IServiceProviderPlace place, DirectoryEntry lastEntry, IBaseDataObject payloadArg)
Communicate with the directory through the current place to get the next place to go. These are all local calls since all the local directories have all the information This call may cause several key entries to be returned from the directory. All will be put on an internal queue and the first one will be returned to the caller. Caller knows to look on the internal queue for additional entries before calling this method again.
-
setAgentId
protected void setAgentId(@Nullable String theId)Build the unique agent ID for carrying this payload around mostly used in error reporting- Parameters:
theId- usually comes from the shortName of the payload
-
go
public void go(Object payloadArg, IServiceProviderPlace arrivalPlaceArg)
A little more than the name implies, this method sets the things required for an idle agent to get moving again. This is to be used when starting the agent from a pickup place because although we start with an initial 'place' we don't use it for processing, just to get the nextKey from the directory there.- Specified by:
goin interfaceIMobileAgent- Parameters:
payloadArg- the real payload, existing if any will be clearedarrivalPlaceArg- the place we start at
-
go
protected void go(@Nullable Object dataObject, @Nullable IServiceProviderPlace arrivalPlaceArg, boolean processAtFirstPlace)Private implementation for both of the above arrive and go methods, uses the setProcessFirstPlace to communicate on which path we entered to the agent's thread- Parameters:
dataObject- the real payloadarrivalPlaceArg- the place we start atprocessAtFirstPlace- true if we should call process on arrivalPlaceArg
-
getMoveErrorCount
public int getMoveErrorCount()
Provide access to the move-error counter for the MoveAdapter- Specified by:
getMoveErrorCountin interfaceIMobileAgent
-
getItineraryQueueItems
public DirectoryEntry[] getItineraryQueueItems()
Provide access to the itinerary queue for the MoveAdapter- Specified by:
getItineraryQueueItemsin interfaceIMobileAgent- Returns:
- array of DirectoryEntry
-
arrive
public void arrive(Object dataObject, IServiceProviderPlace arrivalPlaceArg, int moveErrorCount, List<DirectoryEntry> queuedItineraryItems) throws Exception
This is for an already in process agent arriving at a new place from a "moveTo". This is different than the above method because we presume we have arrived at this place in order to do some processing here, not just because we got picked up by it. So we don't need to get a key first, just start processing.- Specified by:
arrivein interfaceIMobileAgent- Parameters:
dataObject- the real payload, exisitng if any will be clearedarrivalPlaceArg- the place we start atmoveErrorCount- transported move error counterqueuedItineraryItems- transported itinerary items list of DirectoryEntry- Throws:
Exception
-
purgeNonFinalForms
protected static void purgeNonFinalForms(IBaseDataObject payloadArg)
Delete all forms on the stack that are not final. This is called in error conditions to try and break out of loops or terminate other badness and zip to the end- Parameters:
payloadArg- the dataobject to work on
-
logAgentCompletion
protected void logAgentCompletion(IBaseDataObject payloadArg)
Make a nice log message when we are done with the payload- Parameters:
payloadArg- the one we just finished with
-
recordHistory
protected void recordHistory(IServiceProviderPlace place, IBaseDataObject payloadArg)
Record the processing history in the data object- Parameters:
place- where the processing is taking placepayloadArg- the dataobject that is being processed
-
recordHistory
protected void recordHistory(DirectoryEntry placeEntry, IBaseDataObject payloadArg)
Record the processing history in the data object- Parameters:
placeEntry- where the processing is taking placepayloadArg- the data object that is being processed
-
setProcessFirstPlace
protected void setProcessFirstPlace(boolean arg)
Setter for processFirstPlace- Parameters:
arg- the new value for processFirstPlace
-
getProcessFirstPlace
protected boolean getProcessFirstPlace()
Getter for processFirstPlace- Returns:
- the value of processFirstPlace
-
dumpPlaceStats
public void dumpPlaceStats()
- Specified by:
dumpPlaceStatsin interfaceMobileAgentMBean
-
getMaxMoveErrors
public int getMaxMoveErrors()
Get the number of move errors- Specified by:
getMaxMoveErrorsin interfaceIMobileAgent
-
setMaxMoveErrors
public void setMaxMoveErrors(int value)
Set the maximum number of move attempts that can error out before this instance will quit trying and set the workflow to be an ERROR condition- Specified by:
setMaxMoveErrorsin interfaceIMobileAgent- Parameters:
value- the maximum number of move failures
-
getMaxItinerarySteps
public int getMaxItinerarySteps()
Get the maximum number of itinerary steps- Specified by:
getMaxItineraryStepsin interfaceIMobileAgent
-
setMaxItinerarySteps
public void setMaxItinerarySteps(int value)
Set the maximum number of itinerary steps before this instance will turn the workflow into an ERROR condition- Specified by:
setMaxItineraryStepsin interfaceIMobileAgent- Parameters:
value- the new maximum number of steps
-
-