Class DFService
- java.lang.Object
-
- jade.domain.FIPAService
-
- jade.domain.DFService
-
public class DFService extends FIPAService
This class provides a set of static methods to communicate with a DF Service that complies with FIPA specifications. It includes methods to register, deregister, modify and search with a DF. Each of this method has version with all the needed parameters, or with a subset of them where, those parameters that can be omitted have been defaulted to the default DF of the platform, the AID of the sending agent, the default Search Constraints.Notice that all these methods block every activity of the agent until the action (i.e. register/deregister/modify/search) has been successfully executed or a jade.domain.FIPAException exception has been thrown (e.g. because a FAILURE message has been received from the DF).
In some cases, instead, it is more convenient to execute these tasks in a non-blocking way. In these cases a
jade.proto.AchieveREInitiatororjade.proto.SubscriptionInitiatorshould be used in conjunction with thecreateRequestMessage(), createSubscriptionMessage(), decodeDone(), decodeResult() and decodeNotification()methods that facilitate the preparation and decoding of messages to be sent/received to/from the DF. The following piece of code exemplifies that in the case of an agent subscribing to the default DF.DFAgentDescription template = // fill the template Behaviour b = new SubscriptionInitiator( this, DFService.createSubscriptionMessage(this, getDefaultDF(), template, null)) { protected void handleInform(ACLMessage inform) { try { DFAgentDescription[] dfds = DFService.decodeNotification(inform.getContent()); // do something } catch (FIPAException fe) { fe.printStackTrace(); } } }; addBehaviour(b);- Version:
- $Date$ $Revision$
- Author:
- Fabio Bellifemine (CSELT S.p.A.), Elisabetta Cortese (TiLab S.p.A.), Giovanni Caire (TiLab S.p.A.)
-
-
Field Summary
Fields Modifier and Type Field Description static StringDF_SEARCH_TIMEOUT_DEFAULTstatic StringDF_SEARCH_TIMEOUT_KEY
-
Constructor Summary
Constructors Constructor Description DFService()Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ACLMessagecreateCancelMessage(Agent a, AID dfName, ACLMessage subscribe)Utility method that creates a suitable message to be used to CANCEL a subscription to a DF agent.static ACLMessagecreateRequestMessage(Agent a, AID dfName, String action, DFAgentDescription dfd, SearchConstraints constraints)Utility method that creates a suitable message to be used to REQUEST a DF agent to perform a given action of the FIPA-Management-ontology.static ACLMessagecreateSubscriptionMessage(Agent a, AID dfName, DFAgentDescription template, SearchConstraints constraints)Utility method that creates a suitable message to be used to SUBSCRIBE to a DF agent in order to receive notifications when a new DF-Description matching the indicated template is registererd with that DF.static DFAgentDescriptiondecodeDone(String s)Process the content of the finalinform (Done)message resulting from aregisterorderegisteraction requested to a DF agent, extracting thedf-agent-descriptioncontained within.static DFAgentDescription[]decodeNotification(String s)Process the content of theinformmessage resulting from a subscription with a DF agent, extracting the array ofdf-agent-descriptionobjects contained within.static DFAgentDescription[]decodeResult(String s)Process the content of the finalinform (result)message resulting from asearchaction requested to a DF agent, extracting the array ofdf-agent-descriptioncontained within.static voidderegister(Agent a)Deregisters aDFAgentDescriptionfrom the default DF.static voidderegister(Agent a, AID dfName)A default Agent Description is used which contains only the AID of this agent.static voidderegister(Agent a, AID dfName, DFAgentDescription dfd)Deregister a DFAgentDescription from a DF agent.static voidderegister(Agent a, DFAgentDescription dfd)Deregisters aDFAgentDescriptionfrom the default DFstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, AID dfName, String actionName)Deprecated.UseAchieveREInitiatorinsteadstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, AID dfName, String actionName, DFAgentDescription dfd)Deprecated.UseAchieveREInitiatorinsteadstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, AID dfName, String actionName, DFAgentDescription dfd, SearchConstraints constraints)Deprecated.UseAchieveREInitiatorinsteadstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, String actionName)Deprecated.UseAchieveREInitiatorinsteadstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, String actionName, DFAgentDescription dfd)Deprecated.UseAchieveREInitiatorinsteadstatic RequestFIPAServiceBehaviourgetNonBlockingBehaviour(Agent a, String actionName, DFAgentDescription dfd, SearchConstraints constraints)Deprecated.UseAchieveREInitiatorinsteadstatic ACLMessagegetSubscriptionMessage(Agent a, AID dfName, DFAgentDescription template, SearchConstraints constraints)Deprecated.UsecreateSubscriptionMessage()insteadstatic voidkeepRegistered(Agent a, AID df, DFAgentDescription dfd, Date deadline)Add a suitable behaviour that ensures that a DF-Description currently registered with a DF is kept registered until a given deadline.static DFAgentDescriptionmodify(Agent a, AID dfName, DFAgentDescription dfd)Modifies a previously registered DF-Description within a DF agent.static DFAgentDescriptionmodify(Agent a, DFAgentDescription dfd)Modify aDFAgentDescriptionfrom the default DF.static AIDparseAID(SimpleSLTokenizer parser)The parser content has the form: agent-identifier ......)static DFAgentDescriptionregister(Agent a, AID dfName, DFAgentDescription dfd)Register a new DF-Description with a DF agent.static DFAgentDescriptionregister(Agent a, DFAgentDescription dfd)Registers aDFAgentDescriptionwith the default DFstatic DFAgentDescription[]search(Agent a, AID dfName, DFAgentDescription dfd)The default SearchConstraints are used.static DFAgentDescription[]search(Agent a, AID dfName, DFAgentDescription dfd, SearchConstraints constraints)Searches for data contained within a DF agent.static DFAgentDescription[]search(Agent a, DFAgentDescription dfd)The default DF is used.static DFAgentDescription[]search(Agent a, DFAgentDescription dfd, SearchConstraints constraints)The default DF is used.static DFAgentDescription[]searchUntilFound(Agent a, AID dfName, DFAgentDescription dfd, SearchConstraints constraints, long timeout)Searches the DF and remains blocked until a result is found or the specified timeout has expired.-
Methods inherited from class jade.domain.FIPAService
doFipaRequestClient, doFipaRequestClient
-
-
-
-
Field Detail
-
DF_SEARCH_TIMEOUT_KEY
public static final String DF_SEARCH_TIMEOUT_KEY
- See Also:
- Constant Field Values
-
DF_SEARCH_TIMEOUT_DEFAULT
public static final String DF_SEARCH_TIMEOUT_DEFAULT
- See Also:
- Constant Field Values
-
-
Method Detail
-
register
public static DFAgentDescription register(Agent a, AID dfName, DFAgentDescription dfd) throws FIPAException
Register a new DF-Description with a DF agent.It should be noted that, depending on the policy adopted by the DF, the granted lease time for the registration can be shorter than the requested one. This can be checked by looking at the DF-Description actually registered by the DF that is made available as the return value of this method. The
keepRegistered()method can be used to keep the registration valid until a given time.- Parameters:
a- is the Agent performing the registration (it is needed in order to send/receive messages)dfName- The AID of the DF agent to register with.dfd- ADFAgentDescriptionobject containing all data necessary to the registration. If the Agent name is empty, than it is set according to theaparameter.- Returns:
- the
DFAgentDescriptionactually registered by the DF - Throws:
FIPAException- If aREFUSE,FAILUREorNOT_UNDERSTOODmessage is received from the DF (to indicate some error condition) or if the supplied DF-Description is not valid.- See Also:
keepRegistered(Agent, AID, DFAgentDescription, Date)
-
register
public static DFAgentDescription register(Agent a, DFAgentDescription dfd) throws FIPAException
Registers aDFAgentDescriptionwith the default DF- Throws:
FIPAException- See Also:
register(Agent,AID,DFAgentDescription)
-
deregister
public static void deregister(Agent a, AID dfName, DFAgentDescription dfd) throws FIPAException
Deregister a DFAgentDescription from a DF agent.- Parameters:
dfName- The AID of the DF agent to deregister from.dfd- ADFAgentDescriptionobject containing all data necessary to the deregistration.- Throws:
FIPAException- If aREFUSE,FAILUREorNOT_UNDERSTOODmessage is received from the DF (to indicate some error condition) or if the supplied DF-Description is not valid.
-
deregister
public static void deregister(Agent a, DFAgentDescription dfd) throws FIPAException
Deregisters aDFAgentDescriptionfrom the default DF- Throws:
FIPAException- See Also:
deregister(Agent a, AID dfName, DFAgentDescription dfd)
-
deregister
public static void deregister(Agent a, AID dfName) throws FIPAException
A default Agent Description is used which contains only the AID of this agent.- Throws:
FIPAException- See Also:
deregister(Agent a, AID dfName, DFAgentDescription dfd)
-
deregister
public static void deregister(Agent a) throws FIPAException
Deregisters aDFAgentDescriptionfrom the default DF. A default DF-Description is used which contains only the AID of this agent.- Throws:
FIPAException- See Also:
deregister(Agent a, AID dfName, DFAgentDescription dfd)
-
modify
public static DFAgentDescription modify(Agent a, AID dfName, DFAgentDescription dfd) throws FIPAException
Modifies a previously registered DF-Description within a DF agent.It should be noted that, depending on the policy adopted by the DF, the granted lease time for the modified registration can be shorter than the requested one. This can be checked by looking at the DF-Description actually registered by the DF that is made available as the return value of this method. The
keepRegistered()method can be used to keep the registration valid until a given time.- Parameters:
a- is the Agent performing the request of modificationdfName- The AID of the DF agent holding the data to be changed.dfd- ADFAgentDescriptionobject containing all new data values;- Returns:
- the
DFAgentDescriptionactually registered (after the modification) by the DF - Throws:
FIPAException- If aREFUSE,FAILUREorNOT_UNDERSTOODmessage is received from the DF (to indicate some error condition) or if the supplied DF-Description is not valid.- See Also:
keepRegistered(Agent, AID, DFAgentDescription, Date)
-
modify
public static DFAgentDescription modify(Agent a, DFAgentDescription dfd) throws FIPAException
Modify aDFAgentDescriptionfrom the default DF.- Throws:
FIPAException- See Also:
modify(Agent a, AID dfName, DFAgentDescription dfd)
-
keepRegistered
public static void keepRegistered(Agent a, AID df, DFAgentDescription dfd, Date deadline)
Add a suitable behaviour that ensures that a DF-Description currently registered with a DF is kept registered until a given deadline. This method is particularly useful when dealing with a DF agent that grants limited lease time for agent registrations. The following piece of code exemplifies how to use it.DFAgentDescription dfd = // fill DF-Description try { DFAgentDescription actualDfd = DFService.register(this, dfd); DFService.keepRegistered(this, actualDfd, dfd.getLeaseTime()); } catch (FIPAException fe) { fe.printStackTarce(); }- Parameters:
a- The agent that is registerd with the DF.df- The DF agentdfd- The DF-Description that is currently registered with the DFdeadline- The time until which the currenlty registered DF-Description must be kept valid. Use null to indicate an infinite time
-
search
public static DFAgentDescription[] search(Agent a, AID dfName, DFAgentDescription dfd, SearchConstraints constraints) throws FIPAException
Searches for data contained within a DF agent.- Parameters:
a- is the Agent requesting the searchdfName- The AID of the DF agent to start search from.dfd- ADFAgentDescriptionobject containing data to search for; this parameter is used as a template to match data against.constraints- of the search- Returns:
- An array of
DFAgentDescriptioncontaining all found items matching the given descriptor, subject to given search constraints for search depth and result size. - Throws:
FIPAException- If aREFUSE,FAILUREorNOT_UNDERSTOODmessage is received from the DF (to indicate some error condition)
-
search
public static DFAgentDescription[] search(Agent a, DFAgentDescription dfd, SearchConstraints constraints) throws FIPAException
The default DF is used.
-
search
public static DFAgentDescription[] search(Agent a, DFAgentDescription dfd) throws FIPAException
The default DF is used. The default SearchConstraints are used. According to FIPA they are defaulted to null value for all slots.
-
search
public static DFAgentDescription[] search(Agent a, AID dfName, DFAgentDescription dfd) throws FIPAException
The default SearchConstraints are used. According to FIPA they are defaulted to null value for all slots.
-
searchUntilFound
public static DFAgentDescription[] searchUntilFound(Agent a, AID dfName, DFAgentDescription dfd, SearchConstraints constraints, long timeout) throws FIPAException
Searches the DF and remains blocked until a result is found or the specified timeout has expired.- Parameters:
a- The agent that is performing the searchdfName- The AID of the DF agent where to search into.template- ADFAgentDescriptionobject that is used as a template to identify the DF descriptions to search for.constraints- The constraints to limit the number of results to be sent back.timeout- The maximum amount of time that we want to remain blocked waiting for results.- Returns:
- The DF agent descriptions matching the specified template or
nullif the timeout expires. - Throws:
FIPAException- If aREFUSE,FAILUREorNOT_UNDERSTOODmessage is received from the DF (to indicate some error condition) or if the supplied DF-Description template is not valid.
-
createRequestMessage
public static ACLMessage createRequestMessage(Agent a, AID dfName, String action, DFAgentDescription dfd, SearchConstraints constraints)
Utility method that creates a suitable message to be used to REQUEST a DF agent to perform a given action of the FIPA-Management-ontology.This method can be fruitfully used in combination with the
jade.proto.AchieveREInitiatorprotocol and with thedecodeDone()anddecodeResult()methods to interact with a DF in a non-blocking way.- Parameters:
a- The agent that is requesting the DFdfName- The AID of the DF agent to send the request to.action- The name of the requested action. This must be one ofFIPAManagementVocabulary.REGISTERFIPAManagementVocabulary.DEREGISTERFIPAManagementVocabulary.MODIFYFIPAManagementVocabulary.SEARCH
dfd- ADFAgentDescriptionobject. Depending on the requested action, this is the description to register/deregister/modify or a template to match data against during a search.constraints- The constraints to limit the number of results to be notified. This is meaningful only if the requested action is SEARCH.- Returns:
- the request message.
- See Also:
AchieveREInitiator,decodeDone(String),decodeResult(String)
-
createSubscriptionMessage
public static ACLMessage createSubscriptionMessage(Agent a, AID dfName, DFAgentDescription template, SearchConstraints constraints)
Utility method that creates a suitable message to be used to SUBSCRIBE to a DF agent in order to receive notifications when a new DF-Description matching the indicated template is registererd with that DF.This method can be fruitfully used in combination with the
jade.proto.SubscriptionInitiatorprotocol and with thecreateCancelMessage()anddecodeNotification()methods to interact with a DF in a non-blocking way.- Parameters:
a- The agent that is subscribing to the DFdfName- The AID of the DF agent to subscribe to.template- ADFAgentDescriptionobject that is used as a template to identify DF description that will be notifiedconstraints- The constraints to limit the number of results to be notified.- Returns:
- the subscription message.
- See Also:
SubscriptionInitiator,createCancelMessage(Agent, AID, ACLMessage),decodeNotification(String)
-
getSubscriptionMessage
public static ACLMessage getSubscriptionMessage(Agent a, AID dfName, DFAgentDescription template, SearchConstraints constraints) throws FIPAException
Deprecated.UsecreateSubscriptionMessage()instead- Throws:
FIPAException
-
createCancelMessage
public static ACLMessage createCancelMessage(Agent a, AID dfName, ACLMessage subscribe)
Utility method that creates a suitable message to be used to CANCEL a subscription to a DF agent.- Parameters:
a- The agent that wants to cancel its subscription to the DFdfName- The AID of the DF agent.subscribe- The subscription message previously sent to the DF- Returns:
- the cancel message.
- See Also:
SubscriptionInitiator,createSubscriptionMessage(Agent, AID, DFAgentDescription, SearchConstraints),decodeNotification(String)
-
decodeDone
public static DFAgentDescription decodeDone(String s) throws FIPAException
Process the content of the finalinform (Done)message resulting from aregisterorderegisteraction requested to a DF agent, extracting thedf-agent-descriptioncontained within.- Returns:
- The
DFAgentDescriptionobject included in the "done" expression used as the content of the INFORM message send back by the DF in response to a REQUEST to perform a register, deregister or modify action. - Throws:
FIPAException- If some error occurs while decoding
-
decodeResult
public static DFAgentDescription[] decodeResult(String s) throws FIPAException
Process the content of the finalinform (result)message resulting from asearchaction requested to a DF agent, extracting the array ofdf-agent-descriptioncontained within.- Returns:
- The
DFAgentDescriptionobjects (as an array) included in the "result" expression used as the content of the INFORM message send back by the DF in response to a REQUEST to perform a search action. - Throws:
FIPAException- If some error occurs while decoding
-
decodeNotification
public static DFAgentDescription[] decodeNotification(String s) throws FIPAException
Process the content of theinformmessage resulting from a subscription with a DF agent, extracting the array ofdf-agent-descriptionobjects contained within.- Returns:
- The
DFAgentDescriptionobjects (as an array) included in the "(= (iota...) ...)" expression used as the content of an INFORM message sent back by the DF as a subscription notification. - Throws:
FIPAException- If some error occurs while decoding
-
parseAID
public static AID parseAID(SimpleSLTokenizer parser) throws Exception
The parser content has the form: agent-identifier ......)- Throws:
Exception
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, AID dfName, String actionName, DFAgentDescription dfd, SearchConstraints constraints) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadIn some cases it is more convenient to execute this tasks in a non-blocking way. This method returns a non-blocking behaviour that can be added to the queue of the agent behaviours, as usual, by usingAgent.addBehaviour().Several ways are available to get the result of this behaviour and the programmer can select one according to his preferred programming style:
- call getLastMsg() and getSearchResults() where both throw a NotYetReadyException if the task has not yet finished;
- create a SequentialBehaviour composed of two sub-behaviours: the first subbehaviour is the returned RequestFIPAServiceBehaviour, while the second one is application-dependent and is executed only when the first is terminated;
- use directly the class RequestFIPAServiceBehaviour by extending it and overriding all the handleXXX methods that handle the states of the fipa-request interaction protocol.
- Parameters:
a- is the agent performing the taskdfName- is the AID of the DF that should perform the requested actionactionName- is the name of the action (one of the constants defined in FIPAManagementOntology: REGISTER / DEREGISTER / MODIFY / SEARCH).dfd- is the agent descriptionconstraints- are the search constraints (can be null if this is not a search operation)- Returns:
- the behaviour to be added to the agent
- Throws:
FIPAException- A suitable exception can be thrown to indicate some error condition locally discovered (e.g.the agentdescription is not valid.)- See Also:
FIPAManagementOntology
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, String actionName, DFAgentDescription dfd, SearchConstraints constraints) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadThe default DF is used.
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, String actionName) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadThe default DF is used. the default SearchContraints are used. a default AgentDescription is used, where only the agent AID is set.
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, AID dfName, String actionName) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadthe default SearchContraints are used. a default AgentDescription is used, where only the agent AID is set.
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, String actionName, DFAgentDescription dfd) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadThe defautl DF is used. the default SearchContraints are used.
-
getNonBlockingBehaviour
public static RequestFIPAServiceBehaviour getNonBlockingBehaviour(Agent a, AID dfName, String actionName, DFAgentDescription dfd) throws FIPAException
Deprecated.UseAchieveREInitiatorinsteadthe default SearchContraints are used.
-
-