2.8 Confidence
3.1.4 Agent
p u b l i c a b s t r a c t c l a s s A g e n t e x t e n d s P e r i o d i c S e r v i c e i m p l e m e n t s I M e s s a g e H a n d l i n g A g e n t
This abstract class represents an agent in the MAS that is run on a OCmNode (see Sec-tion 2.1). It is thus a concrete implementaSec-tion of the TEM’s PeriodicService (see Section 2.4) and further provides additional methods to request the current time and to simplify message handling by implementing the IMessageHandlingAgent interface.
Although the TEMAS hides the complexity of the underlying infrastructure, the Agent can provide information about the OCmNode it runs on. Note that basic Agents cannot make use of the TEM’s Trust Metric Infrastructure (see Section 2.7). If an agent should be able to make use of the Trust Metric Infrastructure, it has to extend the TrustAgent (see Section 3.5.2).
3While it is undefined which reply is returned, usually the first reply that is received should be returned
Constructors Creates a new Agent and an instance of the given timeProviderClass used to retrieve the current time. The serviceBindingProvider (see Section 3.2.9) can be used later on to generate and query the service bindings of specific types of Agents.
In general, service bindings specify the agent or a group of agents that should receive a message.
p u b l i c A g e n t ( S e r v i c e B i n d i n g P r o v i d e r s e r v i c e B i n d i n g P r o v i d e r , Class <? e x t e n d s D e f a u l t T i m e P r o v i d e r > t i m e P r o v i d e r C l a s s ) { . . . }
Important Members
identifier: A unique identifier that unambiguously identifies this agent (see Sec-tion 3.1.5).
p r o t e c t e d A g e n t I d e n t i f i e r i d e n t i f i e r ;
timeProvider: The DefaultTimeProvider from which the current time is re-trieved (see Section 3.6.2).
p r i v a t e D e f a u l t T i m e P r o v i d e r t i m e P r o v i d e r ;
SIMULATE TEM MESSAGE TRANSPORT: Switches serialization and de-serialization of data sent via messages on or off. This should only be activated if the application is deployed in the temLight simulation environment (see Section 4).
p u b l i c s t a t i c f i n a l b o o l e a n S I M U L A T E _ T E M _ M E S S A G E _ T R A N S P O R T = f a l s e;
DEFAULT TIMEOUT: A predefined amount of time (in ms) Agents wait for reply messages.
p u b l i c s t a t i c f i n a l int D E F A U L T _ T I M E O U T = 5 0 0 0 ;
Important Methods
initAgent: Initializes an Agent with the given data, which might be null if no data is necessary. If a customized initialization of an Agent implementation is necessary, this method must be overridden.
p u b l i c v o i d i n i t A g e n t ( Map < String , S e r i a l i z a b l e > i n i t D a t a ) { . . . }
achieveGoals: The method periodically called by the underlying MAS that in-forms the agent to pursue its goals. For example, in the TEM execution envi-ronment (see Section 4), this method is triggered when the PeriodicService’s step() method is called (see Section 2.4). Consequently, all actions that should be periodically performed by this Agent should be called in this method in the right order. This method is declared in the interface IAgent (see Section 3.1.1).
p u b l i c v o i d a c h i e v e G o a l s () { . . . }
Because it is not ensured that the default implementation of achieveGoals() is empty, subclasses of Agent should always call super.achieveGoals() first:
p u b l i c c l a s s M y A g e n t e x t e n d s A g e n t {
getPrimitives: A static method that gets the Agent’s primitives, which define the messages the Agent can receive. By default, this is an instance of AgentPrimitives.
This method is similar to the getPrimitives() method declared in the class AgentComponent (see Section 3.1.6).
p u b l i c s t a t i c A g e n t P r i m i t i v e s g e t P r i m i t i v e s () { . . . }
Subclasses of Agent can specify a subclass of AgentPrimitives and refine the getPrimitives() method. If the primitives of an imaginary class MyAgent are de-fined in an imaginary class MyAgentPrimitives, MyAgent refines getPrimitives() as follows:
getAgentIdentifier: Gets the unique identifier in the form of a string that unambiguously identifies this Agent (see Section 3.1.5).
p u b l i c S t r i n g g e t A g e n t I d e n t i f i e r () { . . . }
getActualAgentIdentifier: Gets, in contrast to getAgentIdentifier(...), the Agent’s unique identifier in the form of an AgentIdentifier (see Section 3.1.5).
p u b l i c A g e n t I d e n t i f i e r g e t A c t u a l A g e n t I d e n t i f i e r () { . . . }
getCurrentTime: Returns the current time in form of a GregorianCalendar (see Java documentation). The time is requested from the Agent’s timeProvider (see Section 3.6.2).
p u b l i c G r e g o r i a n C a l e n d a r g e t C u r r e n t T i m e () { . . . }
getInterval: Returns the time in milliseconds for the interval between the calls of the step() method triggered by the TEM. This value is only regarded when using the asynchronous execution model in the TEM execution environment (see Section 4.1 and Section 4.3).
p r o t e c t e d l o n g g e t I n t e r v a l () { . . . }
getServiceId: Gets the service id of the service represented by this agent (see Section 3.1.5).
p u b l i c S t r i n g g e t S e r v i c e I d () { . . . }
getServiceType: Returns the service type of this service (Agents implement the interface Service, presented in Section 2.2). The service type is a part of the service id. By default, the service type of all agents is the Java fully qualified class name of the class Agent (see method getServiceTypeForClass).
p u b l i c S t r i n g g e t S e r v i c e T y p e () { . . . }
getServiceTypeForClass: Returns the service type of this Agent. By default, this is the Java fully qualified class name of the class Agent.
p u b l i c s t a t i c S t r i n g g e t S e r v i c e T y p e F o r C l a s s () { . . . }
getNodeId: Gets the identifier of the OcmNode that currently hosts this agent (see Section 3.1.5).
p r o t e c t e d S t r i n g g e t N o d e I d () { . . . }
discoverAgents: This method uses the Discovery functionality of OCµ (see Section 2.6). Calling this method starts a discovery of Agents that are bound to at least one of the given service bindings. Note that this method might not find all Agents in the system that are bound to one of the service bindings if the TEM simulation environment is used (see Section 4). Waits at most timeout milliseconds for the results. The method returns a DiscoveryTask (see Section 3.3.1) running in a separate thread that returns the result in the form of a DefaultDiscoveryResult (see Section 3.3.2) if finished. The DefaultDiscoveryResult can be evaluated with the method evaluateDiscoveryResult below.
p r o t e c t e d D i s c o v e r y T a s k d i s c o v e r A g e n t s (int timeout , S t r i n g ... s e r v i c e B i n d i n g s ) { . . . }
evaluateDiscoveryResult: Evaluates a DefaultDiscoveryResult by extracting and returning a set of AgentIdentifiers of Agents that have been identified in the course of a discovery. For an example how to use this and the method above, see Section 3.3.
p r o t e c t e d Set < A g e n t I d e n t i f i e r > e v a l u a t e D i s c o v e r y R e s u l t ( D e f a u l t D i s c o v e r y R e s u l t d i s c o v e r y R e s u l t ) { . . . }
sendEvent, sendRequest, waitForReply, sendRequestAndWaitForReply, broadcastEvent, broadcastRequest, broadcastRequestAndWaitForReply:
These methods implement the messaging functionality (see Section 3.1.3) on the basis of OCµ’s MessageSender and EventMessages. Note that the Agent throws, in contrast to the IMessageHandlingAgent, a ReplyMessageException instead of a common RuntimeException.
p u b l i c U U I D s e n d E v e n t ( S t r i n g a g e n t I d e n t i f i e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e d a t a ) { . . . }
p u b l i c U U I D s e n d R e q u e s t ( S t r i n g a g e n t I d e n t i f i e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e d a t a ) { . . . }
p u b l i c S e r i a l i z a b l e w a i t F o r R e p l y ( U U I D m e s s a g e I d e n t i f i e r , S t r i n g a g e n t I d e n t i f i e r , S t r i n g t h e P r i m i t i v e , int t i m e o u t ) t h r o w s T i m e o u t E x c e p t i o n , R e p l y M e s s a g e E x c e p t i o n { . . . }
p u b l i c S e r i a l i z a b l e s e n d R e q u e s t A n d W a i t F o r R e p l y ( S t r i n g a g e n t I d e n t i f i e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e data , int t i m e o u t )
t h r o w s T i m e o u t E x c e p t i o n , R e p l y M e s s a g e E x c e p t i o n { . . . }
p u b l i c U U I D b r o a d c a s t E v e n t ( S t r i n g t y p e O f R e c e i v e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e d a t a ) { . . . }
p u b l i c U U I D b r o a d c a s t R e q u e s t ( S t r i n g t y p e O f R e c e i v e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e d a t a ) { . . . }
p u b l i c S e r i a l i z a b l e b r o a d c a s t R e q u e s t A n d W a i t F o r R e p l y ( S t r i n g t y p e O f R e c e i v e r , S t r i n g t h e P r i m i t i v e , S e r i a l i z a b l e data , int t i m e o u t )
t h r o w s T i m e o u t E x c e p t i o n , R e p l y M e s s a g e E x c e p t i o n { . . . }
Usage The Agent is the major concept of the TEMAS. If you want to implement a trust-aware Agent, extend the concept TrustAgent (see Section 3.5.2).