Addresses
Three types of addresses are defined in the system:
- agent addresses,
- component addresses,
- node addresses.
All addresses are immutable through the entire lifetime of the system.
Agents and components addresses
Both agent and component addresses consists of two elements:
- some identifier (a name in the form of a string in case of a component and UUID for an agent)
- their parent node address (the node they were firstly registered at).
Moreover, agent addresses allows to use a user-friendly name that is meant to be presented to (and partially provided by) the end-user.
The string representation of the address is defined as a name@nodeAddress
for the default implementation of addresses. However, a name does not have to be unique in the case of agents. To get round this problem an agent interface requires an existence of the method that can create an unique string representation (toUniqueString()
). In the default implementation it has a following form: UUID@nodeAddress
.
Sample configuration of agent
Correct configuration of addresses for agents is very simple. The sample code below defines one agent whose address will be initialized with a value "Scully".
<agent name="scully" class="org.jage.examples.helloworld.HelloWorldSimpleAgent"> <property name="nameInitializer"> <value value="Scully" class="String" /> </property> </agent>
As one can see the only needed configuration is the name initializer for the agent.
A declaration of the name initialization value is not required. If not provided, a string representation of a UUID will be used.
Nodes addresses
A node address interface does not distinguish any parts. It is not transparent to the user and agents but its standard representation as a string is user-friendly. The default implementation consists of a JVM process ID and a hostname its running on.
Address providers
There are three components responsible for generating addresses in a node:
- an address provider creates agent addresses on demand,
- a name provider generates user friendly names from templates and is used by the address provider,
- a node address provider creates a node address instance on demand (and it is used by the address provider, too).
An agent needs only to interact with the IAgentAddressProvider
.
Sample configuration of IAgentAddressProvider
The code below shows the fragment of the configuration that defines all three components. It is recommended to declare both the name provider and the agent address provider in the workplace manager, as they are relevant only to agents.
<component name="nodeAddressProvider" class="org.jage.address.node.provider.DefaultNodeAddressProvider" isSingleton="true" /> <component name="workplaceManager" class="org.jage.pico.PicoWorkplaceManager" isSingleton="true"> <component name="nameProvider" class="org.jage.address.provider.DefaultNameProvider" isSingleton="true" /> <component name="addressProvider" class="org.jage.address.provider.DefaultAgentAddressProvider" isSingleton="true"/> ... </component>
Minimal configuration
When using default implementations it is enough to declare the address provider.
<component name="addressProvider" class="org.jage.address.provider.DefaultAgentAddressProvider" isSingleton="true"/>
How can agent obtain its address?
If you are subclassing the AbstractAgent
class all the work is done for you. You only have to remember:
- if you override override
init()
method, do not forget to callĀsuper.init()
at the begining
If the agent is not a subclass of the AbstractAgent
class, the simplest code for getting an address is:
IAgentAddressProvider addressProvider = instanceProvider.getInstance(IAgentAddressProvider.class); if (addressProvider == null) { throw new ComponentException("No implementation of IAgentAddressProvider available."); } address = addressProvider.obtainAddress(nameInitializer);