public class Behavior extends java.lang.Object implements java.lang.Comparable<Behavior>
CyclicBehavior
for continuous behaviors
OneShotBehavior
for one time behaviors
WakerBehavior
for behaviors to be executed once after a specified period
TickerBehavior
for behaviors to be executed periodically
BackoffBehavior
for retry or backoff timeouts
PoissonBehavior
for simulating Poisson arrival processes
MessageBehavior
for behaviors to process incoming messages
TestBehavior
for unit testing
FSMBehavior
for implementing finite state machines
Modifier and Type | Field and Description |
---|---|
protected Callback |
action
If this field is not null, the default action() method calls it.
|
protected Agent |
agent
Agent owning this behavior.
|
protected java.util.logging.Logger |
log
Logger for the behavior to log messages to.
|
Constructor and Description |
---|
Behavior() |
Modifier and Type | Method and Description |
---|---|
void |
action()
This method is repeatedly called during the life of a behavior.
|
AgentID |
agent(java.lang.String name)
Convenience method to create an owned agent id for the named agent.
|
AgentID |
agentForService(java.lang.Enum<?> service)
Convenience method to find an agent that provides a named service.
|
AgentID |
agentForService(java.lang.String service)
Convenience method to find an agent that provides a named service.
|
AgentID[] |
agentsForService(java.lang.Enum<?> service)
Convenience method to find all agents that provides a named service.
|
AgentID[] |
agentsForService(java.lang.String service)
Convenience method to find all agents that provides a named service.
|
void |
block()
Blocks the behavior.
|
void |
block(long millis)
Blocks the behavior for a specified period of time.
|
int |
compareTo(Behavior obj)
Implements natural ordering based on behavior priority.
|
boolean |
done()
This method should return true if the behavior is completed, false otherwise.
|
int |
getPriority()
This method should return a number that denotes the priority of a behavior.
|
boolean |
isBlocked()
Returns true if the behavior is blocked, false otherwise.
|
void |
onEnd()
This method is called when a behavior is completed.
|
void |
onStart()
This method is called when a behavior is added to an agent.
|
void |
println(java.lang.String msg)
Log a message at an INFO level.
|
void |
reset()
Resets a behavior to its initial state.
|
void |
restart()
Unblocks the behavior if it was blocked.
|
protected Agent agent
protected java.util.logging.Logger log
protected Callback action
public void onStart()
public void onEnd()
public void action()
public boolean done()
public int getPriority()
public int compareTo(Behavior obj)
compareTo
in interface java.lang.Comparable<Behavior>
public void block()
action()
is completed. In a blocked state, the
action()
method is no longer called until the behavior is unblocked by
a call to restart()
. Unlike Agent.block()
, this method is non-blocking.public void block(long millis)
action()
is completed. In a
blocked state, the action()
method is no longer called until the behavior is
unblocked after the specified period of time or by a call to restart()
.
Unlike Agent.block()
, this method is non-blocking.millis
- number of milliseconds before the behavior should be unblocked.public void restart()
block()
public boolean isBlocked()
public void reset()
public AgentID agent(java.lang.String name)
public AgentID agentForService(java.lang.String service)
service
- the named service of interest.public AgentID agentForService(java.lang.Enum<?> service)
service
- the named service of interest.public AgentID[] agentsForService(java.lang.String service)
service
- the named service of interest.public AgentID[] agentsForService(java.lang.Enum<?> service)
service
- the named service of interest.public void println(java.lang.String msg)
msg
- message to log.