es.upv.dsic.gti_ia.core
Class BaseAgent

java.lang.Object
  extended by es.upv.dsic.gti_ia.core.BaseAgent
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
BridgeAgentInOut, BridgeAgentOutIn, CAgent, QueueAgent, SingleAgent, TraceManager

public class BaseAgent
extends Object
implements Runnable

Base class to inherit when implementing a basic Magentix agent. This class provides mechanisms to enable communication between agents. A good alternative is to inherit from SingleAgent, which provides methods (callbacks) when a message arrives, etc. If this class is too basic, consider to inherit from one of the two possibilities given by the QueueAgent and the CAgent.

Author:
Ricard Lopez Fogues, Sergio Pajares Ferrando, Joan Bellver Faus, Luis Burdalo
See Also:
SingleAgent, QueueAgent, CAgent

Field Summary
protected  org.apache.log4j.Logger logger
          The logger variable considers to print any event that occurs by the agent
protected  org.apache.qpid.transport.Session session
          QPid session used for communication.
protected  org.apache.qpid.transport.Session traceSession
          Qpid session used for tracing.
 
Constructor Summary
BaseAgent(AgentID aid)
          Creates a new agent in an open broker connection
 
Method Summary
 void activateTraceService()
           
 void changeIdentity(AgentID _aid)
          Changes the name of the agent to acquire a new identity.
 void deactivateTraceService()
           
protected  void execute()
          Method that defines all the logic and behavior of the agent.
 void finalize()
          The trace system is notified when the agent is about to disappear, in this method.
 AgentID getAid()
          Returns a structure as the Agent Identificator formed by the name, protocol, host and port Agent.
 String getName()
          Returns the agent name
protected  void init()
          Define activities such as initialization resources, and every task necessary before execution of execute procedure.
protected  void onMessage(ACLMessage msg)
          Function that will be executed when the agent gets a message The user has to write his/her code here
protected  void onTraceEvent(TraceEvent tEvent)
          Function that will be executed when the agent gets a trace event.
 void run()
          Runs Agent's thread
 void send(ACLMessage msg)
          Sends a ACLMessage to all specified recipients agents.
 void sendTraceEvent(TraceEvent tEvent)
          Sends a trace event to the mgx.trace exchange
 void start()
          Starts the agent
protected  void terminate()
          Function that will be executed when the agent terminates
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.log4j.Logger logger
The logger variable considers to print any event that occurs by the agent


session

protected org.apache.qpid.transport.Session session
QPid session used for communication.


traceSession

protected org.apache.qpid.transport.Session traceSession
Qpid session used for tracing.

See Also:
TracingService
Constructor Detail

BaseAgent

public BaseAgent(AgentID aid)
          throws Exception
Creates a new agent in an open broker connection

Parameters:
aid - Agent identification for the new agent, it has to be unique on the platform
Throws:
Exception - If Agent ID already exists on the platform
Method Detail

changeIdentity

public void changeIdentity(AgentID _aid)
                    throws Exception
Changes the name of the agent to acquire a new identity.

Parameters:
_aid - the new agent id
Throws:
Exception

send

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

Parameters:
msg -

sendTraceEvent

public void sendTraceEvent(TraceEvent tEvent)
Sends a trace event to the mgx.trace exchange

Parameters:
tEvent - Trace event which is to be sent

getName

public String getName()
Returns the agent name

Returns:
Agent name

init

protected void init()
Define activities such as initialization resources, and every task necessary before execution of execute procedure. It will be executed when the agent will be launched and may be defined by the user.


execute

protected void execute()
Method that defines all the logic and behavior of the agent. This method necessarily must be defined.


finalize

public void finalize()
The trace system is notified when the agent is about to disappear, in this method.

Overrides:
finalize in class Object

onMessage

protected void onMessage(ACLMessage msg)
                  throws Exception
Function that will be executed when the agent gets a message The user has to write his/her code here

Parameters:
msg - Message received
Throws:
Exception

onTraceEvent

protected void onTraceEvent(TraceEvent tEvent)
Function that will be executed when the agent gets a trace event. The user has to write his/her code here


terminate

protected void terminate()
Function that will be executed when the agent terminates


run

public void run()
Runs Agent's thread

Specified by:
run in interface Runnable

start

public void start()
Starts the agent


getAid

public AgentID getAid()
Returns a structure as the Agent Identificator formed by the name, protocol, host and port Agent.

Returns:
agent ID

activateTraceService

public void activateTraceService()

deactivateTraceService

public void deactivateTraceService()


Copyright © 2012 GTI-IA. All Rights Reserved.