|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object
|
+--java.lang.Thread
|
+--com.ls.lars.communication.CommunicationTemplate
|
+--com.ls.lars.server.AgentTemplate
|
+--com.ls.lars.server.AgentMessageRouter
This class is the wrapper agent for the MessageRouter class.
Almost every agent sends AgentMessageRouter a register message in its initialization phase
(see AgentTemplate.initializeMessages()) to become registered in the
local platform's message router.
If an agent terminates, it sends a sender_rip service message (AgentMessageRouter is a service provider
for that), see AgentTemplate.terminateAction()).
Additionally AgentMessageRouter is responsible for registerering and unregistering service providers.
It is also responsible for maintaining message groups to which agents can be subscribed and unsubscribed.
Finally AgentMessageRouter is used by agents that have moved, to tell their home platform's message router
their new location.
Note: AgentMessageRouter logs ERROR and WARNING log information in both the system's log file and it's own log file, all log messages with a less important log level are logged only in AgentMessageRouter's own log file.
Incoming Messages:
AgentMessageRouter offers the following services.
Input parameters you have to specify are listed with the messages
and must be transmitted using a Map.
-----------------------------------------------------------------------
notify_agent_connected
-----------------------------------------------------------------------
Function: Registers the sender of this message at the
AgentMessageRouter for being notified, as soon as
one or more defined agent(s) got connected to
the local platform.
Parameters: awaitedAgent (String or Map)
Responses: agent_connected, as soon as awaitedAgent has been
connected to the platform.
Content of this message is the name of the connected
agent.
-----------------------------------------------------------------------
agent_connected
-----------------------------------------------------------------------
Function: Notifies the AgentMessageRouter that a given agent
connectedAgent is available on the platform.
When the AgentMessageRouter receives this message,
it will notify all registered agents, who wants
to get informed about the availability of
connectedAgent.
Note:
The AgentMessageRouter interprets this message for
internal use, only. Therefore the AgentMessageRouter
checks the sender of this message in order to prevent
any misuse of it.
Parameters: connectedAgent (String)
Responses: none
-----------------------------------------------------------------------
notify_service_status_changed
-----------------------------------------------------------------------
Function: Registers the sender of this message at the
AgentMessageRouter for being notified, when the status of a
defined service has changed (i.e. a service provider
registers or unregisters for that service).
Parameters: awaitedService (String)
Response: service_status_changed, every time the status of that service
has changed.
Content of this message is:
- the name of the service
- the string "INCREASED" or "DECREASED", depending whether
a service provider did register or unregister
- the actual number of service providers for that service
Note:
The 'service_status_changed' response message can only be
sent by the message router. If you want to prevent the
misuse of this message by other parties, you should ensure
the message's sender to be Message.ADDRESS_LARS_INTERNAL.
-----------------------------------------------------------------------
initialize_inbox_check
-----------------------------------------------------------------------
Function: Registers this agent to the notifierAgent
(mostly AgentCron) for being notified regularly,
in order to check the inbox size of all connected
messengers. This check implies a warning, which
will be written to the SystemLogger, if the size of
an inbox exceeds the given delimiterSize.
The period of getting notified will
be structured as in AgentCron.
Parameters: notifierAgent (String)
delimiterSize (String)
period (Map) (compare AgentCron).
For configuring the inbox_check the right way, you should place the
following message into the config file of AgentMessageRouter
(the period definition can be changed to your needs):
startup_constraint
AgentCron
check_inbox_size
3
AgentCron
INTERVAL
10
0
0
Responses: none
-----------------------------------------------------------------------
check_inbox_size
-----------------------------------------------------------------------
Function: Tells the AgentMessageRouter to check the inboxes
of all connected messengers.
Normally, this message is being sent from the
notifierAgent as given in the
initialize_inbox_check message.
Parameters: none
Responses: none
-----------------------------------------------------------------------
agent_not_notified
-----------------------------------------------------------------------
Function: Informs the AgentMessageRouter that its notification
request per notify_agent has not been
processed properly.
Parameters: same information as being sent with the according
notify_agent message
Responses: none
-----------------------------------------------------------------------
register
-----------------------------------------------------------------------
Function: Tells the lars platform's message router to forward any
messages to the sender to the agent message router
specified in the parameter. The newMessageRouter is the
complete address of the agent message router which will
handle further messages to the sender.
Parameters: newMessageRouter (String)
Responses: none
-----------------------------------------------------------------------
unregister
-----------------------------------------------------------------------
Function: Removes a forwarding entry from the platform's
message router.
Parameters: none
Responses: none
-----------------------------------------------------------------------
register_service
-----------------------------------------------------------------------
Function: sender wants to become a service provider for the
given services
Parameters: service (String) or services (List);
The service(s) this agent wants to become a service
provider for.
Responses: none
Note: If multiple services are specified (message content is a
Collection), the agent is registered as service provider for
all services or for none of them.
-----------------------------------------------------------------------
unregister_service
-----------------------------------------------------------------------
Function: sender doesn't want to be a service provider for
the specified services any more
Parameters: service (String) or services (List);
The service(s) this agent doesn't want
to be a service provider for any more.
Responses: none
-----------------------------------------------------------------------
unregister_all_services
-----------------------------------------------------------------------
Function: sender doesn't want to be a service provider for any
service
Parameters: none
Responses: none
-----------------------------------------------------------------------
subscribe_to_message_group
-----------------------------------------------------------------------
Function: subscribes a single agent or a list of agents
to the specified message group. If the group
is not existing, a new group is created.
Any message sent to this group will be
published to all subscribed agents.
Parameters: group: the name of the group to subscribe to.
agent (String) or agent (List):
the agent(s) that should be subscribed
transaction (String):
on (default): subscribe all agents or none of them
off: subscribe as many agents as possible
Responses: subscribe_to_message_group_succeeded:
if all agent(s) could be subscribed,
content of the answer is the content of the request
subscribe_to_message_group_failed:
if the agent(s) could not be subscribed,
content of the answer is the content of the request
subscribe_to_message_group_partially:
If not all agents could be subscribed.
This answer can be sent only, if the parameter
'transaction' of the request was set to 'off'.
Content of this answer is the content of
the request plus the two additional keys/value pairs:
succeeded: value is a collection of names of agents,
that are now subscribed to the message
group
failed: value is a collection of names of agents,
that could not be subscribed to the
message group
Note: If multiple agents are specified (value of key 'agent' in
message content is a Collection), all of those agents are
added to the specified message group or none of them.
-----------------------------------------------------------------------
unsubscribe_from_message_group
-----------------------------------------------------------------------
Function: unsubscribes a single agent or a list of
agents from the specified message group.
If the group gets empty it is removed from
the list of message groups.
Parameters: group: the name of the group to unsubscribe from
agent (String) or agent (List);
The agent(s) that should be unsubscribed.
Responses: unsubscribe_from_message_group_succeeded
if all agents could be unsubscribed
unsubscribe_from_message_group_failed
if not all agents could be unsubscribed
Content of both messages is the content of
the original message.
-----------------------------------------------------------------------
unsubscribe_from_all_message_groups
-----------------------------------------------------------------------
Function: unsubscribes a single agent from all message
groups it is subscribed to. All groups that
get empty are removed from the list of
message groups.
Parameters: agent (String)
The agent that should be unsubscribed.
Responses: unsubscribe_from_all_message_groups_succeeded
if the agent could be unsubscribed from
all groups.
unsubscribe_from_all_message_groups_failed
if the agent could not be unsubscribed
from all groups.
Content of both messages is the content of
the original message.
-----------------------------------------------------------------------
remove_message_group
-----------------------------------------------------------------------
Function: removes a complete message group from the
list of message groups
Parameters: group (String)
the name of the group that should be removed
Responses: remove_message_group_succeeded
if the group could be removed, or did not exist
remove_message_group_failed
if the message or the group name are malformed
Content of both messages is the content of
the original message.
-----------------------------------------------------------------------
close_connection
-----------------------------------------------------------------------
Function: AgentMessageRouter will instruct the underlying
message router to send a 'close_connection'
message to all connected messengers.
Parameters: none
Responses: none
Note: This message can be send either by the AgentManager,
or by the message router. Other originators will
be ignored.
-----------------------------------------------------------------------
sender_rip
-----------------------------------------------------------------------
Function: sender died and wants all references to him
to be removed (service registrations, message groups,
forwards, agent connect-notifications)
Parameters: none
Responses: none
-----------------------------------------------------------------------
log_system_information
-----------------------------------------------------------------------
Function: logs all known services, message groups and platforms
Parameters: none
Responses: none
-----------------------------------------------------------------------
ask_group_members
-----------------------------------------------------------------------
Function: asks for members of one or multiple message groups
Parameters: Map with
key 'group': value is a String or a List of Strings
specifying the name of the group(s) the
sender is interested in
Response: response_group_members message:
hash content contains the key 'group' and as value one
Map or a List of maps (one for each
group of the request) with
- the key 'name' and as value the group name
- the key 'agent' and as value the subscribed
agent(s) (String or List)
- the key 'error' and as value
ILarsConstants.NO_GROUP_AVAILABLE, if the group
does not exist or is empty
-----------------------------------------------------------------------
ask_service_provider_members
-----------------------------------------------------------------------
Function: asks for providers for one or multiple services
Parameters: Map with
key "service_provider":
value is a String or a List of Strings
specifying the name of the service(s)
the sender is interested in
Response: response_service_provider_members message:
hash content contains the key "service_provider" and
as value one Map or a List of Maps (one
for each service of the request) with
- the key 'name' and as value the service name
- the key 'agent' and as value the service provider
agent(s) (String or List)
- the key 'error' and as value
ILarsConstants.NO_SERVICE_PROVIDER_AVAILABLE,
if the service is unknown or no service providers
for it are registered
-----------------------------------------------------------------------
show_all_provided_services
-----------------------------------------------------------------------
Function: asks for a list of services, which are provided on the
local lars platform.
Parameters: none
Response: provided_services message:
hash content contains the key "service" and as value a
List with the names of all provided services.
---------------------------------------------------------------------------
Config File:
AgentMessageRouter does not have a config file by default.
It should however register the log_system_information service
(with help of a register_service message in its config file)
if system information should be available in the logfile:
When the message router shall watch the inbox size of all
connected messengers, the config file of AgentMessageRouter
has to contain the according settings for sending the required
'initialize_inbox_check' message. As the initialization of the
inbox checks sends a 'notify_agent' to the given notifier agent,
the config file of AgentMessageRouter should contain an adequate
'startup_constraint' message (compare to AgentTemplate).
| Field Summary | |
protected String |
revisionInformation
revision information string, managed by our version control system |
| Fields inherited from class com.ls.lars.communication.CommunicationTemplate |
agentName, homePlatform, iPKIHandler, logger, STATUS_CONNECTED, STATUS_NOT_CONNECTED |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
AgentMessageRouter(String agentName,
String homePlatform,
List agentConfigFiles)
Constructor with the agentName, its homePlatform and a List containing
the names of the configuration file(s) of the new agent.It calls super(agentName, homePlatform, agentConfigFiles) and gets a reference
to the local platform's message router by calling
MessageRouter.getMessageRouter(). |
|
| Method Summary | |
void |
executeWhileRunning()
Receives a message from this agent's inbox. |
protected String |
getRevisionInformation()
gets the revision information of this agent |
void |
initializeMessages()
Registers as a service provider for "sender_rip" service, that is sent, if an agent terminates. |
protected boolean |
interpretAgentConnected(Message currentMessage)
Notifies this agent that a specifc agent has been connected to the platform |
protected boolean |
interpretAgentNotNotified(Message currentMessage)
Writes a log message to the system's log file and to the agent's log file, because a "agent_not_notified" message was received (probably from AgentCron). |
protected boolean |
interpretAskGroupMembers(Message currentMessage)
interprets the message "ask_group_members" and responds by sending the names of the agents to the requester |
protected boolean |
interpretAskServiceProviderMembers(Message currentMessage)
interprets the message "ask_service_providers_members" and responds by sending the names of the agents to the requester |
protected boolean |
interpretCheckInboxSize(Message currentMessage)
Checks the inbox size of all local agents. |
protected boolean |
interpretCloseConnection(Message currentMessage)
Instructs the underlying message router to forward this 'close_connection' to all connected messengers. |
protected boolean |
interpretInitializeInboxCheck(Message currentMessage)
Initializes the settings for periodical checking the inbox size of all messengers. |
protected boolean |
interpretLogSystemInformation(Message currentMessage)
Writes all registered services to the system logfile. |
protected boolean |
interpretNotifyAgentConnected(Message currentMessage)
Asks AgentMessageRouter to notify the sender of the given message, if any of the agents given in the content of this message connects or is currently connected. |
protected boolean |
interpretNotifyServiceStatusChanged(Message currentMessage)
Asks AgentMessageRouter to notify the sender of the given message, if the status of the given service has changed. |
protected boolean |
interpretRegister(Message currentMessage)
registers the sender of the given message in this platform's message router |
protected boolean |
interpretRegisterService(Message currentMessage)
Adds an agent to the list(s) of service providers for the specified service(s). |
protected boolean |
interpretRemoveMessageGroup(Message currentMessage)
Removes the specified message group from the list of all message groups. |
protected boolean |
interpretSenderRip(Message currentMessage)
Removes an agent from all lists of service providers, afterwards that agent is no service provider any more. |
protected boolean |
interpretShowAllProvidedServices(Message currentMessage)
interprets the message "show_all_provided_services", which returns the names of all services being provided on the local lars platform. |
protected boolean |
interpretSubscribeToMessageGroup(Message currentMessage)
Adds the specified agent(s) to the message group specified. |
protected boolean |
interpretUnregister(Message currentMessage)
deletes the sender of the given message from register in MessageRouter |
protected boolean |
interpretUnregisterAllServices(Message currentMessage)
Removes an agent from all lists of service providers, afterwards that agent is no service provider any more. |
protected boolean |
interpretUnregisterService(Message currentMessage)
Removes an agent from the list(s) of service providers for the specified service(s) |
protected boolean |
interpretUnsubscribeFromAllMessageGroups(Message currentMessage)
Removes the specified agent from all message groups existing. |
protected boolean |
interpretUnsubscribeFromMessageGroup(Message currentMessage)
Removes the specified agent(s) from the message group specified. |
boolean |
terminateAction()
Checks, if AgentMessageRouter's run level is less than STOPPED and AgentMessageRouter has clients waiting for connection notifications AgentMessageRouter has service provider(s) as clients AgentMessageRouter has message group member(s) as clients If none of those conditions is true, super.terminateAction is called. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.ls.lars.communication.IToLars |
start |
| Field Detail |
protected String revisionInformation
| Constructor Detail |
public AgentMessageRouter(String agentName,
String homePlatform,
List agentConfigFiles)
List containing
the names of the configuration file(s) of the new agent.super(agentName, homePlatform, agentConfigFiles) and gets a reference
to the local platform's message router by calling
MessageRouter.getMessageRouter().agentName - name of the agent (example: xyz )homePlatform - name of the home platform where the agent was created
(example: 195.52.158.233/lars)agentConfigFiles - config file(s), which should be read by the agent
when it starts up.| Method Detail |
protected String getRevisionInformation()
getRevisionInformation in class AgentTemplatepublic void initializeMessages()
Note: AgentTemplate.initializeMessages() is not called, because otherwise this AgentMessageRouter would send a "register" message to itself
initializeMessages in class AgentTemplatepublic void executeWhileRunning()
this.messageRouter.routeMessage(currentMessage));
else it is interpreted.executeWhileRunning in class AgentTemplatepublic boolean terminateAction()
terminateAction in class AgentTemplateAgentTemplate.terminateAction()protected boolean interpretNotifyAgentConnected(Message currentMessage)
currentMessage - "notify_agent_connected" messageprotected boolean interpretAgentConnected(Message currentMessage)
interpretAgentConnected in class AgentTemplatecurrentMessage - "agent_connected" messageprotected boolean interpretNotifyServiceStatusChanged(Message currentMessage)
currentMessage - "notify_service_status_changed" messageprotected boolean interpretInitializeInboxCheck(Message currentMessage)
currentMessage - "initialize_inbox_check" messageprotected boolean interpretCheckInboxSize(Message currentMessage)
interpretInitializeInboxCheck(Message),
a warning will be logged out.currentMessage - "check_inbox_size" messageAgentCronprotected boolean interpretAgentNotNotified(Message currentMessage)
currentMessage - "agent_not_notified" messageprotected boolean interpretRegister(Message currentMessage)
currentMessage - "register" messageMessageRouter.addForward(java.lang.String, java.lang.String)protected boolean interpretUnregister(Message currentMessage)
currentMessage - message to be interpretedMessageRouter.removeForward(java.lang.String)protected boolean interpretRegisterService(Message currentMessage)
Note: If multiple services are specified (message content is a Collection), the agent is registered as service provider for all services or for none of them.
interpretRegisterService in class AgentTemplatecurrentMessage - "register" message containing one or more services in its contentprotected boolean interpretUnregisterService(Message currentMessage)
currentMessage - "unregister_service" message containing one or more services in its contentprotected boolean interpretUnregisterAllServices(Message currentMessage)
currentMessage - "unregister_all_services" messageprotected boolean interpretSubscribeToMessageGroup(Message currentMessage)
Note: If multiple agents are specified (value of key 'agent' in message content is a Collection), the behaviour depends on the value of the 'transaction' key in the content: If it is not set or it is set to 'on', all of the specified agents or none of them are added to the given message group; else all possible ones are added.
currentMessage - "subscribe" message containing the group name and one or more agent names in the contentprotected boolean interpretUnsubscribeFromMessageGroup(Message currentMessage)
currentMessage - "unsubscribe" message containing the group name and one or more agent names as contentprotected boolean interpretUnsubscribeFromAllMessageGroups(Message currentMessage)
currentMessage - "unsubscribe" message containing the agent name in the contentprotected boolean interpretRemoveMessageGroup(Message currentMessage)
currentMessage - message containing the goup name in the content to be removedprotected boolean interpretCloseConnection(Message currentMessage)
interpretCloseConnection in class AgentTemplatecurrentMessage - "close_connection" messageprotected boolean interpretSenderRip(Message currentMessage)
currentMessage - "sender_rip" messageprotected boolean interpretLogSystemInformation(Message currentMessage)
currentMessage - "log_system_information" messageprotected boolean interpretAskGroupMembers(Message currentMessage)
currentMessage - "ask_group_members" message, that contains a "group" key in its content's Map.protected boolean interpretAskServiceProviderMembers(Message currentMessage)
currentMessage - "ask_service_provider_members" messageprotected boolean interpretShowAllProvidedServices(Message currentMessage)
currentMessage - "show_all_provided_services" message
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||