Magentix2
2.1.1
|
Public Member Functions | |
FIPAQueryInitiator (QueueAgent agent, ACLMessage msg) | |
QueueAgent | getQueueAgent () |
boolean | finished () |
String | getIdConversation () |
void | action () |
Public Attributes | |
QueueAgent | myAgent |
Protected Member Functions | |
ACLMessage | prepareRequest (ACLMessage msg) |
void | handleAgree (ACLMessage msg) |
void | handleRefuse (ACLMessage msg) |
void | handleNotUnderstood (ACLMessage msg) |
void | handleInform (ACLMessage msg) |
void | handleFailure (ACLMessage msg) |
void | handleOutOfSequence (ACLMessage msg) |
Package Functions | |
int | getState () |
Package Attributes | |
String | conversationID = null |
This class implements the FIPA-Query interaction protocol, Role Initiator
Definition at line 16 of file FIPAQueryInitiator.java.
es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.FIPAQueryInitiator | ( | QueueAgent | agent, |
ACLMessage | msg | ||
) |
Creates a new FIPA-Query interaction protocol, rol initiator.
agent | is the reference to the Agent Object |
msg | initial message |
Definition at line 50 of file FIPAQueryInitiator.java.
{ myAgent = agent; requestmsg = msg; this.monitor = myAgent.addMonitor(this); }
Runs the state machine with the communication protocol
Definition at line 95 of file FIPAQueryInitiator.java.
{ switch (state) { case PREPARE_MSG_STATE: { ACLMessage msg = prepareRequest(this.requestmsg); this.requestsentmsg = msg; state = SEND_MSG_STATE; break; } case SEND_MSG_STATE: { ACLMessage request = this.requestsentmsg; if (request == null) { //Finalized protocol this.finish = true; break; } else { if (request.getConversationId().equals("")) { conversationID = "C" + hashCode() + "_" + System.currentTimeMillis(); request.setConversationId(conversationID); } else { conversationID = request.getConversationId(); } // Configure template template = new MessageTemplate(InteractionProtocol.FIPA_QUERY); template.addConversation(conversationID); template.add_receiver(request.getReceiver()); myAgent.setActiveConversation(conversationID); //The timeout is fixed in the message Date d = request.getReplyByDate(); if (d != null) timeout = d.getTime() - (new Date()).getTime(); else timeout = -1; endingtime = System.currentTimeMillis() + timeout; //If the message is for a Jade agent if (request.getReceiver() != null) { if (request.getReceiver(0).name.contains("/JADE")) { request.getReceiver().host = request.getReceiver().name.substring(request.getReceiver().name.indexOf("@")+1,request.getReceiver().name.indexOf(":")); request.getReceiver().port = "7778"; request.getReceiver().protocol = "http"; } } myAgent.send(request); state = RECEIVE_REPLY_STATE; } break; } case RECEIVE_REPLY_STATE: { ACLMessage firstReply = myAgent.receiveACLMessage(template, 0); if (firstReply != null) { switch (firstReply.getPerformativeInt()) { case ACLMessage.AGREE: { state = RECEIVE_2ND_REPLY_STATE; handleAgree(firstReply); break; } case ACLMessage.REFUSE: { state = ALL_REPLIES_RECEIVED_STATE; handleRefuse(firstReply); break; } case ACLMessage.NOT_UNDERSTOOD: { state = ALL_REPLIES_RECEIVED_STATE; handleNotUnderstood(firstReply); break; } case ACLMessage.FAILURE: { state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; handleFailure(firstReply); break; } case ACLMessage.INFORM: { state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; handleInform(firstReply); break; } default: { //We receive the second message, there were problems in first message state = RECEIVE_REPLY_STATE; handleOutOfSequence(firstReply); break; } } break; } else { if (timeout > 0) { long blocktime = endingtime - System.currentTimeMillis(); if (blocktime <= 0) state = ALL_REPLIES_RECEIVED_STATE; else this.monitor.waiting(blocktime); } else { this.monitor.waiting(); state = RECEIVE_REPLY_STATE;// state = // ALL_REPLIES_RECEIVED_STATE; break; } } } case RECEIVE_2ND_REPLY_STATE: { ACLMessage secondReply = myAgent.receiveACLMessage(template, 0); if (secondReply != null) { switch (secondReply.getPerformativeInt()) { case ACLMessage.INFORM: { state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; handleInform(secondReply); break; } case ACLMessage.FAILURE: { state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; handleFailure(secondReply); break; } default: { // state = RECEIVE_REPLY_STATE; state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; handleOutOfSequence(secondReply); break; } } break; } else { this.monitor.waiting(); state = RECEIVE_2ND_REPLY_STATE; break; } } case ALL_REPLIES_RECEIVED_STATE: { state = ALL_RESULT_NOTIFICATION_RECEIVED_STATE; break; } case ALL_RESULT_NOTIFICATION_RECEIVED_STATE: { this.finish = true; this.requestmsg = null; this.requestsentmsg = null; this.myAgent.deleteMonitor(this); this.myAgent.deleteActiveConversation(conversationID); break; } } }
This method reports if the protocol has been finished
Definition at line 74 of file FIPAQueryInitiator.java.
{
return this.finish;
}
Returns the id of the message used in communication protocol
Definition at line 87 of file FIPAQueryInitiator.java.
{ return this.conversationID; }
Return the agent.
Definition at line 61 of file FIPAQueryInitiator.java.
{ return this.myAgent; }
int es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.getState | ( | ) | [package] |
Definition at line 79 of file FIPAQueryInitiator.java.
{
return this.state;
}
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleAgree | ( | ACLMessage | msg | ) | [protected] |
This method is called when a agree message is received.
msg | the received agree message. |
Definition at line 288 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "in HandleAgree: " + msg.toString()); }
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleFailure | ( | ACLMessage | msg | ) | [protected] |
This method is called when a Failure message is received.
msg | the received Failure message. |
Definition at line 332 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, "in HandleFailure: " + msg.toString()); }
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleInform | ( | ACLMessage | msg | ) | [protected] |
This method is called when a Inform message is received.
msg | the received Inform message. |
Definition at line 321 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "in HandleInform: " + msg.toString()); }
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleNotUnderstood | ( | ACLMessage | msg | ) | [protected] |
This method is called when a NotUnderstood message is received.
msg | the received NotUnderstood message. |
Definition at line 310 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "in HandleNotUnderstood: " + msg.toString()); }
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleOutOfSequence | ( | ACLMessage | msg | ) | [protected] |
This method is called when a unexpected message is received.
msg | the received message |
Definition at line 343 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, "in HandleOutOfSequence: " + msg.toString()); }
void es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.handleRefuse | ( | ACLMessage | msg | ) | [protected] |
This method is called when a refuse message is received.
msg | the received refuse message. |
Definition at line 299 of file FIPAQueryInitiator.java.
{ if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "in HandleRefuse: " + msg.toString()); }
ACLMessage es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.prepareRequest | ( | ACLMessage | msg | ) | [protected] |
This method must return the ACLMessage to be sent. This default implementation just return the ACLMessage object passed in the constructor. Programmer might override the method in order to return a different ACLMessage. Note that for this simple version of protocol, the message will be just send to the first receiver set.
msg | the ACLMessage object passed in the constructor. |
Definition at line 278 of file FIPAQueryInitiator.java.
{
return msg;
}
String es.upv.dsic.gti_ia.architecture.FIPAQueryInitiator.conversationID = null [package] |
Definition at line 34 of file FIPAQueryInitiator.java.
Definition at line 27 of file FIPAQueryInitiator.java.