Class AgentId

  • All Implemented Interfaces:
    Encodable, Serializable

    public final class AgentId
    extends Object
    implements Serializable, Encodable
    An AgentId allows for uniquely identifying and localizing an agent throughout the distributed system. It defines variable members describing the identifier and all needed function members to manipulate the structure (creation, serialization, etc).
    However before describing the structure of an AgentId we must take into account a second requirement: an agent may be created onto a remote agent server, and the creating entity needs to know the new identifier created for that agent. As agents live in an asynchronous world it is not so easy to get back the identifier from the remote server. We decided instead to make the creating entity responsible for creating the identifier.

    The two requirements are then:

    • static localization of agents to allow the system to forward notifications ;
    • local generation of identifiers for remote agents.

    The AgentId is then built of three parts:
    • the identification of the agent server hosting the creating agent (from field),
    • the identification of the agent server hosting the created agent (to field),
    • a stamp, local to the agent server hosting the creating agent (stamp field) ; see AgentIdStamp class.
    The three fields form the unique global identifier of the agent, that is two agents may share a common stamp, as long as their from or to fields differ. The to field identifies the agent server hosting the agent, so it is used by the channel to forward notifications to the agent.
    See Also:
    AgentIdStamp, Serialized Form
    • Field Detail

      • serialVersionUID

        static final long serialVersionUID
        Define serialVersionUID for interoperability.
        See Also:
        Constant Field Values
      • from

        transient short from
        The identification of the agent server hosting the creating agent.
      • to

        transient short to
        The identification of the agent server hosting the created agent.
      • stamp

        transient int stamp
        The stamp, local to the agent server hosting the creating agent.
      • str

        private transient String str
        A temporary string representation of object in order to improve performances. TODO (AF): May be we should use a SoftReference.
      • NullIdStamp

        public static final int NullIdStamp
        Reserved stamp for NullId.
        See Also:
        Constant Field Values
      • FactoryIdStamp

        public static final int FactoryIdStamp
        Reserved stamp for factory AgentId.
        See Also:
        Constant Field Values
      • MaxSystemIdStamp

        public static final int MaxSystemIdStamp
        Maximum reserved stamp for system services.
        See Also:
        Constant Field Values
      • MinWKSIdStamp

        public static int MinWKSIdStamp
        Minimum reserved stamp for well known services.
      • NameServiceStamp

        public static int NameServiceStamp
        Reserved stamp for name service AgentId.
      • SchedulerServiceStamp

        public static int SchedulerServiceStamp
        Reserved stamp for scheduler service AgentId.
      • FileTransfertStamp

        public static int FileTransfertStamp
        Reserved stamp for fileTransfert service AgentId.
      • JndiServiceStamp

        public static int JndiServiceStamp
        Reserved stamp for JNDI service AgentId.
      • LocalJndiServiceStamp

        public static int LocalJndiServiceStamp
        Reserved stamp for local JNDI service AgentId.
      • SCAdminProxyStamp

        public static int SCAdminProxyStamp
        Reserved stamp for SCAdmin proxy AgentId.
      • JoramAdminStamp

        public static int JoramAdminStamp
        Reserved stamp for JORAM administration topic AgentId.
      • JoramAdminPxStamp

        public static int JoramAdminPxStamp
        Reserved stamp for JORAM administration proxy AgentId.
      • ControlTopicStamp

        public static int ControlTopicStamp
        Reserved stamp for JMS topic AgentId in charge of sending control events.
      • ServerConfigStamp

        public static int ServerConfigStamp
        Reserved stamp for the server reconfiguration agent AgentId .
      • ResourceAgentStamp

        public static int ResourceAgentStamp
        Reserved stamp for ResourceAgent.
      • AMQPAgentStamp

        public static int AMQPAgentStamp
        Reserved stamp for AMQPAgent.
      • MqttAgentStamp

        public static int MqttAgentStamp
        Reserved stamp for MQTT proxy agent.
      • MqttDefaultTopicStamp

        public static int MqttDefaultTopicStamp
        Reserved stamp for MQTT default topic.
      • MqttDefault$TopicStamp

        public static int MqttDefault$TopicStamp
        Reserved stamp for MQTT default $ topic.
      • MaxWKSIdStamp

        public static int MaxWKSIdStamp
        Maximum reserved stamp for well known services.
      • MaxIdStamp

        public static int MaxIdStamp
        Maximum reserved stamp.
      • nullId

        public static final AgentId nullId
        null AgentId.
      • localId

        static AgentId localId
        Used by channel to send messages without source agent (from proxy or engine). The from field does not be nullId because the destination node use the from.to field to get the from node id.
        See Also:
        Engine, Channel.sendTo(AgentId, Notification)
    • Constructor Detail

      • AgentId

        AgentId()
         throws IOException
        Allocates an AgentId object for a new agent hosted by this agent server.
        Throws:
        IOException - an error occurs.
      • AgentId

        AgentId​(short to)
         throws IOException
        Allocates an AgentId object for a new agent hosted by specified agent server.
        Parameters:
        to - The identification of the agent server hosting the agent.
        Throws:
        IOException - an error occurs.
      • AgentId

        public AgentId​(short from,
                       short to,
                       int stamp)
        Allocates a new AgentId object.
        Parameters:
        from - The identification of the agent server hosting the creating agent.
        to - The identification of the agent server hosting the agent.
        stamp - The stamp of agent.
    • Method Detail

      • writeObject

        private void writeObject​(ObjectOutputStream out)
                          throws IOException
        The writeObject method is responsible for writing the state of the object for its particular class so that the corresponding readObject method can restore it.
        Parameters:
        out - the underlying output stream.
        Throws:
        IOException - an error occurs.
      • factoryId

        public static final AgentId factoryId​(short sid)
        Returns the AgentId for a remote factory agent.
        Parameters:
        sid - remote server id.
        Returns:
        the AgentId for a remote factory agent.
      • localId

        public static final AgentId localId​(short sid)
      • getFrom

        public final short getFrom()
      • getTo

        public final short getTo()
      • getStamp

        public final int getStamp()
      • parseInt

        public static final int parseInt​(String str,
                                         int idx,
                                         int end)
                                  throws NumberFormatException
        Parses the string argument as a non signed integer. The characters in the substring must all be digits.
        Parameters:
        str - the String containing the integer representation to be parsed.
        idx - the beginning index, inclusive.
        end - the ending index, exclusive.
        Returns:
        the integer represented by the string argument.
        Throws:
        NumberFormatException - if the String does not contain a parsable int.
      • fromString

        public static final AgentId fromString​(String str)
        Parses the string argument as an AgentId.
        Parameters:
        str - the String containing the integer representation to be parsed.
        Returns:
        The AgentId object represented by the argument.
      • toString

        public final String toString()
        Returns a string representation of this AgentId object. Note: This method is optimized, the string representation is cached in the AgentId object.
        Overrides:
        toString in class Object
        Returns:
        A string representation of this object.
      • hashCode

        public int hashCode()
        Returns a hashcode for this AgentId object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code value for this object, equal to the primitive int value represented by the stamp field.
      • isNullId

        public final boolean isNullId()
        Returns:
        true if this id is equals to NullId; false otherwise.
      • isLocal

        public final boolean isLocal()
        Returns:
        true if this the 2 agents are colocated; false otherwise.
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other agent id. is "equal to" this one. This method returns true if and only if obj is an AgentId and refer to the same agent (from, to and stamp fields are equals).
        Overrides:
        equals in class Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
      • getEncodableClassId

        public int getEncodableClassId()
        The class id is still not defined.
        Specified by:
        getEncodableClassId in interface Encodable
        Returns:
        a unique class identifier
      • encode

        public void encode​(Encoder encoder)
                    throws Exception
        Encodes the object.
        Specified by:
        encode in interface Encodable
        Parameters:
        encoder - the encoder
        Throws:
        Exception - if an error occurs
      • decode

        public void decode​(Decoder decoder)
                    throws Exception
        Decodes the object.
        Specified by:
        decode in interface Encodable
        Parameters:
        decoder - the encoder
        Throws:
        Exception - if an error occurs
      • getEncodedSize

        public int getEncodedSize()
                           throws Exception
        Returns the size of the encoded object.
        Specified by:
        getEncodedSize in interface Encodable
        Returns:
        the size of the encoded object
        Throws:
        Exception - if an error occurs