|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmadkit.kernel.AbstractAgent
public class AbstractAgent
The main MadKit AbstractAgent class. It provides support for agent's
The agent's behavior is intentionally not defined. It is up to the agent developer to choose an agent model or to develop his specific agent library on top of the facilities provided by MadKit. However, all agent share the same organizational view, and the basic messaging code, so integration of agent coming from different developer and having heterogeneous models is quite easy.
Agent-related methods (almost everything here) can be invoked only
after registration in the kernel (i.e. after the activate
method has been invoked
on this agent). That means that you should not use any of the agent methods in constructor
Constructor Summary | |
---|---|
AbstractAgent()
Default no-args constructor, which just set-up internal structures |
Method Summary | |
---|---|
void |
activate()
This method is initially called when the micro-kernel registers the agent. |
void |
broadcastMessage(java.lang.String groupName,
java.lang.String roleName,
Message m)
|
void |
broadcastMessage(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName,
Message m)
Broadcast a message to every agent having a role in a group. |
boolean |
connectedWithCommunity(java.lang.String communityName)
returns true if the community is shared on the network |
int |
createGroup(boolean distributed,
java.lang.String groupName,
java.lang.String description,
GroupIdentifier theIdentifier)
Creates a new Group within the default community public. |
int |
createGroup(boolean distributed,
java.lang.String communityName,
java.lang.String groupName,
java.lang.String description,
GroupIdentifier theIdentifier)
Creates a new Group. |
void |
debug(java.lang.String message)
Print out debug information only if the debug flag is on. |
void |
destroyGroup(java.lang.String communityName,
java.lang.String groupName)
This method is still experimental. |
void |
disposeMyGUI()
hide the graphical component that represents the Agent in some higher interface |
void |
end()
This method is called by the agent micro-kernel at the end of the agent lifecycle. |
void |
foundGroup(java.lang.String groupName)
Deprecated. As of MadKit 3.0. replaced by createGroup(boolean,String,String,String,GroupIdentifier) .
This call is now equivalent to |
AgentAddress |
getAddress()
Gets the agent's own agent address. |
AgentAddress[] |
getAgentsWithRole(java.lang.String groupName,
java.lang.String roleName)
Gets the addresses of all the agents (including this agent if present) that handle this role within this group. |
AgentAddress[] |
getAgentsWithRole(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName)
Gets the addresses of all the agents (including this agent if present) that handle this role within this group in this community. |
AgentAddress |
getAgentWithRole(java.lang.String groupName,
java.lang.String roleName)
Gets an agent that handles a given role within a group of the default MadKit community. |
AgentAddress |
getAgentWithRole(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName)
Gets an agent that handles a given role within a group of a particular community. |
java.lang.String[] |
getAvailableCommunities()
returns the available communities |
java.lang.Object |
getBean()
Deprecated. As of MadKit 2.0. replaced by getGUIObject() |
Controller |
getController()
Returns the current controller of the agent if there is one. |
KernelAddress |
getCurrentKernelAddress()
Returns the kernelAddress of the agency where this agent is situated... |
boolean |
getDebug()
|
java.lang.String[] |
getExistingGroups()
returns an array containing the names of the groups which exist in the default community. |
java.lang.String[] |
getExistingGroups(java.lang.String communityName)
returns the names of the groups that exist in this community. |
java.lang.String[] |
getExistingRoles(java.lang.String groupName)
returns the names of the roles that exist within this group in the default community. |
java.lang.String[] |
getExistingRoles(java.lang.String communityName,
java.lang.String groupName)
returns the names of the roles that exist in this (community,group) couple. |
java.util.Vector<java.lang.String> |
getGroups()
Deprecated. As of MadKit 3.0. replaced by getExistingGroups(String) |
java.lang.Object |
getGUIObject()
Gets the graphic component representing the agent. |
int |
getMessageBoxSize()
Gets the number of messages in the message box |
java.lang.String[] |
getMyGroups()
Gets the name of the groups the agent joined in the default community. |
java.lang.String[] |
getMyGroups(java.lang.String communityName)
Gets the name of the groups the agent joined in this community. |
java.lang.String[] |
getMyRoles(java.lang.String groupName)
Gets roles currently handled within a group of the default community. |
java.lang.String[] |
getMyRoles(java.lang.String communityName,
java.lang.String groupName)
Gets roles currently handled within a group of this community. |
java.lang.String |
getName()
Gets the current agent patronymic name. |
java.lang.String[] |
getRoles(java.lang.String groupName)
Deprecated. As of MadKit 3.0. replaced by getExistingRoles(String,String) |
boolean |
hasGUI()
Check if a bean is running in GUI mode. |
int |
hashCode()
|
void |
hideMyGUI()
|
void |
initGUI()
This method is called by the specific external graphic system (as the G-Box) to ask the agent to prepare a graphical interface. |
boolean |
isBelongingToGroup(AgentAddress address,
java.lang.String groupName)
Tell if an agent is a member of a specific group in the default community |
boolean |
isBelongingToGroup(AgentAddress address,
java.lang.String communityName,
java.lang.String groupName)
Tells if an agent is a member of a specific group in a given community. |
boolean |
isCommunity(java.lang.String communityName)
Determines if this group already exists in this community |
boolean |
isGroup(java.lang.String groupName)
Determines if this group already exists in the default community |
boolean |
isGroup(java.lang.String communityName,
java.lang.String groupName)
Determines if this group already exists in this community |
boolean |
isMemberOf(java.lang.String groupName)
Tells if the agent is a member of a specific group in the default community. |
boolean |
isMemberOf(java.lang.String communityName,
java.lang.String groupName)
Tells if the agent is a member of a specific group in a given community |
boolean |
isMessageBoxEmpty()
Is there any message left to be read ? |
boolean |
isRole(java.lang.String groupName,
java.lang.String roleName)
|
boolean |
isRole(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName)
|
void |
joinGroup(java.lang.String groupName)
Deprecated. As of MadKit 3.0. replaced by createGroup(boolean,String,String,String,GroupIdentifier) .
This call is now equivalent to |
void |
killAgent(AbstractAgent agent)
Kills another agent (or self). |
void |
launchAgent(AbstractAgent agent,
java.lang.String name,
boolean gui)
This method is called in order to launch an agent from another agent. |
void |
launchAgent(AbstractAgent agent,
java.lang.String name,
java.awt.Point position,
java.awt.Dimension dim)
This method try to launch an agent with a GUI with the specified coordinates and dimension. |
int |
leaveGroup(java.lang.String groupName)
Makes the agent leave a group of the default community. |
int |
leaveGroup(java.lang.String communityName,
java.lang.String groupName)
Makes the agent leave a group of a particular community. |
int |
leaveRole(java.lang.String groupName,
java.lang.String roleName)
Abandons an handled role within a group of the default community. |
int |
leaveRole(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName)
Abandons an handled role within a group of a particular community. |
Message |
nextMessage()
Gets the first message in the queue. |
void |
print(java.lang.String message)
Prints text information in a environment-independent way (GUI, console, ...) |
void |
println(java.lang.String message)
Prints text information in an environment-independent way (GUI, console, ...) |
protected void |
receiveMessage(Message m)
This method is invoked by the kernel when the agent receives a message. |
void |
redisplayMyGUI()
try to restore the graphical component that represents the Agent in some higher interface |
void |
requestRole(java.lang.String groupName,
java.lang.String roleName)
Deprecated. As of MadKit 3.0. replaced by requestRole(String,String,Object) .
This call is now equivalent to |
int |
requestRole(java.lang.String groupName,
java.lang.String roleName,
java.lang.Object memberCard)
Requests a role within a group of the default community. |
int |
requestRole(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName,
java.lang.Object memberCard)
Requests a role within a group of a particular community. |
void |
restoreAgent(AbstractAgent agent)
experimental |
void |
sendMessage(AgentAddress a,
Message m)
Send a message to another agent. |
void |
sendMessage(java.lang.String groupName,
java.lang.String roleName,
Message m)
Send a message to an agent having a specific role in a group of the default community |
boolean |
sendMessage(java.lang.String communityName,
java.lang.String groupName,
java.lang.String roleName,
Message m)
Send a message to an agent having a specific role in a group of this particular community. |
void |
setBean(java.lang.Object theBean)
Deprecated. As of MadKit 2.0. replaced by setGUIObject(Object) |
void |
setController(Controller c)
Assign a controller which will be in charge of the control of the agent's behavior |
void |
setDebug(boolean b)
Sets the debug flag. |
void |
setGUIObject(java.lang.Object theBean)
This method set the bean that will be used to represent the agent in a graphical environment, the agent is also registered as running in GUI mode |
void |
setName(java.lang.String theName)
Change the current agent patronymic name. |
void |
setOutput(java.io.Writer o)
Deprecated. As of MadKit 2.0. replaced by setOutputWriter(Writer) |
void |
setOutputWriter(java.io.Writer o)
Reassigns the "standard" agent text output stream (used by method println). |
java.lang.String |
toString()
|
void |
windowClosing(java.awt.AWTEvent we)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AbstractAgent()
Method Detail |
---|
public Controller getController()
public void setController(Controller c)
public void activate()
Here is a typical example (taken from the PingPong
agent of MadKit (plugin demos)) :
public void activate() { try { createGroup(true,"ping-pong",null,null); println ("No ping-pong group : I created one"); creator=true; } catch (OrganizationRequestException e) { // the group already exists creator=false; println ("A ping-pong group already exists : I will join"); } requestRole("ping-pong","player",null); }
public void end()
public int createGroup(boolean distributed, java.lang.String communityName, java.lang.String groupName, java.lang.String description, GroupIdentifier theIdentifier)
distributed
- if true
the new group will be distributed when multiple MadKit kernels are connected.communityName
- the community within the group will be created. If this community does not exist it will be created.groupName
- the name of the new groupdescription
- can be null (thus the description will be the name of the group)theIdentifier
- an object that implements the GroupIdentifer Interface
which could be used to check if an agent can be admitted in the group. When this object is null, there is no group access control
1
: operation success; -8
: operation failed ; the group already exists GroupIdentifier
public int createGroup(boolean distributed, java.lang.String groupName, java.lang.String description, GroupIdentifier theIdentifier)
distributed
- if true
the new group will be distributed when multiple MadKit kernels are connected.groupName
- the name of the new groupdescription
- can be null (thus the description will be the name of the group)theIdentifier
- an object that implements the GroupIdentifer Interface
which could be used to check if an agent can be admitted in the group. When this object is null, there is no group access control
1
: operation success; -8
: operation failed ; the group already exists GroupIdentifier
public int requestRole(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName, java.lang.Object memberCard)
communityName
- the group's community.groupName
- the desired group.roleName
- the desired role.memberCard
- the passKey to enter a group. If needed, it is generally delivered by the group's group manager to nice agents :)
It can be null
when the desired group has no security (i.e. was created using null
for theIdentifier parameter).
1
: operation success; -1
: the community does not exist. -2
: the group does not exist; -4
: the role is already handled by this agent; -5
: access denied by the manager of that group;GroupIdentifier
public int requestRole(java.lang.String groupName, java.lang.String roleName, java.lang.Object memberCard)
groupName
- the group nameroleName
- the role namememberCard
- the passKey to enter a group. If needed, it is generally delivered by the group's group manager to nice agents :)
It can be null
when the desired group has no security (i.e. was created using null
for theIdentifier parameter).
1
: operation success; -2
: the group does not exist; -4
: the role is already handled by this agent; -5
: access denied by the manager of that group;GroupIdentifier
public int leaveRole(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName)
communityName
- the community namegroupName
- the group nameroleName
- the role name
1
: operation success; -1
: the community does not exist. -2
: the group does not exist; -6
: the role is not handled;public int leaveRole(java.lang.String groupName, java.lang.String roleName)
groupName
- the group nameroleName
- the role name
1
: operation success; -2
: the group does not exist; -6
: the role is not handled;public int leaveGroup(java.lang.String communityName, java.lang.String groupName)
communityName
- the community namegroupName
- the group name
1
: operation success; -1
: the community does not exist; -2
: the group does not exist; -7
: the agent is not a member of that grouppublic int leaveGroup(java.lang.String groupName)
groupName
- the group name
1
: operation success; -2
: the group does not exist; -7
: the agent is not a member of that grouppublic void joinGroup(java.lang.String groupName)
createGroup(boolean,String,String,String,GroupIdentifier)
.
This call is now equivalent to createGroup(true, groupName, null, null)
if the group does not exist or requestRole(groupName, "member", null)
otherwise.
public void requestRole(java.lang.String groupName, java.lang.String roleName) throws madkit.kernel.RequestRoleException
requestRole(String,String,Object)
.
This call is now equivalent to requestRole(groupName, roleName, null)
.
RequestRoleException
public void foundGroup(java.lang.String groupName) throws madkit.kernel.OrganizationRequestException
createGroup(boolean,String,String,String,GroupIdentifier)
.
This call is now equivalent to createGroup(true, groupName, null, null)
.
OrganizationRequestException
public AgentAddress[] getAgentsWithRole(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName)
communityName
- the community namegroupName
- the group nameroleName
- the role name
public AgentAddress[] getAgentsWithRole(java.lang.String groupName, java.lang.String roleName)
groupName
- the group nameroleName
- the role name
public AgentAddress getAgentWithRole(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName)
groupName
- group nameroleName
- role namecommunityName
- community name
null
otherwise.public AgentAddress getAgentWithRole(java.lang.String groupName, java.lang.String roleName)
groupName
- the group nameroleName
- the role name
null
otherwise.public java.lang.String[] getMyGroups(java.lang.String communityName)
communityName
- a string holding a community name
public java.lang.String[] getMyGroups()
public java.lang.String[] getExistingGroups(java.lang.String communityName)
communityName
- the community name
public java.lang.String[] getExistingGroups()
public boolean isMemberOf(java.lang.String communityName, java.lang.String groupName)
public boolean isMemberOf(java.lang.String groupName)
groupName
- the group name
public boolean isBelongingToGroup(AgentAddress address, java.lang.String communityName, java.lang.String groupName)
address
- the agent addresscommunityName
- the community namegroupName
- the group name
public boolean isBelongingToGroup(AgentAddress address, java.lang.String groupName)
public java.lang.String[] getMyRoles(java.lang.String communityName, java.lang.String groupName)
communityName
- the community namegroupName
- the group name
public java.lang.String[] getMyRoles(java.lang.String groupName)
groupName
- the group name
public java.lang.String[] getExistingRoles(java.lang.String communityName, java.lang.String groupName)
communityName
- the community namegroupName
- the group name
public java.lang.String[] getExistingRoles(java.lang.String groupName)
groupName
- the group name
public java.lang.String[] getRoles(java.lang.String groupName)
getExistingRoles(String,String)
public boolean isRole(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName)
true
if the role exists (i.e. there is at least one agent having this role); false
otherwise.public boolean isRole(java.lang.String groupName, java.lang.String roleName)
true
if the role exists (i.e. there is at least one agent with this role); false
otherwise.public java.util.Vector<java.lang.String> getGroups()
getExistingGroups(String)
public boolean isGroup(java.lang.String communityName, java.lang.String groupName)
public boolean isGroup(java.lang.String groupName)
public boolean isCommunity(java.lang.String communityName)
public java.lang.String[] getAvailableCommunities()
public boolean connectedWithCommunity(java.lang.String communityName)
public void destroyGroup(java.lang.String communityName, java.lang.String groupName)
public boolean isMessageBoxEmpty()
public int getMessageBoxSize()
public Message nextMessage()
protected void receiveMessage(Message m)
m
- the messagepublic void sendMessage(AgentAddress a, Message m) throws MessageException
a
- AgentAddress of the receiverm
- Message to be sent
MessageException
- if no recipient is found or the message is nullpublic boolean sendMessage(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName, Message m) throws MessageException
communityName
- community in which the group is definedgroupName
- group in which the role is definedroleName
- Role of the receiverm
- Message to be sent
true
, if an agent has been found as receiver. Beware that this does not mean that the message will be successfully delivered.
MessageException
- if the message is nullgetAgentWithRole(String, String, String)
public void sendMessage(java.lang.String groupName, java.lang.String roleName, Message m) throws MessageException
groupName
- the group nameroleName
- the role namem
- the message
MessageException
- the message exceptionsendMessage(String, String, String, Message)
public void broadcastMessage(java.lang.String communityName, java.lang.String groupName, java.lang.String roleName, Message m) throws MessageException
communityName
- the community namegroupName
- the group nameroleName
- the role namem
- the m
MessageException
- the message exceptionpublic void broadcastMessage(java.lang.String groupName, java.lang.String roleName, Message m) throws MessageException
MessageException
public void launchAgent(AbstractAgent agent, java.lang.String name, boolean gui)
agent
- The new agent (already instantiated using a new instruction) .name
- The "usual" namegui
- Should we setup the agent GUI if possible ?public void launchAgent(AbstractAgent agent, java.lang.String name, java.awt.Point position, java.awt.Dimension dim)
agent
- the agentname
- the name of the agentposition
- the position on the screendim
- the dimension of the GUIpublic void restoreAgent(AbstractAgent agent)
public void killAgent(AbstractAgent agent)
agent
- the agent to killpublic AgentAddress getAddress()
public void setName(java.lang.String theName)
theName
- the new name to setpublic java.lang.String getName()
public KernelAddress getCurrentKernelAddress()
public boolean hasGUI()
public void initGUI()
public void setBean(java.lang.Object theBean)
setGUIObject(Object)
public java.lang.Object getBean()
getGUIObject()
public void setGUIObject(java.lang.Object theBean)
theBean
- an allocated graphic componentpublic java.lang.Object getGUIObject()
public void debug(java.lang.String message)
message
- the messagepublic void setDebug(boolean b)
b
- the bpublic boolean getDebug()
public void println(java.lang.String message)
message
- the stringpublic void print(java.lang.String message)
message
- the stringpublic void setOutput(java.io.Writer o)
setOutputWriter(Writer)
public void setOutputWriter(java.io.Writer o)
public void disposeMyGUI()
public void hideMyGUI()
public void redisplayMyGUI()
public void windowClosing(java.awt.AWTEvent we)
public final int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |