Package fr.dyade.aaa.agent
Class AgentEngineContextImpl
- java.lang.Object
-
- fr.dyade.aaa.agent.AgentEngineContextImpl
-
- All Implemented Interfaces:
AgentEngineContext
class AgentEngineContextImpl extends Object implements AgentEngineContext
Context enabling anAgentEngineimplemented in another package to invoke operations that cannot be accessed outside of thefr.dyade.aaa.agentpackage. AnAgentEngineContextshould be for the unique private use of its associatedAgentEngineand should not be shared with any other components otherwise the agent server security would be broken.
-
-
Field Summary
Fields Modifier and Type Field Description private static EncodableFactorymessageFactory
-
Constructor Summary
Constructors Constructor Description AgentEngineContextImpl()Package constructor not accessible from outside this package.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelPost(Message msg)Posts a message in the channel.voidcheckMessageFrom(Message msg)Checks the message 'from'.AgentcreateAgentFactory()Creates an instance ofAgentFactory.MessagecreateMessage(AgentId from, AgentId to, Notification not)Creates a message.voiddeleteMessage(Message msg)Deletes and frees the specified message.voiddirectSendTo(AgentId to, Notification not)Sends a notification to the specified destination with a local id.MessageConsumergetConsumer(short id)Returns the specifiedMessageConsumerAgentIdgetLocalAgentId()Returns the local agent id.voidincReactNumber(Agent ag)Increments the reaction counter of the specified agent.voidinitAgentLogger(Agent agent)Initializes the agent's logger.voidinitializeAgent(AgentId id, Agent agent)Initializes an agent after creation.voidinitializeReloadedAgent(Agent agent)Initializes a reloaded agent.AgentloadAgent(AgentId id)Loads the specified agent.voidsaveAgent(Agent agent)Saves the agentvoidsaveChannel()Saves the channelvoidsetAgentLast(Agent ag, long last)Sets the agent last reaction count.voidsetSaveAgent(Agent agent)Sets the agent as to be saved.voidstampAndSave(Message msg, int stamp)Stamps and saves the specified message.voidvalidateChannel()Validates the Channel.
-
-
-
Field Detail
-
messageFactory
private static EncodableFactory messageFactory
-
-
Method Detail
-
createAgentFactory
public Agent createAgentFactory() throws IOException
Creates an instance ofAgentFactory.- Specified by:
createAgentFactoryin interfaceAgentEngineContext- Returns:
- an instance of
AgentFactory - Throws:
IOException- an error occurs.
-
initializeAgent
public void initializeAgent(AgentId id, Agent agent) throws Exception
Initializes an agent after creation. First time is true.- Specified by:
initializeAgentin interfaceAgentEngineContext- Parameters:
id- the identifier of the agent to initializeagent- the agent to initialize- Throws:
Exception- an error occurs.
-
directSendTo
public void directSendTo(AgentId to, Notification not)
Sends a notification to the specified destination with a local id.- Specified by:
directSendToin interfaceAgentEngineContext- Parameters:
to- the notification destinationnot- the notification to send
-
initAgentLogger
public void initAgentLogger(Agent agent) throws Exception
Initializes the agent's logger.- Specified by:
initAgentLoggerin interfaceAgentEngineContext- Parameters:
agent- the agent to initialize- Throws:
Exception- an error occurs.
-
loadAgent
public Agent loadAgent(AgentId id) throws IOException, ClassNotFoundException
Loads the specified agent.- Specified by:
loadAgentin interfaceAgentEngineContext- Parameters:
id- the identifier of the agent to load- Returns:
- the loaded agent
- Throws:
IOException- an error occurs.ClassNotFoundException- an error occurs.
-
setAgentLast
public void setAgentLast(Agent ag, long last)
Sets the agent last reaction count.- Specified by:
setAgentLastin interfaceAgentEngineContext- Parameters:
ag- the agent to modifylast- the reaction count to set
-
initializeReloadedAgent
public void initializeReloadedAgent(Agent agent) throws Exception
Initializes a reloaded agent. First time is false.- Specified by:
initializeReloadedAgentin interfaceAgentEngineContext- Parameters:
agent- the agent to initialize.- Throws:
Exception- an error occurs.
-
setSaveAgent
public void setSaveAgent(Agent agent)
Sets the agent as to be saved.- Specified by:
setSaveAgentin interfaceAgentEngineContext- Parameters:
agent- the agent to update
-
saveAgent
public void saveAgent(Agent agent) throws IOException
Saves the agent- Specified by:
saveAgentin interfaceAgentEngineContext- Parameters:
agent- the agent to save- Throws:
IOException- an error occurs.
-
createMessage
public Message createMessage(AgentId from, AgentId to, Notification not)
Creates a message.- Specified by:
createMessagein interfaceAgentEngineContext- Parameters:
from- the source of the messageto- the destination of the messagenot- the notification to be transmitted by the message- Returns:
- the created message.
-
deleteMessage
public void deleteMessage(Message msg)
Deletes and frees the specified message.- Specified by:
deleteMessagein interfaceAgentEngineContext- Parameters:
msg- the message to delete.
-
getLocalAgentId
public AgentId getLocalAgentId()
Returns the local agent id.- Specified by:
getLocalAgentIdin interfaceAgentEngineContext- Returns:
- the local agent id
-
incReactNumber
public void incReactNumber(Agent ag)
Increments the reaction counter of the specified agent.- Specified by:
incReactNumberin interfaceAgentEngineContext- Parameters:
ag- the agent to update
-
validateChannel
public void validateChannel()
Validates the Channel.- Specified by:
validateChannelin interfaceAgentEngineContext
-
checkMessageFrom
public void checkMessageFrom(Message msg)
Checks the message 'from'.- Specified by:
checkMessageFromin interfaceAgentEngineContext- Parameters:
msg- the message to check
-
getConsumer
public MessageConsumer getConsumer(short id) throws UnknownServerException
Returns the specifiedMessageConsumer- Specified by:
getConsumerin interfaceAgentEngineContext- Parameters:
id- the identifier of theMessageConsumer- Returns:
- the specified
MessageConsumer - Throws:
UnknownServerException- the server is not defined.
-
channelPost
public void channelPost(Message msg) throws Exception
Posts a message in the channel.- Specified by:
channelPostin interfaceAgentEngineContext- Parameters:
msg- the message to post- Throws:
Exception- an error occurs.
-
saveChannel
public void saveChannel() throws IOExceptionSaves the channel- Specified by:
saveChannelin interfaceAgentEngineContext- Throws:
IOException- an error occurs.
-
stampAndSave
public void stampAndSave(Message msg, int stamp) throws IOException
Stamps and saves the specified message.- Specified by:
stampAndSavein interfaceAgentEngineContext- Parameters:
msg- the message to stamp and savestamp- the stamp to assign- Throws:
IOException- an error occurs.
-
-