Magentix2
2.1.1
|
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 () |
This class defines an new agents template, extending of BaseAgent. This type of agent's implements the protocols.
Definition at line 29 of file QueueAgent.java.
es.upv.dsic.gti_ia.architecture.QueueAgent.QueueAgent | ( | AgentID | aid | ) | throws Exception |
Create a new QueueAgent.
aid | agent ID. |
Exception | if agent id already exists on the platform |
Definition at line 48 of file QueueAgent.java.
{ super(aid); }
synchronized Monitor es.upv.dsic.gti_ia.architecture.QueueAgent.addMonitor | ( | Object | b | ) | [package] |
Adds new monitor
Definition at line 231 of file QueueAgent.java.
{ this.addRole(b); if (this.monitor == null) this.monitor = new Monitor(); return monitor; }
void es.upv.dsic.gti_ia.architecture.QueueAgent.addTask | ( | Object | obj | ) |
Adds a new task (FIPA protocol) to the agent,was creating a new thread
obj | object 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.
agentID |
Definition at line 263 of file QueueAgent.java.
{ for (String conv : this.activeConversationsList) { if (conv.equals(agentID)) { this.activeConversationsList.remove(agentID); break; } } }
synchronized boolean es.upv.dsic.gti_ia.architecture.QueueAgent.deleteAllActiveConversation | ( | ) | [package] |
Removes all active conversations.
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.
b | Monitor |
Definition at line 243 of file QueueAgent.java.
{
this.removeRole(b);
if (this.roles.size() == 0)
this.monitor = null;
}
synchronized Monitor es.upv.dsic.gti_ia.architecture.QueueAgent.getMonitor | ( | ) | [package] |
Returns the monitor
Definition at line 291 of file QueueAgent.java.
{
return this.monitor;
}
void es.upv.dsic.gti_ia.architecture.QueueAgent.onMessage | ( | ACLMessage | msg | ) | [protected] |
Function that will be executed when the agent gets a message
msg | ACLMessage |
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(); } }
synchronized ACLMessage es.upv.dsic.gti_ia.architecture.QueueAgent.receiveACLMessage | ( | MessageTemplate | template | ) | throws Exception |
Method to receives a magentix2 ACLMessage
template | is a MessageTemplate, will serve as a filter for receiving the right message |
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; }
synchronized ACLMessage es.upv.dsic.gti_ia.architecture.QueueAgent.receiveACLMessage | ( | MessageTemplate | template, |
int | type | ||
) | [package] |
Method to receives a magentix2 ACLMessage
template | is a MessageTemplate, will serve as a filter for receiving the right message |
type | 1 = rol responder other = rol initiator |
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.
agentID |
Definition at line 253 of file QueueAgent.java.
{ this.activeConversationsList.add(agentID); }
void es.upv.dsic.gti_ia.architecture.QueueAgent.terminate | ( | ) | [protected] |
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(); }