es.upv.dsic.gti_ia.cAgents
Class CProcessor

java.lang.Object
  extended by es.upv.dsic.gti_ia.cAgents.CProcessor
All Implemented Interfaces:
Cloneable, Runnable

public class CProcessor
extends Object
implements Runnable, Cloneable

CProcessors manage conversations. Each conversation is managed by a different CProcessor. CProcessors are created by CFactories, also a CProcessor can act as a template and be associated to a CFactory. Every CProcessor has a graph associated, this graph specifies the states of the conversation and their transitions.

Author:
Ricard Lopez Fogues

Constructor Summary
protected CProcessor(CAgent myAgent)
          Creates a new CProcessor associated to an agent
 
Method Summary
protected  void addMessage(ACLMessage msg)
          Assigns a message to this CProcessor
 void addTransition(State from, State destination)
          Adds a transition between two states
 void addTransition(String from, String destination)
          Adds a transition between two states
protected  BeginState beginState()
          Returns the name of the first state
protected  es.upv.dsic.gti_ia.cAgents.CancelState cancelState()
          Returns the name of the exception cancel state
 int cleanMessagesQueue(String agentID, String headerTitle, ArrayList<String> headerContents)
          Deletes the messages from the messageQueue that have the given agentID (as sender), header title and the contents of this header
 Object clone()
          Clones this object
 void createAsyncConversation(ACLMessage initalMessage)
          Creates a asynchronous CProcessor
 ACLMessage createSyncConversation(ACLMessage initalMessage)
          Creates a synchronous conversation where this agent is the initiator
 ACLMessage createSyncConversation(CFactory factory, String id)
          Creates a synchronous conversation, in this conversation this agent is the initiator
 void deregisterState(State s)
          Removes a state from the graph
 String getConversationID()
          Gets conversation identifier
 Map<String,Object> getInternalData()
          Gets conversation's internal data
 ACLMessage getLastReceivedMessage()
          Gets the last received message during this conversation
 ACLMessage getLastSentMessage()
          Gets the last sent message during this conversation
 CAgent getMyAgent()
          Returns the agent owner of this CProcessor
 CFactory getMyFactory()
          Returns the factory that has associated this CProcessor
 CProcessor getParent()
          Returns the CProcessor which is parent of this one
 Map<String,Object> getParentInternalData()
          Returns parent internal data
 State getState(String name)
          Returns the state identified by its name
 TransitionTable getTransitionTable()
          Returns the table of transitions between the states of the graph
 boolean isIdle()
          Returns true if the CProcessor is idle, false otherwise
protected  boolean isInitiator()
          Returns whether the CProcessor is initiator
 boolean isTerminated()
          Returns true if the CProcessor is terminated, false otherwise
protected  String newConversationID()
          Returns a new conversation identifier
 void registerFirstState(State s)
          Registers the first state of the graph
 void registerState(State s)
          Registers a new state in the CProcessor
 void removeTransition(String from, String destination)
          Removes a transition between from state and destination state
 void run()
          This method executes the CProcessor thread.
protected  es.upv.dsic.gti_ia.cAgents.SendingErrorsState sendingErrorsState()
          Returns the exception state that manages sending errors
protected  void setConversationID(String id)
          Sets the conversation identifier
protected  void setFactory(CFactory factory)
          Sets the factory to which this CProcessor is associated
protected  void setIdle(boolean idle)
          Sets the CProcessor as idle
protected  void setInitiator(boolean initiator)
          Sets the CProcessor as initiator or participant
protected  void setIsSynchronized(boolean synchronization)
          Sets the CProcessor as synchronous or asynchronous
protected  void setParent(CProcessor parent)
          Sets the parent CProcessor of this one
 void ShutdownAgent()
          Tries to end agent execution
 void unlockMyAgent()
          Unlocks the mutex of the agent owner of this CProcessor
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CProcessor

protected CProcessor(CAgent myAgent)
Creates a new CProcessor associated to an agent

Parameters:
myAgent - The associated agent
Method Detail

addTransition

public void addTransition(String from,
                          String destination)
Adds a transition between two states

Parameters:
from - name of the from state
destination - name of the destination state

addTransition

public void addTransition(State from,
                          State destination)
Adds a transition between two states

Parameters:
from - state
destination - state

createAsyncConversation

public void createAsyncConversation(ACLMessage initalMessage)
Creates a asynchronous CProcessor

Parameters:
initalMessage - first message received in this conversation, i.e. the message which started the conversation

createSyncConversation

public ACLMessage createSyncConversation(ACLMessage initalMessage)
Creates a synchronous conversation where this agent is the initiator

Parameters:
initalMessage - The message that will be sent as the first message of the conversation
Returns:
Final message generated by this conversation

createSyncConversation

public ACLMessage createSyncConversation(CFactory factory,
                                         String id)
Creates a synchronous conversation, in this conversation this agent is the initiator

Parameters:
factory - Factory that will create the conversation
id - Conversation id
Returns:
Final message generated by this conversation

deregisterState

public void deregisterState(State s)
Removes a state from the graph

Parameters:
s - State to remove

getConversationID

public String getConversationID()
Gets conversation identifier

Returns:
Conversation identifier

getInternalData

public Map<String,Object> getInternalData()
Gets conversation's internal data

Returns:
CProcessor's internal data

getLastReceivedMessage

public ACLMessage getLastReceivedMessage()
Gets the last received message during this conversation

Returns:
the last received message during this conversation

getLastSentMessage

public ACLMessage getLastSentMessage()
Gets the last sent message during this conversation

Returns:
the last sent message during this conversation

getMyAgent

public CAgent getMyAgent()
Returns the agent owner of this CProcessor

Returns:
the agent owner of this CProcessor

getParent

public CProcessor getParent()
Returns the CProcessor which is parent of this one

Returns:
the CProcessor which is parent of this one

getParentInternalData

public Map<String,Object> getParentInternalData()
Returns parent internal data

Returns:
parent internal data

getState

public State getState(String name)
Returns the state identified by its name

Parameters:
name - of the state
Returns:
the state identified by its name

getTransitionTable

public TransitionTable getTransitionTable()
Returns the table of transitions between the states of the graph

Returns:
the table of transitions between the states of the graph

registerState

public void registerState(State s)
Registers a new state in the CProcessor

Parameters:
s - The new state

removeTransition

public void removeTransition(String from,
                             String destination)
Removes a transition between from state and destination state

Parameters:
from - name of the form state
destination - name of the destination state

run

public void run()
This method executes the CProcessor thread. This method manages the conversation through the different graph states

Specified by:
run in interface Runnable

ShutdownAgent

public void ShutdownAgent()
Tries to end agent execution


unlockMyAgent

public void unlockMyAgent()
Unlocks the mutex of the agent owner of this CProcessor


clone

public Object clone()
Clones this object

Overrides:
clone in class Object
Returns:
a clone of this object

addMessage

protected void addMessage(ACLMessage msg)
Assigns a message to this CProcessor

Parameters:
msg - message to be assigned

cleanMessagesQueue

public int cleanMessagesQueue(String agentID,
                              String headerTitle,
                              ArrayList<String> headerContents)
Deletes the messages from the messageQueue that have the given agentID (as sender), header title and the contents of this header

Parameters:
agentID - of the sender
headerTitle - to search in the headers of the messages
headerContents - of the given header title to delete the message from queue
Returns:
number of messages deleted

beginState

protected BeginState beginState()
Returns the name of the first state

Returns:
The name of the begin state

cancelState

protected es.upv.dsic.gti_ia.cAgents.CancelState cancelState()
Returns the name of the exception cancel state

Returns:
The name of the cancel state

getMyFactory

public CFactory getMyFactory()
Returns the factory that has associated this CProcessor

Returns:
the factory that has associated this CProcessor

isIdle

public boolean isIdle()
Returns true if the CProcessor is idle, false otherwise

Returns:
true if the CProcessor is idle, false otherwise

isTerminated

public boolean isTerminated()
Returns true if the CProcessor is terminated, false otherwise

Returns:
true if the CProcessor is terminated, false otherwise

newConversationID

protected String newConversationID()
Returns a new conversation identifier

Returns:
a new conversation identifier

registerFirstState

public void registerFirstState(State s)
Registers the first state of the graph

Parameters:
s - the state to register

sendingErrorsState

protected es.upv.dsic.gti_ia.cAgents.SendingErrorsState sendingErrorsState()
Returns the exception state that manages sending errors

Returns:
the exception state that manages sending errors

setConversationID

protected void setConversationID(String id)
Sets the conversation identifier

Parameters:
id - the conversation identifier

setFactory

protected void setFactory(CFactory factory)
Sets the factory to which this CProcessor is associated

Parameters:
factory - to which this CProcessor will be associated

setIdle

protected void setIdle(boolean idle)
Sets the CProcessor as idle

Parameters:
idle - true if you want to set it to idle, false otherwise

setIsSynchronized

protected void setIsSynchronized(boolean synchronization)
Sets the CProcessor as synchronous or asynchronous

Parameters:
synchronization - true if you want to set it to synchronous, false otherwise

setParent

protected void setParent(CProcessor parent)
Sets the parent CProcessor of this one

Parameters:
parent - CProcessor of this one

setInitiator

protected void setInitiator(boolean initiator)
Sets the CProcessor as initiator or participant

Parameters:
initiator - true if you want to set it to initiator, false otherwise

isInitiator

protected boolean isInitiator()
Returns whether the CProcessor is initiator

Returns:
whether the CProcessor is initiator


Copyright © 2012 GTI-IA. All Rights Reserved.