fr.lifl.magique
Class AtomicAgent

java.lang.Object
  extended byfr.lifl.magique.AbstractAgent
      extended byfr.lifl.magique.AtomicAgent
Direct Known Subclasses:
Agent, PlatformAgent

public class AtomicAgent
extends AbstractAgent

This class is dedicated to be extended to create more complex agent. It provides an hollow shell for creating agents. An agent must own to a platform, then after creation he must be added to the platform that runs on his host (see platform.addPlatform(Agent)) The of a agent is based on a short name given at creation. To this short name, the IP address (or hostname) of the host where the agent runs is added, as well as the port number of the platform. Therefore, name is of the form shortName@hostname:port (e.g. anAgent@here.domain.country:4444). An agent is gifted of skills. Roughly a skill is a component (then an object) the public methods of which are immediately usable buy the agent. An agent can dynamically learn new skills using the addSkill method or the learnSkill skill. A new skill can be learn while it does not contain a public method with exactly the same signature that another already "known" by the agent. Skills correspond to the reactive part of the agent. Skills known by agent at creation are defined in the initBasicSkills methods. Here messages are in fact Request objects. The text member of a request object is a name of a method (args can be provided). Therefore, an agent can "ask" another agent to achieve a "method" for him. Some othe properties can be set (e.g. the policy for concurrent request : setConcurrencyPolicy

See Also:
Agent, Skill, DefaultSkill, Platform

Field Summary
protected  java.util.List allKnownSkills
           
protected  java.lang.Object monitor
           
protected  ConcurrencyPolicy myConcurrencyPolicy
          the policy for concurrency
protected  java.util.Hashtable mySkills
          this attributs stores all the "object-skill" the agent own. the mapping is : the key is a method's name, the value is a reference to the associated object.
protected  MessageList unsentRequests
           
 
Fields inherited from class fr.lifl.magique.AbstractAgent
questionTable, toDo, verboseLevel
 
Constructor Summary
AtomicAgent()
           
AtomicAgent(java.lang.String name)
           
 
Method Summary
 void addSkill(java.lang.Object newSkill)
          Add all the methods of the object newSkill to the agent
 void addSkill(java.lang.String skillClassName)
          Add all the methods of the class skillClassName to the agent.
 void addSkill(java.lang.String skillClassName, java.lang.Object[] args)
          Add all the methods of the class skillClassName to the agent.
 void concurrentPerform(Request request)
          treat a concurrent request : if the agent knows the method, he applies it,
 void connectTo(java.lang.String agentName)
          connect this agent to another one
 java.util.Iterator getAllKnownSkills()
           
 Platform getPlatform()
          get my platform
protected  MessageList getUnsentRequests()
           
 java.lang.String giveSkillClassNameFromSignature(java.lang.String signature)
           
protected  void initBasicSkills()
          defines the skills known by the agent at creation.
protected  void initialize()
           
protected  Request interprete(Request request)
          invoke request : text is a known method name.
 java.util.Vector myMethodsNames()
          the vector containing the names (String) of the methods of this object
 void perform(Request request)
          treat a request : if the agent knows the method, he applies it,
 void processRequest(Request request)
          process a received Request object, it can be an answer, to one of my request, back an answer to someone else back on the way to its creator a request to treat
 void removeSkill(java.lang.String key)
          Remove the "key" from the hashtable of skills.
 void removeSkillFromClassName(java.lang.String skillClassName)
          remove a skill from its class name
 void send(java.lang.String to, Message msg)
          send a request to to through the platform if needed If to is unknown, request is stored
 void send(java.lang.String to, Request request)
           
 void sendMessage(java.lang.String to, Message msg)
           
 void setAction(ActionSkill action)
          changes the action skill that corresponds to the proactive part of the agent
 void setConcurrencyPolicy(ConcurrencyPolicy theConcurrencyPolicy)
          set the concurrency policy
 void setPlatform(Platform platform)
          set my platform
 void start()
          starts the agent activity described in action() method (something like the start() method in thread)
 void treatUnsentRequests(java.lang.String agent, java.util.Vector methods)
          agent is just known at now, maybe he can handle some of the unsent requests ?
 
Methods inherited from class fr.lifl.magique.AbstractAgent
addAgenda, ask, ask, ask, ask, ask, ask, ask, ask, ask, ask, ask, ask, ask, ask, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, askNow, concurrentAsk, concurrentAsk, concurrentAsk, concurrentAsk, concurrentAsk, concurrentAsk, concurrentAsk, createOrder, createOrder, createOrder, createOrder, createOrder, createOrder, createQuestion, createQuestion, createQuestion, createQuestion, createQuestion, createQuestion, createQuestion, createQuestion, forgetQuestion, getAgenda, getAnswerer, getListener, getName, getQuestionTable, getToDo, getVerboseLevel, isAnswerReceived, perform, perform, perform, perform, perform, perform, perform, perform, perform, perform, perform, perform, perform, processAnswer, returnAnswer, returnValue, setName, setQuestionTable, setVerboseLevel, stopListener, verbose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unsentRequests

protected MessageList unsentRequests

monitor

protected java.lang.Object monitor

myConcurrencyPolicy

protected ConcurrencyPolicy myConcurrencyPolicy
the policy for concurrency


mySkills

protected java.util.Hashtable mySkills
this attributs stores all the "object-skill" the agent own. the mapping is : the key is a method's name, the value is a reference to the associated object.


allKnownSkills

protected java.util.List allKnownSkills
Constructor Detail

AtomicAgent

public AtomicAgent()

AtomicAgent

public AtomicAgent(java.lang.String name)
Parameters:
name - = shortname : identifier for my name (platform hostname and port number are added) hostname is by default the local one (not "localhost" if Ip address does exist)
Method Detail

initialize

protected final void initialize()

initBasicSkills

protected void initBasicSkills()
                        throws SkillAlreadyAcquiredException
defines the skills known by the agent at creation.

Throws:
SkillAlreadyAcquiredException - if agent tries to learn an already known skill

setConcurrencyPolicy

public void setConcurrencyPolicy(ConcurrencyPolicy theConcurrencyPolicy)
set the concurrency policy


setPlatform

public void setPlatform(Platform platform)
set my platform


getPlatform

public Platform getPlatform()
get my platform

Returns:
my platform

getUnsentRequests

protected MessageList getUnsentRequests()
Returns:
my unsent requests list

addSkill

public void addSkill(java.lang.Object newSkill)
              throws SkillAlreadyAcquiredException
Add all the methods of the object newSkill to the agent

Parameters:
newSkill - the new skills to be added. Each method of the object newSkill, is added to the agent.
Throws:
SkillAlreadyAcquiredException - if newSkill contains a method with the same signature as another already known

addSkill

public void addSkill(java.lang.String skillClassName)
              throws SkillAlreadyAcquiredException
Add all the methods of the class skillClassName to the agent. skillClassName must be in the classpath.

Parameters:
skillClassName - the class used that contains new skills to be added.
Throws:
SkillAlreadyAcquiredException - if newSkill contains a method with the same signature as another already known

addSkill

public void addSkill(java.lang.String skillClassName,
                     java.lang.Object[] args)
              throws SkillAlreadyAcquiredException
Add all the methods of the class skillClassName to the agent. skillClassName must be in the classpath. args are used to create the skill.

Parameters:
skillClassName - the class used that contains new skills to be added.
args - the ragument used to create the skill
Throws:
SkillAlreadyAcquiredException - if newSkill contains a method with the same signature as another already known
See Also:
AtomicAgent#addSkill(Skill)

giveSkillClassNameFromSignature

public java.lang.String giveSkillClassNameFromSignature(java.lang.String signature)

getAllKnownSkills

public java.util.Iterator getAllKnownSkills()

removeSkill

public void removeSkill(java.lang.String key)
                 throws SkillNotKnownException
Remove the "key" from the hashtable of skills. This method removes all the method learned at the same time than key (that means the "full" skill which contains "key")

Parameters:
key - a string representing the method's signature to be removed.
Throws:
SkillNotKnownException - if key is not a knwon method signature

removeSkillFromClassName

public void removeSkillFromClassName(java.lang.String skillClassName)
                              throws SkillNotKnownException
remove a skill from its class name

Parameters:
skillClassName - the class name of the skill to be removed
Throws:
SkillNotKnownException - if skill is not a known skill

myMethodsNames

public java.util.Vector myMethodsNames()
the vector containing the names (String) of the methods of this object

Returns:
the vector containing the names (String) of the methods of this object

connectTo

public void connectTo(java.lang.String agentName)
connect this agent to another one

Parameters:
agentName - the name of the agent i connect to (of the form "name@hostname:rmiport")

send

public void send(java.lang.String to,
                 Request request)

send

public void send(java.lang.String to,
                 Message msg)
send a request to to through the platform if needed If to is unknown, request is stored

Specified by:
send in class AbstractAgent
Parameters:
to - name of recipient (name can be short name)
msg - message to be sent
See Also:
Serializable

sendMessage

public void sendMessage(java.lang.String to,
                        Message msg)

treatUnsentRequests

public void treatUnsentRequests(java.lang.String agent,
                                java.util.Vector methods)
agent is just known at now, maybe he can handle some of the unsent requests ? if so I send them to him

Parameters:
agent - the new known agent
methods - the methods this agent can handle

processRequest

public void processRequest(Request request)
process a received Request object, it can be

Overrides:
processRequest in class AbstractAgent
Parameters:
request - request to handle

interprete

protected Request interprete(Request request)
invoke request : text is a known method name. If is a question, answer is replied.

Overrides:
interprete in class AbstractAgent
Parameters:
request - the reauest to invoke
Returns:
the request with its answer field updated with invocation result (null if no answer is required)

start

public void start()
           throws NoActionSkillException
starts the agent activity described in action() method (something like the start() method in thread)

Throws:
NoActionSkillException - if action has not been defined
See Also:
fr.lifl.magique.Agent#setAction()

setAction

public void setAction(ActionSkill action)
changes the action skill that corresponds to the proactive part of the agent

Parameters:
action - the new action skill, it must inherit ActionSkill
See Also:
ActionSkill

perform

public void perform(Request request)
treat a request : if the agent knows the method, he applies it,

Specified by:
perform in class AbstractAgent
Parameters:
request - the request to be treated
Returns:
no return value

concurrentPerform

public void concurrentPerform(Request request)
treat a concurrent request : if the agent knows the method, he applies it,

Specified by:
concurrentPerform in class AbstractAgent
Parameters:
request - the request to be treated
Returns:
no return value