Package fr.dyade.aaa.agent
Class AgentId
- java.lang.Object
-
- fr.dyade.aaa.agent.AgentId
-
- All Implemented Interfaces:
Encodable,Serializable
public final class AgentId extends Object implements Serializable, Encodable
AnAgentIdallows 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.
- See Also:
AgentIdStamp, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intAMQPAgentStampReserved stamp for AMQPAgent.static intControlTopicStampReserved stamp for JMS topicAgentIdin charge of sending control events.(package private) static AgentIdfactoryIdAgentIdfor local factory agent.static intFactoryIdStampReserved stamp for factoryAgentId.static intFileTransfertStampReserved stamp for fileTransfert serviceAgentId.(package private) shortfromThe identification of the agent server hosting the creating agent.static intJndiServiceStampReserved stamp for JNDI serviceAgentId.static intJoramAdminPxStampReserved stamp for JORAM administration proxyAgentId.static intJoramAdminStampReserved stamp for JORAM administration topicAgentId.(package private) static AgentIdlocalIdUsed by channel to send messages without source agent (from proxy or engine).static intLocalJndiServiceStampReserved stamp for local JNDI serviceAgentId.static intMaxIdStampMaximum reserved stamp.static intMaxSystemIdStampMaximum reserved stamp for system services.static intMaxWKSIdStampMaximum reserved stamp for well known services.static intMinWKSIdStampMinimum reserved stamp for well known services.static intMqttAgentStampReserved stamp for MQTT proxy agent.static intMqttDefault$TopicStampReserved stamp for MQTT default $ topic.static intMqttDefaultTopicStampReserved stamp for MQTT default topic.static intNameServiceStampReserved stamp for name serviceAgentId.static AgentIdnullIdnullAgentId.static intNullIdStampReserved stamp for NullId.static intResourceAgentStampReserved stamp for ResourceAgent.static intSCAdminProxyStampReserved stamp for SCAdmin proxyAgentId.static intSchedulerServiceStampReserved stamp for scheduler serviceAgentId.(package private) static longserialVersionUIDDefine serialVersionUID for interoperability.static intServerConfigStampReserved stamp for the server reconfiguration agentAgentId.(package private) intstampThe stamp, local to the agent server hosting the creating agent.private StringstrA temporary string representation of object in order to improve performances.(package private) shorttoThe identification of the agent server hosting the created agent.-
Fields inherited from interface fr.dyade.aaa.common.encoding.Encodable
BOOLEAN_ENCODED_SIZE, BYTE_ENCODED_SIZE, DOUBLE_ENCODED_SIZE, FLOAT_ENCODED_SIZE, INT_ENCODED_SIZE, LONG_ENCODED_SIZE, SHORT_ENCODED_SIZE
-
-
Constructor Summary
Constructors Constructor Description AgentId()Allocates anAgentIdobject for a new agent hosted by this agent server.AgentId(short to)Allocates anAgentIdobject for a new agent hosted by specified agent server.AgentId(short from, short to, int stamp)Allocates a newAgentIdobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddecode(Decoder decoder)Decodes the object.voidencode(Encoder encoder)Encodes the object.booleanequals(Object obj)Indicates whether some other agent id. is "equal to" this one.static AgentIdfactoryId(short sid)Returns theAgentIdfor a remote factory agent.static AgentIdfromString(String str)Parses the string argument as anAgentId.intgetEncodableClassId()The class id is still not defined.intgetEncodedSize()Returns the size of the encoded object.shortgetFrom()intgetStamp()shortgetTo()inthashCode()Returns a hashcode for thisAgentIdobject.(package private) static voidinit()Statically initializesAgentIdclass.booleanisLocal()booleanisNullId()static AgentIdlocalId(short sid)static intparseInt(String str, int idx, int end)Parses the string argument as a non signed integer.private voidreadObject(ObjectInputStream in)ThereadObjectis responsible for reading from the stream and restoring the classes fields.StringtoString()Returns a string representation of thisAgentIdobject.private voidwriteObject(ObjectOutputStream out)ThewriteObjectmethod is responsible for writing the state of the object for its particular class so that the correspondingreadObjectmethod can restore it.
-
-
-
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 factoryAgentId.- 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 serviceAgentId.
-
SchedulerServiceStamp
public static int SchedulerServiceStamp
Reserved stamp for scheduler serviceAgentId.
-
FileTransfertStamp
public static int FileTransfertStamp
Reserved stamp for fileTransfert serviceAgentId.
-
JndiServiceStamp
public static int JndiServiceStamp
Reserved stamp for JNDI serviceAgentId.
-
LocalJndiServiceStamp
public static int LocalJndiServiceStamp
Reserved stamp for local JNDI serviceAgentId.
-
SCAdminProxyStamp
public static int SCAdminProxyStamp
Reserved stamp for SCAdmin proxyAgentId.
-
JoramAdminStamp
public static int JoramAdminStamp
Reserved stamp for JORAM administration topicAgentId.
-
JoramAdminPxStamp
public static int JoramAdminPxStamp
Reserved stamp for JORAM administration proxyAgentId.
-
ControlTopicStamp
public static int ControlTopicStamp
Reserved stamp for JMS topicAgentIdin charge of sending control events.
-
ServerConfigStamp
public static int ServerConfigStamp
Reserved stamp for the server reconfiguration agentAgentId.
-
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
nullAgentId.
-
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)
-
factoryId
static AgentId factoryId
AgentIdfor local factory agent.- See Also:
AgentFactory
-
-
Constructor Detail
-
AgentId
AgentId() throws IOException
Allocates anAgentIdobject for a new agent hosted by this agent server.- Throws:
IOException- an error occurs.
-
AgentId
AgentId(short to) throws IOException
Allocates anAgentIdobject 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 newAgentIdobject.- 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
ThewriteObjectmethod is responsible for writing the state of the object for its particular class so that the correspondingreadObjectmethod can restore it.- Parameters:
out- the underlying output stream.- Throws:
IOException- an error occurs.
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
ThereadObjectis responsible for reading from the stream and restoring the classes fields.- Parameters:
in- the underlying input stream.- Throws:
IOException- an error occurs.ClassNotFoundException- an error occurs.
-
factoryId
public static final AgentId factoryId(short sid)
Returns theAgentIdfor a remote factory agent.- Parameters:
sid- remote server id.- Returns:
- the
AgentIdfor a remote factory agent.
-
localId
public static final AgentId localId(short sid)
-
init
static void init() throws IOException, ClassNotFoundExceptionStatically initializesAgentIdclass.- Throws:
IOException- an error occurs.ClassNotFoundException- an error occurs.
-
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- theStringcontaining 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 theStringdoes not contain a parsableint.
-
fromString
public static final AgentId fromString(String str)
Parses the string argument as anAgentId.- Parameters:
str- theStringcontaining the integer representation to be parsed.- Returns:
- The
AgentIdobject represented by the argument.
-
toString
public final String toString()
Returns a string representation of thisAgentIdobject. Note: This method is optimized, the string representation is cached in the AgentId object.
-
hashCode
public int hashCode()
Returns a hashcode for thisAgentIdobject.
-
isNullId
public final boolean isNullId()
- Returns:
trueif this id is equals to NullId;falseotherwise.
-
isLocal
public final boolean isLocal()
- Returns:
trueif this the 2 agents are colocated;falseotherwise.
-
equals
public boolean equals(Object obj)
Indicates whether some other agent id. is "equal to" this one. This method returnstrueif and only if obj is anAgentIdand refer to the same agent (from, to and stamp fields are equals).
-
getEncodableClassId
public int getEncodableClassId()
The class id is still not defined.- Specified by:
getEncodableClassIdin interfaceEncodable- Returns:
- a unique class identifier
-
getEncodedSize
public int getEncodedSize() throws ExceptionReturns the size of the encoded object.- Specified by:
getEncodedSizein interfaceEncodable- Returns:
- the size of the encoded object
- Throws:
Exception- if an error occurs
-
-