Package fr.dyade.aaa.agent
Interface AgentEngine
-
- All Superinterfaces:
MessageComparator,MessageConsumer
- All Known Implementing Classes:
Engine
public interface AgentEngine extends MessageConsumer
TheAgentEngineprovides multiprogramming of agents. It realizes the program loop which successively gets the notifications from the message queue and calls the relevant reaction function member of the target agent. The engine's basic behaviour is:While (true) { // get next message in channel Message msg = qin.get(); // get the agent to process event Agent agent = load(msg.to); // execute relevant reaction, all notification sent during this // reaction is inserted into persistent queue in order to processed // by the channel. agent.react(msg.from, msg.not); // save changes, then commit. <BEGIN TRANSACTION> qin.pop(); channel.dispatch(); agent.save(); <COMMIT TRANSACTION> }The
AgentEngineensures the atomic handling of an agent reacting to a notification:- if the reaction completes, a COMMIT ensures all changes related to the reaction are committed (state change of the agent, notifications signaled during the reaction, deletion of the handled notification);
- if anything goes wrong during the reaction, a ROLLBACK undoes the changes; depending on the error kind it may be necessary to execute additional operations to resynchronize the database and the memory objects, and to allow the main program to continue.
Handling errors.Two types of errors may occur: errors of first type are detected in the source code and signaled by an
Exception; serious errors lead to anErrorbeing raised then the engine exits. In the first case the exception may be handled at any level, even partially. Most of them are signaled up to the engine loop. Two cases are then distinguished depending on the recovery policy:- if
recoveryPolicyis set toRP_EXC_NOT(default value) then the agent state and the message queue are restored (ROLLBACK); anExceptionNotificationnotification is sent to the sender and the engine may then proceed with next notification; - if
recoveryPolicyis set toRP_EXITthe engine stops the agent server.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcreateAgent(AgentId id, Agent agent)Creates and initializes an agent.voiddeleteAgent(AgentId agent)Deletes an agent.StringdumpAgent(AgentId id)Returns a string representation of the specified agent.floatgetAverageLoad1()Returns the load averages for the last minute.floatgetAverageLoad15()Returns the load averages for the past 15 minutes.floatgetAverageLoad5()Returns the load averages for the past 5 minutes.longgetCommitTime()longgetNbReactions()Returns the number of agent's reaction since last boot.intgetNbWaitingMessages()Gets the number of waiting messages in this engine.longgetReactTime()StringgetRunningAgent()Returns the unique id. of the running agent if any, null otherwise.voidincWorkInProgress()Increments the tick counter that reflects activity in server.voidinit(AgentEngineContext agentEngineContext)Initializes the engine.booleanisAgentProfiling()Returns true if the agent profiling is on.booleanisEngineThread()Checks if the current thread calling this method belongs to the engine.booleanisNoTxIfTransient()Returns the flag to avoid transactions.voidpush(AgentId from, AgentId to, Notification not)Puts a notification in the output queue.voidpush(AgentId to, Notification not)Puts a notification in the output queue.voidresetAverageLoad()voidsetAgentProfiling(boolean agentProfiling)Sets the agent profiling.-
Methods inherited from interface fr.dyade.aaa.agent.MessageComparator
isPrior
-
Methods inherited from interface fr.dyade.aaa.agent.MessageConsumer
delete, getDomainName, getName, getQueue, insert, isRunning, post, postAndValidate, restore, save, start, stop, validate
-
-
-
-
Method Detail
-
isEngineThread
boolean isEngineThread()
Checks if the current thread calling this method belongs to the engine.- Returns:
- true if the current thread calling this method belongs to the engine
-
resetAverageLoad
void resetAverageLoad()
-
getAverageLoad1
float getAverageLoad1()
Returns the load averages for the last minute.- Specified by:
getAverageLoad1in interfaceMessageConsumer- Returns:
- the load averages for the last minute.
-
getAverageLoad5
float getAverageLoad5()
Returns the load averages for the past 5 minutes.- Specified by:
getAverageLoad5in interfaceMessageConsumer- Returns:
- the load averages for the past 5 minutes.
-
getAverageLoad15
float getAverageLoad15()
Returns the load averages for the past 15 minutes.- Specified by:
getAverageLoad15in interfaceMessageConsumer- Returns:
- the load averages for the past 15 minutes.
-
isAgentProfiling
boolean isAgentProfiling()
Returns true if the agent profiling is on.- Returns:
- true if the agent profiling is on.
- See Also:
EngineMBean.isAgentProfiling()
-
setAgentProfiling
void setAgentProfiling(boolean agentProfiling)
Sets the agent profiling.- Parameters:
agentProfiling- if true sets the agent profiling.- See Also:
EngineMBean.setAgentProfiling(boolean)
-
getReactTime
long getReactTime()
- Returns:
- the reactTime
-
getCommitTime
long getCommitTime()
- Returns:
- the commitTime
-
init
void init(AgentEngineContext agentEngineContext) throws Exception
Initializes the engine. TheAgentEngineContextparameter should be for the unique private use of thisAgentEngineand should not be shared with any other components otherwise the agent server security would be broken.- Parameters:
agentEngineContext- context enabling thisAgentEngineto invoke operations that cannot be accessed outside of thefr.dyade.aaa.agentpackage. TheAgentEngineContextshould be for the unique private use of thisAgentEngineand should not be shared with any other components otherwise the agent server security would be broken.- Throws:
Exception- an error occurs.
-
getNbWaitingMessages
int getNbWaitingMessages()
Gets the number of waiting messages in this engine.- Returns:
- the number of waiting messages.
-
getNbReactions
long getNbReactions()
Returns the number of agent's reaction since last boot.- Returns:
- the number of agent's reaction since last boot
-
getRunningAgent
String getRunningAgent()
Returns the unique id. of the running agent if any, null otherwise.- Returns:
- the unique id. of the running agent if any, null otherwise.
-
dumpAgent
String dumpAgent(AgentId id) throws IOException, ClassNotFoundException
Returns a string representation of the specified agent. If the agent is not present it is loaded in memory, be careful it is not initialized (agentInitialize) nor cached in agents vector.- Parameters:
id- The agent's unique identification.- Returns:
- A string representation of specified agent.
- Throws:
IOException- an error occurs.ClassNotFoundException- an error occurs.
-
push
void push(AgentId to, Notification not)
Puts a notification in the output queue.- Parameters:
to- the destinationnot- the notification to push
-
push
void push(AgentId from, AgentId to, Notification not)
Puts a notification in the output queue.- Parameters:
from- the sourceto- the destinationnot- the notification to push
-
createAgent
void createAgent(AgentId id, Agent agent) throws Exception
Creates and initializes an agent.- Parameters:
id- the unique identifieragent- agent object to create- Throws:
Exception- unspecialized exception
-
deleteAgent
void deleteAgent(AgentId agent) throws Exception
Deletes an agent.- Parameters:
agent- agent to delete- Throws:
Exception- unspecialized exception
-
isNoTxIfTransient
boolean isNoTxIfTransient()
Returns the flag to avoid transactions.- Returns:
- the flag to avoid transactions
-
incWorkInProgress
void incWorkInProgress()
Increments the tick counter that reflects activity in server.
-
-