Class Agent
- Direct Known Subclasses:
SimuAgent
- Agent's Life cycle, logging, and naming.
- Agent launching and killing.
- Artificial society creation and management.
- Messaging.
- Minimal graphical interface management.
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 the MaDKit API. However, all the launched agents share the same organizational view, and the basic messaging code, so integration of different agents is quite easy, even when they are coming from different developers or have heterogeneous models.
An Agent will be given its own thread if it overrides the onLive()
method
Agent-related methods (most of this API) is only effective after the agent has been launched and thus registered in the current MaDKit session. Especially, that means that most of the API has no effect in the constructor method of an Agent and will just fail if used.
Agents are identified and localized within the artificial society. An agent is no longer
A replying mechanism can be used to answer messages using SendReply
methods. It enables the agent with the possibility of replying directly to a given
message. Also, it is possible to get the reply to a message, or to wait for a reply.
See reply(Message, Message)
for more details.
One of the most convenient part of the API is the logging mechanism which is provided.
See the getLogger()
method for more details.
- Since:
- MaDKit 6.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate()
Deprecated, for removal: This API element is subject to removal in a future version.broadcast
(Message message, List<AgentAddress> receivers) Broadcasts a message to every agent having a role in a group in a community using a specific role for the sender.broadcastWithRole
(Message message, List<AgentAddress> receivers, String role) Broadcasts a message to every agent having a role in a group in a community using a specific role for the sender.broadcastWithRoleWaitForReplies
(Message message, List<AgentAddress> receivers, String senderRole, Integer timeOutMilliSeconds) Broadcasts a message and wait for answers considering a timeout duration.boolean
checkAgentAddress
(AgentAddress agentAddress) Checks if this agent address is still valid.createGroup
(String community, String group) Creates a new Group within a community.createGroup
(String community, String group, boolean isDistributed) Creates a new Group within a community.createGroup
(String community, String group, boolean isDistributed, Gatekeeper keyMaster) Creates a new Group within a community.protected void
end()
Deprecated, for removal: This API element is subject to removal in a future version.UseonEnd()
instead.final boolean
An Agent is unique and therefore equals to only itself.protected static Madkit
executeThisAgent
(int nbOfInstances, String... args) This offers a convenient way to create main a main method that launches the agent class under development.protected static Madkit
executeThisAgent
(String... args) This offers a convenient way to create a main method that launches the agent class under development.protected void
Checks if the current agent's thread has been interrupted, for instance, due to a kill attempt.getAgentsWithRole
(String community, String group, String role) Returns a list of agent addresses corresponding to agents having this role in the organization.getAgentWithRole
(String community, String group, String role) Returns anAgentAddress
of a random agent having this position in the organization.The kernel's address on which this agent is running.Gets the kernel configuration associated with the agent.Returns the agent's logger.protected Mailbox
Returns the agent's mailboxgetName()
Gets the agent's name.final String
Returns a string representing a unique identifier for the agent over the network.Gets the organization.<T extends Message>
TgetReplyTo
(Message originalMessage) Gets the next message which is a reply to the originalMessage.void
Handles aRequestActionMessage
so that the agent will trigger the corresponding method using the parameters of the message.final int
hashCode()
Gets the agent's hash code.final boolean
isAlive()
Checks if the agent is alive.protected Agent.ReturnCode
Kills the specified agent, waiting forever for this agent to end.protected Agent.ReturnCode
Kills the specified agent with a specified timeout.<T extends Agent>
TlaunchAgent
(String agentClass, int timeOutSeconds) Launches a new agent using its full class name and returns when the launched agent has completed itsonActivation()
method or when the timeout is elapsed.launchAgent
(Agent a) Launches a new agent and waits until the launched agent has completed itsonActivation()
method.launchAgent
(Agent a, int timeOutSeconds) Launches a new agent and waits until the launched agent has completed itsonActivation()
method or until the timeout is elapsed.leaveGroup
(String community, String group) Makes this agent leaves the group of a particular community.Abandons an handled role within a group of a particular community.protected void
live()
Deprecated, for removal: This API element is subject to removal in a future version.UseonLive()
instead.<M extends Message>
MRetrieves the next message from the mailbox.protected void
First method called when the agent is launched.protected void
onEnd()
This method is called when the agent finishes its life cycle.protected void
onLive()
Defines the main behavior of the agent.protected void
pause
(int milliSeconds) Stops the agent's process for a specified duration.prng()
Returns the random generator used by the MaDKit kernel for this session.void
receiveMessage
(Message message) This method offers a convenient way for regular object to send messages to Agents, especially threaded agents.void
reload()
Kills the caller and launches a new instance of this agent using the latest byte code available for the corresponding class.Sends a message by replying to a previously received message.replyWithRole
(Message reply, Message messageToReplyTo, String senderRole) Sends a message by replying to a previously received message.requestRole
(String community, String group, String role) Requests a role within a group of a particular community.requestRole
(String community, String group, String role, Object passKey) Requests a role within a group of a particular community using a passKey.Sends a message to an agent having this position in the organization, specifying explicitly the role used to send it.send
(Message message, AgentAddress receiver) Sends a message to an agent using an agent address.protected <T extends Message>
TsendWaitReply
(Message messageToSend, String community, String group, String role, Integer timeOutMilliSeconds) Sends a message to an agent having this position in the organization and waits for an answer to it.protected <T extends Message>
TsendWaitReply
(Message messageToSend, AgentAddress receiver, Integer timeOutMilliSeconds) Sends a message to an agent having this position in the organization.sendWithRole
(Message message, AgentAddress receiver, String senderRole) Sends a message, using an agent address, specifying explicitly the role used to send it.protected <T extends Message>
TsendWithRoleWaitReply
(Message messageToSend, String community, String group, String role, String senderRole, Integer timeOutMilliSeconds) Sends a message to an agent having this position in the organization and waits for an answer to it.protected <T extends Message>
TsendWithRoleWaitReply
(Message messageToSend, AgentAddress receiver, String senderRole, Integer timeOutMilliSeconds) Sends a message and waits for an answer to it.void
Creates a default frame for the agent.toString()
To string.protected <T extends Message>
TwaitAnswer
(Message query) Retrieves and removes the next message that is a reply to the query message, waiting for ever if necessary until a matching reply becomes available.protected <T extends Message>
TwaitAnswer
(Message query, Integer timeOutMilliSeconds) Retrieves and removes the next message that is a reply to the query message, waiting for ever if necessary until a matching reply becomes available.protected <T extends Message>
TThis method is the blocking version of nextMessage().protected <T extends Message>
TwaitNextMessage
(long timeOutMilliseconds) This method gets the next message of the mailbox or waits for a new incoming message considering a certain delay.
-
Constructor Details
-
Agent
protected Agent()Constructs a new Agent instance.The agent's hashCode is set when the agent is created. This hashCode is unique for each agent instance and is used to uniquely identify the agent within the artificial society.
It is important to note that the agent is not yet alive at this point.
-
-
Method Details
-
onActivation
protected void onActivation()First method called when the agent is launched. This method should be overridden to define custom activation behavior. -
onLive
protected void onLive()Defines the main behavior of the agent. This method should be overridden to define custom behavior while the agent is alive. It is automatically called when the onActivation method finishes. If implemented, the agent will be given its own thread, thus making the agent completely autonomous. The agent will be alive until this method returns or it is killed. -
onEnd
protected void onEnd()This method is called when the agent finishes its life cycle. Either because the agent was killed or because the onLive method returned. This method can be overridden to define custom cleanup behavior. -
isAlive
public final boolean isAlive()Checks if the agent is alive. An agent is considered alive if it has been launched and has not yet been killed.- Returns:
true
if the agent is alive,false
otherwise.
-
exitOnKill
Checks if the current agent's thread has been interrupted, for instance, due to a kill attempt. If it has, anAgentInterruptedException
is thrown.- Throws:
AgentInterruptedException
- if the thread has been interrupted.
-
launchAgent
Launches a new agent and waits until the launched agent has completed itsonActivation()
method. This has the same effect aslaunchAgent(Agent, int)
but with a default timeout ofInteger.MAX_VALUE
.- Parameters:
a
- the agent to launch.- Returns:
- the result of the launch operation.
-
launchAgent
Launches a new agent and waits until the launched agent has completed itsonActivation()
method or until the timeout is elapsed.The launch is logged at the
Level.FINER
level.- Parameters:
a
- the agent to launch.timeOutSeconds
- the maximum time to wait for the agent to launch.- Returns:
- the result of the launch operation.
-
prng
Returns the random generator used by the MaDKit kernel for this session.- Returns:
- the random generator.
-
launchAgent
Launches a new agent using its full class name and returns when the launched agent has completed itsonActivation()
method or when the timeout is elapsed. This has the same effect aslaunchAgent(Agent, int)
but allows launching an agent using a class name found reflexively. The targeted agent class should have a default constructor for this to work. Additionally, this method will launch the last compiled bytecode of the corresponding class if it has been reloaded usingMadkitClassLoader.reloadClass(String)
. Finally, if the launch succeeds within the timeout, this method returns the instance of the created agent.- Type Parameters:
T
- the type of the agent to launch.- Parameters:
agentClass
- the full class name of the agent to launch.timeOutSeconds
- time to wait for the end of the agent's activation until returningnull
.- Returns:
- the instance of the launched agent or
null
if the operation times out or fails.
-
killAgent
Kills the specified agent, waiting forever for this agent to end.- Parameters:
a
- the agent to be killed.- Returns:
- the result of the kill operation.
-
killAgent
Kills the specified agent with a specified timeout.- Parameters:
agent
- the agent to be killed.timeOutSeconds
- the maximum time to wait for the agent to be killed.- Returns:
- the result of the kill operation.
-
activate
Deprecated, for removal: This API element is subject to removal in a future version.UseonActivation()
instead. -
live
Deprecated, for removal: This API element is subject to removal in a future version.UseonLive()
instead. -
end
Deprecated, for removal: This API element is subject to removal in a future version.UseonEnd()
instead. -
getLogger
Returns the agent's logger. It should not be used beforeonActivation()
to get the proper logging level, that is the one set using "agentLogLevel".- Returns:
- the agent's logger.
- Since:
- MaDKit 5.0.0.6
- See Also:
-
pause
protected void pause(int milliSeconds) Stops the agent's process for a specified duration.- Parameters:
milliSeconds
- the number of milliseconds for which the agent should pause.
-
getName
Gets the agent's name. The default name is "class name + internal ID". This name is used in logger info, GUI title, and so on. This method can be overridden to obtain a customized name.- Returns:
- the agent's name.
-
hashCode
-
equals
-
getKernelConfig
Gets the kernel configuration associated with the agent.- Returns:
- the kernel configuration.
-
createGroup
Creates a new Group within a community. This has the same effect ascreateGroup(community, group, false, null)
- Parameters:
community
- the community within which the group will be created. If this community does not exist it will be created.group
- the name of the new group- Returns:
: If the group has been successfully created.Agent.ReturnCode.SUCCESS
: If the operation failed because such a group already exists.Agent.ReturnCode.ALREADY_GROUP
- Since:
- MaDKit 5.0
- See Also:
-
createGroup
Creates a new Group within a community. This has the same effect ascreateGroup(community, group, isDistributed, null)
- Parameters:
community
- the community within which the group will be created. If this community does not exist it will be created.group
- the name of the new group.isDistributed
- iftrue
the new group will be distributed when multiple MaDKit kernels are connected.- Returns:
: If the group has been successfully created.Agent.ReturnCode.SUCCESS
: If the operation failed because such a group already exists.Agent.ReturnCode.ALREADY_GROUP
- Since:
- MaDKit 5.0
- See Also:
-
getOrganization
Gets the organization. This method should not be used before the agent has been launched. The organization is the agent's view of the artificial society.- Returns:
- the organization to which the agent is attached.
-
createGroup
public Agent.ReturnCode createGroup(String community, String group, boolean isDistributed, Gatekeeper keyMaster) Creates a new Group within a community.If this operation succeed, the agent will automatically handle the role defined by
SystemRoles.GROUP_MANAGER
, which value is "manager", in this created group. Especially, if the agent leaves the role of "manager", it will also automatically leave the group and thus all the roles it has in this group.Agents that want to enter the group may send messages to the "manager" using the role defined by
SystemRoles.GROUP_CANDIDATE
, which value is "candidate".- Parameters:
community
- the community within which the group will be created. If this community does not exist it will be created.group
- the name of the new group.isDistributed
- iftrue
the new group will be distributed when multiple MaDKit kernels are connected.keyMaster
- any object that implements theGatekeeper
interface. If notnull
, this object will be used to check if an agent can be admitted in the group. When this object is null, there is no group access control.- Returns:
: If the group has been successfully created.Agent.ReturnCode.SUCCESS
Agent.ReturnCode.ALREADY_GROUP
- Since:
- MaDKit 5.0
- See Also:
-
requestRole
Requests a role within a group of a particular community. This has the same effect asrequestRole(community, group, role, null, false)
. So the passKey isnull
and the group must not be secured for this to succeed.- Parameters:
community
- the group's community.group
- the targeted group.role
- the desired role.- Returns:
- the result of the request operation.
- Since:
- MaDKit 5.0
- See Also:
-
requestRole
Requests a role within a group of a particular community using a passKey.- Parameters:
community
- the group's community.group
- the targeted group.role
- the desired role.passKey
- thepassKey
to enter a secured group. It is generally delivered by the group's group manager. It could benull
, which is sufficient to enter an unsecured group. Especially,requestRole(String, String, String)
uses anull
passKey
.- Returns:
: If the operation has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If this role is already handled by this agent.Agent.ReturnCode.ROLE_ALREADY_HANDLED
: If the access denied by the manager of that secured group.Agent.ReturnCode.ACCESS_DENIED
- Since:
- MaDKit 5.0
- See Also:
-
leaveGroup
Makes this agent leaves the group of a particular community.- Parameters:
community
- the community namegroup
- the group name- Returns:
: If the operation has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If this agent is not a member of this group.Agent.ReturnCode.NOT_IN_GROUP
- Since:
- MaDKit 5.0
- See Also:
-
leaveRole
Abandons an handled role within a group of a particular community.- Parameters:
community
- the community namegroup
- the group namerole
- the role name- Returns:
: If the operation has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If this role is not handled by this agent.Agent.ReturnCode.ROLE_NOT_HANDLED
- Since:
- MaDKit 5.0
- See Also:
-
getAgentWithRole
Returns anAgentAddress
of a random agent having this position in the organization. The caller is excluded from the search. The PRNG used is the one associated with the caller.- Parameters:
community
- the community namegroup
- the group namerole
- the role name- Returns:
- an
AgentAddress
corresponding to a random agent having this role, ornull
if such an agent does not exist.
-
getNetworkID
Returns a string representing a unique identifier for the agent over the network.- Returns:
- the agent's network identifier
-
toString
-
reload
public void reload()Kills the caller and launches a new instance of this agent using the latest byte code available for the corresponding class. -
sendWithRole
Sends a message, using an agent address, specifying explicitly the role used to send it.- Parameters:
message
- the message to sendreceiver
- the targeted agentsenderRole
- the agent's role with which the message has to be sent- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If this agent is not a member of the receiver's group.Agent.ReturnCode.NOT_IN_GROUP
: IfAgent.ReturnCode.ROLE_NOT_HANDLED
senderRole
is not handled by this agent.
: If the receiver address is no longer valid. This is the case when the corresponding agent has leaved the role corresponding to the receiver agent address.Agent.ReturnCode.INVALID_AGENT_ADDRESS
- See Also:
-
send
Sends a message to an agent using an agent address. This has the same effect assendWithRole(receiver, messageToSend, null)
.- Parameters:
message
- the message to sendreceiver
- the targeted agent- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If this agent is not a member of the receiver's group.Agent.ReturnCode.NOT_IN_GROUP
: If the receiver address is no longer valid. This is the case when the corresponding agent has leaved the role corresponding to the receiver agent address.Agent.ReturnCode.INVALID_AGENT_ADDRESS
- See Also:
-
send
Sends a message to an agent having this position in the organization, specifying explicitly the role used to send it. This has the same effect as sendMessageWithRole(community, group, role, messageToSend,null). If several agents match, the target is chosen randomly. The sender is excluded from this search.- Parameters:
message
- the message to sendcommunity
- the community namegroup
- the group namerole
- the role name- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If the role does not exist.Agent.ReturnCode.NOT_ROLE
: If this agent is not a member of the targeted group.Agent.ReturnCode.NOT_IN_GROUP
: If no agent was found as recipient, i.e. the sender was the only agent having this role.Agent.ReturnCode.NO_RECIPIENT_FOUND
- See Also:
-
sendWithRole
public Agent.ReturnCode sendWithRole(Message message, String community, String group, String role, String senderRole) Sends a message to an agent having this position in the organization. This has the same effect assendMessageWithRole(community, group, role, messageToSend,null)
. If several agents match, the target is chosen randomly. The sender is excluded from this search.- Parameters:
message
- the message to sendcommunity
- the community namegroup
- the group namerole
- the role namesenderRole
- the agent's role with which the message has to be sent- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If the role does not exist.Agent.ReturnCode.NOT_ROLE
: IfAgent.ReturnCode.ROLE_NOT_HANDLED
senderRole
is not handled by this agent.
: If this agent is not a member of the targeted group.Agent.ReturnCode.NOT_IN_GROUP
: If no agent was found as recipient, i.e. the sender was the only agent having this role.Agent.ReturnCode.NO_RECIPIENT_FOUND
- See Also:
-
sendWithRoleWaitReply
protected <T extends Message> T sendWithRoleWaitReply(Message messageToSend, String community, String group, String role, String senderRole, Integer timeOutMilliSeconds) Sends a message to an agent having this position in the organization and waits for an answer to it. The targeted agent is selected randomly among matched agents. The sender is excluded from this search.- Type Parameters:
T
- the type of the message to get- Parameters:
messageToSend
- the message to send.community
- the community namegroup
- the group namerole
- the role namesenderRole
- the role with which the sending is done.timeOutMilliSeconds
- the maximum time to wait. Ifnull
the agent will wait indefinitely.- Returns:
- the reply received as soon as available, or
null
if the time out has elapsed or if there was an error when sending the message. - Since:
- MaDKit 5
-
sendWithRoleWaitReply
protected <T extends Message> T sendWithRoleWaitReply(Message messageToSend, AgentAddress receiver, String senderRole, Integer timeOutMilliSeconds) Sends a message and waits for an answer to it. Additionally, the sending is done using a specific role for the sender.- Type Parameters:
T
- the type of the message to get- Parameters:
messageToSend
- the message to send.receiver
- the targeted agent by the send.senderRole
- the role with which the sending is done.timeOutMilliSeconds
- the maximum time to wait. Ifnull
the agent will wait indefinitely.- Returns:
- the reply received as soon as available, or
null
if the time out has elapsed or if there was an error when sending the message, - Since:
- MaDKit 5
-
sendWaitReply
protected <T extends Message> T sendWaitReply(Message messageToSend, AgentAddress receiver, Integer timeOutMilliSeconds) -
sendWaitReply
protected <T extends Message> T sendWaitReply(Message messageToSend, String community, String group, String role, Integer timeOutMilliSeconds) Sends a message to an agent having this position in the organization and waits for an answer to it. The targeted agent is selected randomly among matched agents. The sender is excluded from this search.- Type Parameters:
T
- the type of the message to get agent will wait indefinitely.- Parameters:
messageToSend
- the message to send.community
- the community namegroup
- the group namerole
- the role nametimeOutMilliSeconds
- the maximum time to wait. Ifnull
the- Returns:
- the reply received as soon as available, or
null
if the time out has elapsed or if there was an error when sending the message. - Since:
- MaDKit 5
-
broadcast
Broadcasts a message to every agent having a role in a group in a community using a specific role for the sender. The sender is excluded from the search.- Parameters:
message
- message to sendreceivers
- list of agent addresses to send the message to- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If the role does not exist.Agent.ReturnCode.NOT_ROLE
: If this agent is not a member of the targeted group.Agent.ReturnCode.NOT_IN_GROUP
: If no agent was found as recipient, i.e. the sender was the only agent having this role.Agent.ReturnCode.NO_RECIPIENT_FOUND
- See Also:
-
broadcastWithRole
public Agent.ReturnCode broadcastWithRole(Message message, List<AgentAddress> receivers, String role) Broadcasts a message to every agent having a role in a group in a community using a specific role for the sender. The sender is excluded from the search.- Parameters:
message
- message to sendreceivers
- list of agent addresses to send the message torole
- the agent's role with which the message should be sent- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If the community does not exist.Agent.ReturnCode.NOT_COMMUNITY
: If the group does not exist.Agent.ReturnCode.NOT_GROUP
: If the role does not exist.Agent.ReturnCode.NOT_ROLE
: If this agent is not a member of the targeted group.Agent.ReturnCode.NOT_IN_GROUP
: If no agent was found as recipient, i.e. the sender was the only agent having this role.Agent.ReturnCode.NO_RECIPIENT_FOUND
- See Also:
-
broadcastWithRoleWaitForReplies
protected <T extends Message> List<T> broadcastWithRoleWaitForReplies(Message message, List<AgentAddress> receivers, String senderRole, Integer timeOutMilliSeconds) Broadcasts a message and wait for answers considering a timeout duration.- Type Parameters:
T
- the type of the message to get- Parameters:
message
- the message to broadcastreceivers
- the list of agent addresses to send the message tosenderRole
- the agent's role with which the message should betimeOutMilliSeconds
- the maximum time to wait.- Returns:
- a list of messages which are answers to the
message
which has been broadcasted.
-
getAgentsWithRole
Returns a list of agent addresses corresponding to agents having this role in the organization. The caller is excluded from this search.- Parameters:
community
- the community namegroup
- the group namerole
- the role name- Returns:
- a list of agent addresses corresponding to agents handling this role
-
checkAgentAddress
Checks if this agent address is still valid. I.e. the corresponding agent is still playing this role.- Parameters:
agentAddress
- the agent address to check- Returns:
true
if the address still exists in the organization.- Since:
- MaDKit 5.0.4
-
replyWithRole
Sends a message by replying to a previously received message. The sender is excluded from this search.- Parameters:
reply
- the reply itself.messageToReplyTo
- the previously received message.senderRole
- the agent's role with which the message should be sent- Returns:
: If the send has succeeded.Agent.ReturnCode.SUCCESS
: If this agent is no longer a member of the corresponding group.Agent.ReturnCode.NOT_IN_GROUP
: IfAgent.ReturnCode.ROLE_NOT_HANDLED
senderRole
is not handled by this agent.
: If the receiver address is no longer valid. This is the case when the corresponding agent has leaved the role corresponding to the receiver agent address.Agent.ReturnCode.INVALID_AGENT_ADDRESS
- See Also:
-
reply
Sends a message by replying to a previously received message. This has the same effect assendReplyWithRole(messageToReplyTo, reply, null)
.- Parameters:
reply
- the reply itself.messageToReplyTo
- the previously received message.- Returns:
: If the reply has succeeded.Agent.ReturnCode.SUCCESS
: If this agent is no longer a member of the corresponding group.Agent.ReturnCode.NOT_IN_GROUP
: If the receiver address is no longer valid. This is the case when the corresponding agent has leaved the role corresponding to the receiver agent address.Agent.ReturnCode.INVALID_AGENT_ADDRESS
- See Also:
-
getReplyTo
Gets the next message which is a reply to the originalMessage.- Type Parameters:
T
- the type of the message to get- Parameters:
originalMessage
- the message to which a reply is searched.- Returns:
- a reply to the originalMessage or
null
if no reply to this message has been received.
-
waitNextMessage
This method is the blocking version of nextMessage(). If there is no message in the mailbox, it suspends the agent life until a message is received- Type Parameters:
T
- the type of the message to get- Returns:
- the first received message
- See Also:
-
waitNextMessage
This method gets the next message of the mailbox or waits for a new incoming message considering a certain delay.- Type Parameters:
T
- the type of the message to get- Parameters:
timeOutMilliseconds
- the maximum time to wait, in milliseconds.- Returns:
- the first message in the mailbox, or
null
if no message has been received before the time out delay is elapsed
-
waitAnswer
Retrieves and removes the next message that is a reply to the query message, waiting for ever if necessary until a matching reply becomes available.- Type Parameters:
T
- the type of the message to get- Parameters:
query
- the message for which a reply is waited for- Returns:
- the first reply to the query message
- Since:
- MadKit 5.0.4
-
waitAnswer
Retrieves and removes the next message that is a reply to the query message, waiting for ever if necessary until a matching reply becomes available.- Type Parameters:
T
- the type of the message to get- Parameters:
query
- the message for which a reply is waited fortimeOutMilliSeconds
- the maximum time to wait, in milliseconds.- Returns:
- the first reply to the query message
- Since:
- MadKit 5.0.4
-
receiveMessage
This method offers a convenient way for regular object to send messages to Agents, especially threaded agents. For instance when a GUI wants to discuss with its linked agent: This allows to enqueue work to do in their life cycle- Parameters:
message
- the message to send
-
getMailbox
-
setupDefaultGUI
public void setupDefaultGUI()Creates a default frame for the agent. It is made of aFXAgentStage
containing aFXOutputPane
-
getKernelAddress
The kernel's address on which this agent is running.- Returns:
- the kernel address representing the MaDKit kernel on which the agent is running
-
nextMessage
Retrieves the next message from the mailbox.It returns the next message of type
M
from the mailbox. The type parameterM
must extend theMessage
class, allowing for flexibility in the types of messages that can be processed.- Type Parameters:
M
- the type of the message to get- Returns:
- the next message of type
M
from the mailbox.
-
executeThisAgent
This offers a convenient way to create main a main method that launches the agent class under development. The agent is launched in a new instance MaDKit. This call only works in the main method of the agent's class. MaDKit. Here is an example of use that will work in any subclass ofAgent
: To launch 10 instances of an agent, you can use:public static void main(String[] args) { executeThisAgent(10, args); }
- Parameters:
nbOfInstances
- specify how many of this kind should be launchedargs
- MaDKit options.- Returns:
- the kernel instance that actually launches this agent, so that it is possible to do other actions after the launch
- Since:
- MaDKit 5.0.0.14
-
executeThisAgent
This offers a convenient way to create a main method that launches the agent class under development. This call only works in the main method of the agent's class. This call is equivalent toexecuteThisAgent(1, true, args)
- Parameters:
args
- MaDKit options- Returns:
- the kernel instance that actually launches this agent, so that it is possible
to do other actions after the launch using
Madkit.launchAgent(Agent)
- Since:
- MaDKit 5.0.0.14
- See Also:
-
handleRequestActionMessage
Handles aRequestActionMessage
so that the agent will trigger the corresponding method using the parameters of the message. Such messages are usually sent by GUI buttons or other user interfaces to trigger actions in the agent.- Parameters:
message
- the message to handle
-
onActivation()
instead.