|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfr.dyade.aaa.agent.Engine
class Engine
The Engine
class provides 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 Engine
class ensures the atomic handling of an agent
reacting to a notification:
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 an Error
being 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:
recoveryPolicy
is set to RP_EXC_NOT
(default value) then the agent state and the message queue are restored
(ROLLBACK); an ExceptionNotification
notification is sent
to the sender and the engine may then proceed with next notification;
recoveryPolicy
is set to RP_EXIT
the engine
stops the agent server.
Nested Class Summary | |
---|---|
(package private) class |
Engine.EngineAverageLoadTask
|
Field Summary | |
---|---|
(package private) Agent |
agent
The current agent running. |
boolean |
agentProfiling
|
(package private) java.util.Hashtable |
agents
This table is used to maintain a list of agents already in memory using the AgentId as primary key. |
(package private) Engine.EngineAverageLoadTask |
averageLoadTask
|
protected boolean |
canStop
Boolean variable used to stop the engine properly. |
private long |
commitTime
Time consumned during reaction commit. |
(package private) java.util.Vector |
fixedAgentIdList
Vector containing id's of all fixed agents. |
protected boolean |
isRunning
Boolean variable used to stop the engine properly. |
protected org.objectweb.util.monolog.api.Logger |
logmon
|
private boolean |
modified
True if the timestamp is modified since last save. |
protected Queue |
mq
|
(package private) Message |
msg
The message in progress. |
private java.lang.String |
name
|
(package private) int |
NbMaxAgents
Maximum number of memory loaded agents. |
protected boolean |
needToBeCommited
|
(package private) long |
now
Virtual time counter use in FIFO swap-in/swap-out mechanisms. |
protected MessageQueue |
qin
Queue of messages to be delivered to local agents. |
private long |
reactTime
Time consumned during agent's reaction. |
(package private) int |
recoveryPolicy
recovery policy in case of exception in agent specific code. |
(package private) static int |
RP_EXC_NOT
Send ExceptionNotification notification in case of exception
in agent specific code. |
(package private) static int |
RP_EXIT
Stop agent server in case of exception in agent specific code. |
(package private) static java.lang.String[] |
rpStrings
String representations of RP_* constant values
for the recoveryPolicy variable. |
private int |
stamp
Logical timestamp information for messages in "local" domain. |
private byte[] |
stampBuf
Buffer used to optimize |
(package private) EngineThread |
thread
The active component of this engine. |
protected long |
timeout
|
Constructor Summary | |
---|---|
protected |
Engine()
Initializes a new Engine object (can only be used by
subclasses). |
Method Summary | |
---|---|
(package private) void |
abort(java.lang.Exception exc)
Abort the agent reaction in case of error during execution. |
(package private) void |
addFixedAgentId(AgentId id)
Adds an AgentId in the fixedAgentIdList
Vector . |
(package private) void |
clean()
Cleans the Channel queue of all pushed notifications. |
(package private) void |
commit()
Commit the agent reaction in case of right termination: suppress the processed notification from message queue, then deletes it ; push all new notifications in qin and qout, and saves them ; saves the agent state ; then commit the transaction to validate all changes. |
(package private) void |
createAgent(Agent agent)
Creates and initializes an agent. |
(package private) void |
createAgent(AgentId id,
Agent agent)
Creates and initializes an agent. |
void |
delete()
This operation always throws an IllegalStateException. |
(package private) void |
deleteAgent(AgentId from)
Deletes an agent. |
(package private) void |
dispatch()
Dispatch messages between the MessageConsumer :
Engine component and
Network components. |
java.lang.String |
dumpAgent(AgentId id)
Returns a string representation of the specified agent. |
java.lang.String |
dumpAgent(java.lang.String id)
Returns a string representation of the specified agent. |
(package private) void |
garbage()
The garbage method should be called regularly , to swap out
from memory all the agents which have not been accessed for a time. |
float |
getAverageLoad1()
Returns the load averages for the last minute. |
float |
getAverageLoad15()
Returns the load averages for the past 15 minutes. |
float |
getAverageLoad5()
Returns the load averages for the past 5 minutes. |
long |
getCommitTime()
|
java.lang.String |
getDomainName()
Returns the corresponding domain's name. |
(package private) AgentId[] |
getLoadedAgentIdlist()
Method used for debug and monitoring. |
java.lang.String |
getName()
Returns this Engine 's name. |
int |
getNbAgents()
Returns the number of agents actually loaded in memory. |
int |
getNbFixedAgents()
Returns the number of fixed agents. |
int |
getNbMaxAgents()
Returns the maximum number of agents loaded in memory. |
int |
getNbMessages()
Gets the number of messages posted to this engine since creation. |
long |
getNbReactions()
Returns the number of agent's reaction since last boot. |
int |
getNbWaitingMessages()
Gets the number of waiting messages in this engine. |
MessageQueue |
getQueue()
Get this engine's MessageQueue qin. |
long |
getReactTime()
|
protected int |
getStamp()
|
(package private) void |
init()
|
void |
insert(Message msg)
Insert a message in the MessageQueue . |
boolean |
isAgentProfiling()
|
boolean |
isRunning()
Tests if the engine is alive. |
(package private) Agent |
load(AgentId id)
The load method return the Agent object
designed by the AgentId parameter. |
(package private) static Engine |
newInstance()
Creates a new instance of Engine (real class depends of server type). |
protected void |
onTimeOut()
|
void |
post(Message msg)
Adds a message in "ready to deliver" list. |
(package private) void |
push(AgentId from,
AgentId to,
Notification not)
Push a new message in temporary queue until the end of current reaction. |
(package private) Agent |
reload(AgentId id)
The reload method return the Agent object
loaded from the storage. |
(package private) void |
removeFixedAgentId(AgentId id)
Removes an AgentId in the fixedAgentIdList
Vector . |
void |
restore()
Restores logical clock information from persistent storage. |
void |
run()
Main loop of agent server Engine . |
void |
save()
Saves logical clock information to persistent storage. |
void |
setAgentProfiling(boolean agentProfiling)
|
void |
setNbMaxAgents(int NbMaxAgents)
Sets the maximum number of agents that can be loaded simultaneously in memory. |
protected void |
setStamp(int stamp)
|
protected void |
stamp(Message msg)
|
void |
start()
Causes this engine to begin execution. |
void |
stop()
Forces the engine to stop executing. |
(package private) void |
terminate()
|
java.lang.String |
toString()
Returns a string representation of this engine. |
void |
validate()
Validates all messages pushed in queue during transaction session. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected MessageQueue qin
protected volatile boolean isRunning
protected volatile boolean canStop
isRunning
variable between
each reaction)
private int stamp
private byte[] stampBuf
private boolean modified
java.util.Hashtable agents
long now
int NbMaxAgents
java.util.Vector fixedAgentIdList
Agent agent
Message msg
EngineThread thread
static final int RP_EXC_NOT
ExceptionNotification
notification in case of exception
in agent specific code.
Constant value for the recoveryPolicy
variable.
static final int RP_EXIT
recoveryPolicy
variable.
static final java.lang.String[] rpStrings
RP_*
constant values
for the recoveryPolicy
variable.
int recoveryPolicy
RP_EXC_NOT
.
private java.lang.String name
protected Queue mq
protected org.objectweb.util.monolog.api.Logger logmon
protected boolean needToBeCommited
protected long timeout
public boolean agentProfiling
private long reactTime
private long commitTime
Engine.EngineAverageLoadTask averageLoadTask
Constructor Detail |
---|
protected Engine() throws java.lang.Exception
Engine
object (can only be used by
subclasses).
java.lang.Exception
Method Detail |
---|
public long getNbReactions()
getNbReactions
in interface EngineMBean
public int getNbMaxAgents()
getNbMaxAgents
in interface EngineMBean
public void setNbMaxAgents(int NbMaxAgents)
setNbMaxAgents
in interface EngineMBean
NbMaxAgents
- the maximum number of agentspublic int getNbAgents()
getNbAgents
in interface EngineMBean
public int getNbMessages()
getNbMessages
in interface EngineMBean
public int getNbWaitingMessages()
getNbWaitingMessages
in interface EngineMBean
public int getNbFixedAgents()
getNbFixedAgents
in interface EngineMBean
public final java.lang.String getName()
Engine
's name.
getName
in interface EngineMBean
getName
in interface MessageConsumer
Engine
's name.public final java.lang.String getDomainName()
getDomainName
in interface MessageConsumer
static Engine newInstance() throws java.lang.Exception
engine
's instance.
java.lang.Exception
final void push(AgentId from, AgentId to, Notification not)
final void dispatch() throws java.lang.Exception
MessageConsumer
:
Engine
component and
Network
components.Handle persistent information in respect with engine transaction.
java.io.IOException
- error when accessing the local persistent
storage.
java.lang.Exception
final void clean()
void init() throws java.lang.Exception
java.lang.Exception
void terminate()
final void createAgent(AgentId id, Agent agent) throws java.lang.Exception
agent
- agent object to create
java.lang.Exception
- unspecialized exceptionfinal void createAgent(Agent agent) throws java.lang.Exception
agent
- agent object to create
java.lang.Exception
- unspecialized exceptionvoid deleteAgent(AgentId from) throws java.lang.Exception
agent
- agent to delete
java.lang.Exception
void garbage()
garbage
method should be called regularly , to swap out
from memory all the agents which have not been accessed for a time.
void removeFixedAgentId(AgentId id) throws java.io.IOException
AgentId
in the fixedAgentIdList
Vector
.
id
- the AgentId
of no more used fixed agent.
java.io.IOException
void addFixedAgentId(AgentId id) throws java.io.IOException
AgentId
in the fixedAgentIdList
Vector
.
id
- the AgentId
of new fixed agent.
java.io.IOException
AgentId[] getLoadedAgentIdlist()
public java.lang.String dumpAgent(java.lang.String id) throws java.lang.Exception
dumpAgent
in interface EngineMBean
id
- The string representation of the agent's unique identification.
java.lang.Exception
dumpAgent(AgentId)
public java.lang.String dumpAgent(AgentId id) throws java.io.IOException, java.lang.ClassNotFoundException
id
- The agent's unique identification.
java.io.IOException
java.lang.ClassNotFoundException
final Agent load(AgentId id) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.Exception
load
method return the Agent
object
designed by the AgentId
parameter. If the Agent
object is not already present in the server memory, it is loaded from
the storage.
Be careful, if the save method can be overloaded to optimize the save
process, the load procedure used by engine is always load.
id
- The agent identification.
java.io.IOException
- If an I/O error occurs.
java.lang.ClassNotFoundException
- Should never happen (the agent has already been loaded in deploy).
UnknownAgentException
- There is no corresponding agent on secondary storage.
java.lang.Exception
- when executing class specific initializationfinal Agent reload(AgentId id) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.Exception
reload
method return the Agent
object
loaded from the storage.
id
- The agent identification.
java.io.IOException
- when accessing the stored image
java.lang.ClassNotFoundException
- if the stored image class may not be found
java.lang.Exception
- unspecialized exceptionpublic void insert(Message msg)
MessageQueue
.
This method is used during initialization to restore the component
state from persistent storage.
insert
in interface MessageConsumer
msg
- the messagepublic void validate()
validate
in interface MessageConsumer
public void start()
start
in interface EngineMBean
start
in interface MessageConsumer
stop
public void stop()
stop
in interface EngineMBean
stop
in interface MessageConsumer
start
public MessageQueue getQueue()
MessageQueue
qin.
getQueue
in interface MessageConsumer
Engine
's queue.public boolean isRunning()
isRunning
in interface EngineMBean
isRunning
in interface MessageConsumer
MessageConsumer
is alive; false
otherwise.public void save() throws java.io.IOException
save
in interface MessageConsumer
java.io.IOException
public void restore() throws java.lang.Exception
restore
in interface MessageConsumer
java.lang.Exception
public void delete() throws java.lang.IllegalStateException
delete
in interface MessageConsumer
java.lang.IllegalStateException
Transaction
protected final int getStamp()
protected final void setStamp(int stamp)
protected final void stamp(Message msg)
public void post(Message msg) throws java.lang.Exception
post
in interface MessageConsumer
java.lang.Exception
public boolean isAgentProfiling()
isAgentProfiling
in interface EngineMBean
public void setAgentProfiling(boolean agentProfiling)
setAgentProfiling
in interface EngineMBean
public long getReactTime()
getReactTime
in interface EngineMBean
public long getCommitTime()
getCommitTime
in interface EngineMBean
protected void onTimeOut() throws java.lang.Exception
java.lang.Exception
public void run()
Engine
.
run
in interface java.lang.Runnable
void commit() throws java.lang.Exception
java.lang.Exception
void abort(java.lang.Exception exc) throws java.lang.Exception
java.lang.Exception
public float getAverageLoad1()
getAverageLoad1
in interface EngineMBean
getAverageLoad1
in interface MessageConsumer
public float getAverageLoad5()
getAverageLoad5
in interface EngineMBean
getAverageLoad5
in interface MessageConsumer
public float getAverageLoad15()
getAverageLoad15
in interface EngineMBean
getAverageLoad15
in interface MessageConsumer
public java.lang.String toString()
toString
in interface EngineMBean
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |