Magentix2  2.1.1
es.upv.dsic.gti_ia.architecture.QueueAgent Class Reference
Inheritance diagram for es.upv.dsic.gti_ia.architecture.QueueAgent:
Collaboration diagram for es.upv.dsic.gti_ia.architecture.QueueAgent:

List of all members.

Classes

class  ThreadInitiator
class  ThreadResponder

Public Member Functions

 QueueAgent (AgentID aid) throws Exception
synchronized ACLMessage receiveACLMessage (MessageTemplate template) throws Exception
void addTask (Object obj)

Protected Member Functions

void onMessage (ACLMessage msg)
void terminate ()

Package Functions

synchronized ACLMessage receiveACLMessage (MessageTemplate template, int type)
synchronized Monitor addMonitor (Object b)
synchronized void deleteMonitor (Object b)
synchronized void setActiveConversation (String agentID)
synchronized void deleteActiveConversation (String agentID)
synchronized boolean deleteAllActiveConversation ()
synchronized Monitor getMonitor ()

Detailed Description

This class defines an new agents template, extending of BaseAgent. This type of agent's implements the protocols.

Author:
Joan Bellver Faus

Definition at line 29 of file QueueAgent.java.


Constructor & Destructor Documentation

Create a new QueueAgent.

Parameters:
aidagent ID.
Exceptions:
Exceptionif agent id already exists on the platform

Definition at line 48 of file QueueAgent.java.

                                                        {
                super(aid);

        }

Member Function Documentation

synchronized Monitor es.upv.dsic.gti_ia.architecture.QueueAgent.addMonitor ( Object  b) [package]

Adds new monitor

Returns:
Monitor

Definition at line 231 of file QueueAgent.java.

                                                  {
                this.addRole(b);
                if (this.monitor == null)
                        this.monitor = new Monitor();
                return monitor;
        }

Adds a new task (FIPA protocol) to the agent,was creating a new thread

Parameters:
objobject of type FIPA protocol. ej: FIPARequestInitiator, FIPARequestResponder, FIPAQueryResponder, FIPAQueryInitiator, FIPAContractNetResponder, FIPAContractNetInitiator.

Definition at line 365 of file QueueAgent.java.

                                        {

                String patron;

                patron = obj.getClass().getSuperclass().getName().substring(
                                obj.getClass().getSuperclass().getName().lastIndexOf(".") + 1,
                                obj.getClass().getSuperclass().getName().length());
                if (patron.equals("FIPARequestInitiator"))

                {

                        ThreadInitiator h = new ThreadInitiator(obj, 1);
                        h.start();

                } else if (patron.equals("FIPARequestResponder")) {

                        ThreadResponder h = new ThreadResponder(obj, 1);
                        h.start();
                }
                if (patron.equals("FIPAQueryInitiator")) {

                        ThreadInitiator h = new ThreadInitiator(obj, 2);
                        h.start();
                } else if (patron.equals("FIPAQueryResponder")) {

                        ThreadResponder h = new ThreadResponder(obj, 2);
                        h.start();
                }
                if (patron.equals("FIPAContractNetInitiator")) {

                        ThreadInitiator h = new ThreadInitiator(obj, 3);
                        h.start();
                } else if (patron.equals("FIPAContractNetResponder")) {

                        ThreadResponder h = new ThreadResponder(obj, 3);
                        h.start();
                }

        }
synchronized void es.upv.dsic.gti_ia.architecture.QueueAgent.deleteActiveConversation ( String  agentID) [package]

Removes a agentID of the array of the active conversations.

Parameters:
agentID

Definition at line 263 of file QueueAgent.java.

                                                                   {
                for (String conv : this.activeConversationsList) {
                        if (conv.equals(agentID)) {
                                this.activeConversationsList.remove(agentID);
                                break;
                        }
                }
        }

Removes all active conversations.

Returns:
boolean value

Definition at line 277 of file QueueAgent.java.

                                                           {
                this.activeConversationsList.clear();
                if (this.activeConversationsList.size() == 0)
                        return true;
                else
                        return false;

        }
synchronized void es.upv.dsic.gti_ia.architecture.QueueAgent.deleteMonitor ( Object  b) [package]

Deletes monitor.

Parameters:
bMonitor

Definition at line 243 of file QueueAgent.java.

                                                  {
                this.removeRole(b);
                if (this.roles.size() == 0)
                        this.monitor = null;
        }

Returns the monitor

Returns:
Monitor

Definition at line 291 of file QueueAgent.java.

                                          {
                return this.monitor;
        }

Function that will be executed when the agent gets a message

Parameters:
msgACLMessage

Reimplemented from es.upv.dsic.gti_ia.core.BaseAgent.

Definition at line 59 of file QueueAgent.java.

                                                 {

                this.writeQueue(msg);

                // responsible for waking the class agent, may be the responder role or
                // the role iniciator
                if (monitor != null) {

                        this.monitor.advise();
                }

        }

Method to receives a magentix2 ACLMessage

Parameters:
templateis a MessageTemplate, will serve as a filter for receiving the right message
Returns:
msg ACLMessage

Definition at line 95 of file QueueAgent.java.

                         {
                ACLMessage msgselect = null;
                Iterator<ACLMessage> iterator = messageList.iterator();

                if (template.getProtocol() == "")
                        throw new Exception("The protocol field is empty");

                while(iterator.hasNext())
                {
                        ACLMessage msg = iterator.next();

                        //Matching with the protocol and converastionID fields, to ensure that the conversation isn't a 
                        //existing conversation 
                        if (template.getProtocol().equals(msg.getProtocol())) {
                                msgselect = msg;

                        }

                }
                if (msgselect != null) {
                        messageList.remove(msgselect);
                }
                return msgselect;
        }

Method to receives a magentix2 ACLMessage

Parameters:
templateis a MessageTemplate, will serve as a filter for receiving the right message
type1 = rol responder other = rol initiator
Returns:
msg ACLMessage

Definition at line 131 of file QueueAgent.java.

                                                                                      {
                ACLMessage msgselect = null;

                Iterator<ACLMessage> iterator = messageList.iterator();
                
                if (type == 1) {
                                
                                while(iterator.hasNext())
                                {
                                        ACLMessage msg = iterator.next();
                                
                        
                                        //Matching with the protocol and converastionID fields, to ensure that the conversation isn't a 
                                        //existing conversation 
                                        if (template.getPerformativeInt() != -2
                                                        && template.getPerformative().equals(
                                                                        msg.getPerformative())
                                                                        || !template.getProtocol().equals("")
                                                                        && template.getProtocol().equals(msg.getProtocol())) {
                                                msgselect = msg;
                                                for (String conv : this.activeConversationsList) {
                                                        //If exist, then the message should be administered by the initiator role.
                                                        if (conv.equals(msg.getConversationId())) {
                                                                msgselect = null;
                                                                break;
                                                        }
                                                }
                                        }

                                }
                        } else {

                                while(iterator.hasNext())
                                {
                                        ACLMessage msg = iterator.next();
                                
                                        
                                        //This is a special case, when is a cancel performative.
                                        if (template.getPerformativeInt() != ACLMessage.CANCEL
                                                        || template.getPerformative().equals(
                                                                        msg.getPerformative())) {
                                                //Matching with the protocol, converastionID fields and sender. 
                                                if (template.getProtocol().equals(msg.getProtocol())) {
                                                        //Look inside the conversations 
                                                        for (String conversacion : template
                                                                        .getList_Conversation())
                                                                if (conversacion
                                                                                .equals(msg.getConversationId())) {
                                                                        msgselect = msg;
                                                                        break;
                                                                }
                                                }
                                                if (msgselect != null)
                                                        break;
                                        }
                                }// for
                        }
                        if (msgselect != null) {
                                messageList.remove(msgselect);
                        }

                
                return msgselect;
        }
synchronized void es.upv.dsic.gti_ia.architecture.QueueAgent.setActiveConversation ( String  agentID) [package]

Sets a new Id conversation, this conversation is considered active.

Parameters:
agentID

Definition at line 253 of file QueueAgent.java.

                                                                {
                this.activeConversationsList.add(agentID);

        }

When agent state is terminated

Reimplemented from es.upv.dsic.gti_ia.core.BaseAgent.

Definition at line 298 of file QueueAgent.java.

                                   {

                if (this.getnRole() == 0)
                        logger.info("Finish ,active roles do not exist");
                else {
                        for (Object obj : this.roles) {

                                String patron;

                                patron = obj.getClass().getSuperclass().getName().substring(
                                                obj.getClass().getSuperclass().getName().lastIndexOf(
                                                ".") + 1,
                                                obj.getClass().getSuperclass().getName().length());

                                if (patron.equals("FIPARequestInitiator"))

                                {
                                        ((FIPARequestInitiator) obj).finish();
                                        logger.info("Finish with role Resquest Initiator, state:  "
                                                        + ((FIPARequestInitiator) obj).getState());

                                } else if (patron.equals("FIPARequestResponder")) {

                                        ((FIPARequestResponder) obj).finish();
                                        logger
                                        .info("Finish with role Responder, protocol:Request, state:  "
                                                        + ((FIPARequestResponder) obj).getState());
                                }
                                if (patron.equals("FIPAQueryInitiator")) {

                                        logger
                                        .info("Finish with role Initiator, protocol:Query, state:  "
                                                        + ((FIPAQueryInitiator) obj).getState());
                                } else if (patron.equals("FIPAQueryResponder")) {

                                        logger
                                        .info("Finish with role Responder, protocol:Query, state:  "
                                                        + ((FIPAQueryResponder) obj).getState());
                                }
                                if (patron.equals("FIPAContractNetInitiator")) {

                                        logger
                                        .info("Finish with role Initiator, protocol:Contract-Net state:  "
                                                        + ((FIPAContractNetInitiator) obj)
                                                        .getState());
                                } else if (patron.equals("FIPAContractNetResponder")) {

                                        logger
                                        .info("Finish with role Responder, protocol:Contract-Net state:  "
                                                        + ((FIPAContractNetResponder) obj)
                                                        .getState());
                                }
                        }
                }

                super.terminate();

        }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables