public class FSMBehavior extends Behavior
An example FSM is shown below:
FSMBehavior fsm = new FSMBehavior(); fsm.add(new FSMBehavior.State("state1") { public void action() { log.info("In State #1"); setNextState("state2"); } }); fsm.add(new FSMBehavior.State("state2") { public void action() { log.info("In State #2"); terminate(); } }); agent.add(fsm);
Modifier and Type | Class and Description |
---|---|
static class |
FSMBehavior.State
FSM state behavior.
|
Constructor and Description |
---|
FSMBehavior()
Creates a FSM behavior.
|
FSMBehavior(FSMBehavior.State... states)
Creates a FSM behavior.
|
Modifier and Type | Method and Description |
---|---|
void |
action()
This method is repeatedly called during the life of a behavior.
|
void |
add(FSMBehavior.State state)
Adds a state to the FSM.
|
void |
clear()
Clears the FSM states.
|
boolean |
done()
This method should return true if the behavior is completed, false otherwise.
|
java.lang.Object |
getCurrentState()
Gets the current state name.
|
void |
reenterState()
Request re-entry of the current state in the FSM.
|
void |
reset()
Resets the FSM.
|
void |
setInitialState(java.lang.Object name)
Sets the initial state to start FSM in.
|
void |
setNextState(java.lang.Object name)
Sets the next state of the FSM.
|
void |
terminate()
Terminates the FSM by setting the next state to be FINAL.
|
void |
trigger(java.lang.Object event)
Trigger an event on the FSM.
|
void |
trigger(java.lang.Object event,
java.lang.Object eventInfo)
Trigger an event on the FSM.
|
agent, agentForService, agentForService, agentsForService, agentsForService, block, block, compareTo, getPriority, isBlocked, onEnd, onStart, println, restart
public FSMBehavior()
public FSMBehavior(FSMBehavior.State... states)
states
- States to be added to the FSM behavior.public void action()
Behavior
public boolean done()
Behavior
public void reset()
FSMBehavior.State.onExit()
being called. The states added to the FSM
are retained.reset
in class Behavior
Behavior.reset()
public void clear()
FSMBehavior.State.onExit()
being called.public void add(FSMBehavior.State state)
state
- state behavior.public void setInitialState(java.lang.Object name)
name
- initial state object or name.public void setNextState(java.lang.Object name)
name
- name of the state.public void reenterState()
public java.lang.Object getCurrentState()
public void terminate()
public void trigger(java.lang.Object event)
event
- an object naming the event.public void trigger(java.lang.Object event, java.lang.Object eventInfo)
event
- an object naming the event.eventInfo
- an object providing extra information on the event.