elge.agent
Class Agency

java.lang.Object
  |
  +--elge.agent.Agency

public class Agency
extends Object

Agency is a class for making the comunication between agents. One possible thing is to give every agent every message that anyone sends. But then the agent themselfs have to realize the type and destination of the message. So an register system is here explaind where every agent can register what he wants to hear, and when that event occures, the agent method will be invoked.

Agency should not exist standalone, so there should always some agent, that has the agency as main agency for comunication.

The idea is, that every agent has it's own agency (if needed) for comunication with his subagents and every agent uses an agency from super agent - the parent agent. The parent agent should for now, not be diferenced from his subagents. So the comunications is only between all subagents and their parent. If needed, the parent can move the comunication to the top or the subagents should move the comunication down.

Author:
Pavol Žibrita

Field Summary
static String METHOD_PREFIX
          Used to determine, what is the prefix for the methods for comunication.
protected  Hashtable ragents
          hashtable of registred agents.
 
Constructor Summary
Agency()
          Creates a new instance of Agency.
 
Method Summary
protected  Vector getAgentsForMessage(String message)
          Internal method.
 Situation getAnswer(Agent agent, Agent callagent, String message, Object params)
          Like getAnswer but tries to ask a specific agent agent.
 Situation getAnswer(Agent agent, String message, Object params)
          Method searches agents for registred agents wich message message and asks one of them for the answer.
 Vector getAnswers(Agent agent, String message, Object params)
          Like simple getAnswer but gets more results.
 void register(Agent agent)
          This method should scan the agent for getAnswer_ Methods and register it.
 void registermethod(Agent agent, String message)
          Register the agent 'agent' for the message 'message'
 void unregister(Agent agent)
          Unregister the agent for all messages.
 void unregister(Agent agent, String message)
          Remove the agent from ragents for comunication message 'message'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METHOD_PREFIX

public static final String METHOD_PREFIX
Used to determine, what is the prefix for the methods for comunication. Every method with this prefix and some type of arguments, is registerable. The standart method prefix is getAnswer_ followed with the message ident string.

See Also:
Constant Field Values

ragents

protected Hashtable ragents
hashtable of registred agents. (message -> vector of agents)

Constructor Detail

Agency

public Agency()
Creates a new instance of Agency.

Method Detail

getAnswers

public Vector getAnswers(Agent agent,
                         String message,
                         Object params)
Like simple getAnswer but gets more results.

Parameters:
agent - agent which is asking.
message - message ident string.
params - any parameters that the message requires.
Returns:
Vector of Situations from agents that could answer the message. It could be empty.
See Also:
getAnswer(elge.agent.Agent, java.lang.String, java.lang.Object)

getAnswer

public Situation getAnswer(Agent agent,
                           String message,
                           Object params)
Method searches agents for registred agents wich message message and asks one of them for the answer.

Parameters:
agent - agent shich is asking.
message - message ident string
params - any parameters
Returns:
returns the answer if found or null if not found.

getAnswer

public Situation getAnswer(Agent agent,
                           Agent callagent,
                           String message,
                           Object params)
Like getAnswer but tries to ask a specific agent agent. If he knows the message type, the asnwer should be available.

Parameters:
agent - agent to ask the message.
callagent - agent which is asking.
message - message ident string.
params - any parameters
Returns:
returns the answer from the agent or null if the agent does not know the message.

register

public void register(Agent agent)
This method should scan the agent for getAnswer_ Methods and register it.

Parameters:
agent - The agent we want to register.

registermethod

public void registermethod(Agent agent,
                           String message)
Register the agent 'agent' for the message 'message'

Parameters:
agent - the agent we want to register
message - the name of comunication message we want to register the agent to ragents.

unregister

public void unregister(Agent agent)
Unregister the agent for all messages.

Parameters:
agent - the agent we want to unregister from ragents.

unregister

public void unregister(Agent agent,
                       String message)
Remove the agent from ragents for comunication message 'message'.

Parameters:
agent - The agent we try to unregister
message - for what method wi try to unregister the agent.

getAgentsForMessage

protected Vector getAgentsForMessage(String message)
Internal method.

Parameters:
message - message ident string.
Returns:
Vector of agents that are registred for method with has the name of the argument. Null if no agents found.