See: Description
Interface | Description |
---|---|
_Operation |
An operation performed by a state machine.
|
ActorFunc |
Returns an actor.
|
BooleanFunc |
Returns a boolean.
|
ObjectFunc |
Returns an object.
|
Class | Description |
---|---|
_Call |
Instantiate and execute a subordinate state machine.
|
_Goto |
Set the program counter of the state machine.
|
_IfF |
If the (indirect) condition is true, set the program counter of the state machine.
|
_IfV |
If the condition is true, set the program counter of the state machine.
|
_Iterator |
A state machine compatible extension of JAIterator.
|
_ReturnF |
Exit the state machine with the given (indirect) result.
|
_ReturnV |
Exit the state machine with the given result.
|
_Send |
Send a request to an actor.
|
_SendFF |
Send an (indirect) request to an (indirect) actor.
|
_SendFV |
Send an (indirect) request to an actor.
|
_SendVF |
Send a request to an (indirect) actor.
|
_SendVV |
Send a request to an actor.
|
_SetF |
Assign an (indirect) partial result.
|
_SetV |
Assign a partial result.
|
_SMBuilder |
Creates and runs a state machine.
|
ExtendedResponseProcessor<RESPONSE_TYPE> |
Supports processing sensitive to how a response is returned.
|
SimpleMachine |
A state machine.
|
You can think of a State Machine as a kind of computer. The three main parts of a computer are the program, the program counter and the memory.
The program is an array of operations which are executed by the state machine. The program counter is an index which identifies the next operation to be executed. The execution cycle of a state machine is a loop with 3 steps:
When you reach the end of the array, the state machine exits.
An operation can change the value of the program counter. This is how a goto works. But to make things just a little friendlier, we add a table called labels. As we create the program, we can capture the index of the next location in the program array and save it with a string for a key in the labels table. This way a goto operation can be given the name of a location, which it looks up in the labels table, rather than an index into the array of operations.
The memory of the state machine is another table called results. This table also uses strings as keys. And an operation can easily access and update the results table.
Why use a state machine? Because it is simpler to program a state machine to execute a series of operations than it is to code it directly, when each operation has a callback which is invoked when the operation completes. The state machine handles all the callbacks, allowing you to focus on the operations to be performed.
The nested class JLPCActor.SMBuilder is a concrete implementation of _SMBuilder and is used to define, instantiate and execute state machines.
class ReturnF1 extends JLPCActor { ReturnF1(Mailbox mailbox) { super(mailbox); } public void processRequest(Object unwrappedRequest, RP rp) throws Exception { SMBuilder smb = new SMBuilder(); smb._return(new ObjectFunc() { public Object get(StateMachine sm) { return "Hello world!"; } }); smb.call(rp); } } Result: Hello world!
Copyright © 2012. All Rights Reserved.