es.upv.dsic.gti_ia.cAgents
Class CAgent

java.lang.Object
  extended by es.upv.dsic.gti_ia.core.BaseAgent
      extended by es.upv.dsic.gti_ia.cAgents.CAgent
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
CommitmentStore, JasonAgent, OMS, SF

public abstract class CAgent
extends BaseAgent

An agent has to extend this class in order to use the conversation support.

Author:
Ricard Lopez Fogues

Field Summary
protected  CFactory defaultFactory
           
 ExecutorService exec
           
protected  CProcessor welcomeProcessor
           
 
Fields inherited from class es.upv.dsic.gti_ia.core.BaseAgent
logger, session, traceSession
 
Constructor Summary
CAgent(AgentID aid)
          Creates a new CAgent
 
Method Summary
 void addFactoryAsInitiator(CFactory factory)
          Add a new factory that will create conversations where this agent will play the initiator role
 void addFactoryAsParticipant(CFactory factory)
          Add a new factory that will create conversations where this agent will play the participant role
protected  void addProcessor(String conversationID, CProcessor processor)
          Adds a CProcessor to the agent
protected  boolean addTimer(String conversationId, String stateName, long period, int waitType)
          Adds a timer in a CProcessor, this is called from a wait state
protected  void createDefaultFactory(CAgent me)
          This method creates the default factory that will manage the messages that no other factory can
protected  void endConversation(CFactory theFactory)
          Ends a conversation
protected  void execute()
          This is the main method of the agent.
protected abstract  void execution(CProcessor firstProcessor, ACLMessage welcomeMessage)
          This is the main method of the agent
protected abstract  void finalize(CProcessor firstProcessor, ACLMessage finalizeMessage)
          This method is executed just before the agent ends its execution
 int getMutexHoldCount()
          Gets the hold count of the agent's mutex
 void lock()
          Locks the agent's mutex
 String newConversationID()
          Gets a new conversation identifier
protected  void notifyAgentEnd()
          This method signals the end of the agent in order to unlock the main conversation thread
 void onMessage(ACLMessage msg)
          This method should not be modified.
 void removeFactory(String name)
          Removes the specified factory
protected  void removeProcessor(String conversationID)
          Removes a processor identified by its conversation id
 void send(ACLMessage msg)
          Sends a ACLMessage to all specified recipients agents.
 void Shutdown()
          Terminates the agent's execution
protected  void startConversation(ACLMessage msg, CProcessor parent, Boolean sync)
          Starts a conversation
 void startSyncConversation(String factoryName)
          Starts a new conversation asynchronously
 void unlock()
          Unlocks the agent's mutex
 
Methods inherited from class es.upv.dsic.gti_ia.core.BaseAgent
activateTraceService, changeIdentity, deactivateTraceService, finalize, getAid, getName, init, onTraceEvent, run, sendTraceEvent, start, terminate
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

welcomeProcessor

protected CProcessor welcomeProcessor

defaultFactory

protected CFactory defaultFactory

exec

public ExecutorService exec
Constructor Detail

CAgent

public CAgent(AgentID aid)
       throws Exception
Creates a new CAgent

Parameters:
aid -
Throws:
Exception
Method Detail

lock

public void lock()
Locks the agent's mutex


unlock

public void unlock()
Unlocks the agent's mutex


addFactoryAsInitiator

public void addFactoryAsInitiator(CFactory factory)
Add a new factory that will create conversations where this agent will play the initiator role

Parameters:
factory - to be added as a initiator one

addFactoryAsParticipant

public void addFactoryAsParticipant(CFactory factory)
Add a new factory that will create conversations where this agent will play the participant role

Parameters:
factory - to be added as a participant one

onMessage

public void onMessage(ACLMessage msg)
This method should not be modified.

Overrides:
onMessage in class BaseAgent
Parameters:
msg - message received by the agent

removeFactory

public void removeFactory(String name)
Removes the specified factory

Parameters:
name - of the factory to remove

Shutdown

public void Shutdown()
Terminates the agent's execution


send

public void send(ACLMessage msg)
Description copied from class: BaseAgent
Sends a ACLMessage to all specified recipients agents. If a message destination having another platform, this will be forwarded to BridgeAgentInOut agent.

Overrides:
send in class BaseAgent

createDefaultFactory

protected void createDefaultFactory(CAgent me)
This method creates the default factory that will manage the messages that no other factory can

Parameters:
me - The agent owner of this factory

notifyAgentEnd

protected void notifyAgentEnd()
This method signals the end of the agent in order to unlock the main conversation thread


execute

protected final void execute()
This is the main method of the agent. It creates the default and welcome factories and starts the welcome factory

Overrides:
execute in class BaseAgent

finalize

protected abstract void finalize(CProcessor firstProcessor,
                                 ACLMessage finalizeMessage)
This method is executed just before the agent ends its execution

Parameters:
firstProcessor - The CProcessor managing the welcome conversation
finalizeMessage - The final message produced by this conversation

execution

protected abstract void execution(CProcessor firstProcessor,
                                  ACLMessage welcomeMessage)
This is the main method of the agent

Parameters:
firstProcessor - The CProcessor managing the welcome conversation
welcomeMessage - The message sent by the platform to the agent

addProcessor

protected void addProcessor(String conversationID,
                            CProcessor processor)
Adds a CProcessor to the agent

Parameters:
conversationID - of the conversation that the CProcessor will manage
processor - The CProcessor to add

addTimer

protected boolean addTimer(String conversationId,
                           String stateName,
                           long period,
                           int waitType)
Adds a timer in a CProcessor, this is called from a wait state

Parameters:
conversationId -
stateName -
period - Time to wait
waitType - Wait type (oneshot, absolut or periodic)
Returns:
true if a timer was added, false otherwise

endConversation

protected void endConversation(CFactory theFactory)
Ends a conversation

Parameters:
theFactory - managing the conversation that is going to be finished

newConversationID

public String newConversationID()
Gets a new conversation identifier

Returns:
new conversation identifier

removeProcessor

protected void removeProcessor(String conversationID)
Removes a processor identified by its conversation id

Parameters:
conversationID - of the conversation that the CProcessor that is going to be removed is managing

startConversation

protected void startConversation(ACLMessage msg,
                                 CProcessor parent,
                                 Boolean sync)
Starts a conversation

Parameters:
msg - Initial message
parent - CProcessor
sync - true if it is a synchronous conversation or false it is asynchronous

startSyncConversation

public void startSyncConversation(String factoryName)
Starts a new conversation asynchronously

Parameters:
factoryName - Name of the initiator factory that will create the conversation

getMutexHoldCount

public int getMutexHoldCount()
Gets the hold count of the agent's mutex

Returns:
mutex hold count


Copyright © 2012 GTI-IA. All Rights Reserved.