Summary
A basic state machine by Tony Swain. This is designed to work from one Thread. Thus never a need to synchronize
Source file: StateMachine.java
Referenced HyperView classes
Declaration & members
public class StateMachine implements StateMachineConstants, StateMachineListener
Declared in src/com/multiversesocial/hyperview/StateMachine.java, lines 12–445. 10 field(s), 3 constructor(s), 8 method(s), plus 9 nested type(s). Every member has an anchor you can link to (e.g. StateMachine.html#<id>).
Fields (10)
| Declaration | Value / initializer | Description | Source |
private int allocatedStates | | No comment in source; assigned in add(); used in toString(). | line 18 |
byte[] buffer | | No comment in source; assigned in StateMachine(), cleanUp(). | line 22 |
int bufferSize | | No comment in source; assigned in StateMachine(); used in toString(). | line 23 |
int currentState | | No comment in source; used in toString(). | line 19 |
public static final int MAX_STATES | = 8 (constant) | byte/short/char/int/long/float/double/String/data[n] | line 16 |
private StateMachineListener notifier | | No comment in source; assigned in StateMachine(), addNotifier(), removeNotifier(), cleanUp(); used in toString(). | line 15 |
StateDispatch[] stateDispatch | | No comment in source; assigned in StateMachine(), makeStateObjects(), add(), cleanUp(); used in toString(). | line 17 |
public volatile int stateFlags | | No comment in source; assigned in StateMachine(), orStateFlags(); used in getStateFlags(), toString(). | line 14 |
volatile int systemBufferIndex | | No comment in source; used in toString(). | line 21 |
volatile int userBufferIndex | | No comment in source; used in toString(). | line 20 |
Constructors (3)
| Signature | Description | Source |
StateMachine() | 3 statement(s); calls super(). | line 25 |
StateMachine(StateMachineListener tNotifier) | 6 statement(s); calls super(), makeStateObjects(). | line 31 |
StateMachine(HyperConnectionNode tNode, StateMachineListener tNotifier) | 6 statement(s); calls super(), makeStateObjects(). | line 40 |
Methods (8)
| Signature | Description | Source |
int add(StateDispatch tDispatch) throws StateMachine.OutOfChannelSpaceException | 4 statement(s); creates OutOfChannelSpaceException. | line 75 |
public void addNotifier(StateMachineListener tObject) throws StateMachine.IllegalStateMachineAddObjectNotifierException | 2 statement(s); creates IllegalStateMachineAddObjectNotifierException. | line 121 |
public void cleanUp() | 3 statement(s). | line 135 |
public int getStateFlags() | Returns stateFlags. Implements StateMachineListener.getStateFlags() | line 50 |
public void makeStateObjects() | 2 statement(s); creates GetByte, GetShort, GetChar. | line 61 |
public int orStateFlags(int tInt) | 2 statement(s). Implements StateMachineListener.orStateFlags() | line 55 |
public void removeNotifier() | Sets notifier = null. | line 130 |
public String toString() | 13 statement(s); calls sb.append(), notifier.toString(), stateDispatch[tz].toString(), sb.toString(); creates StringBuilder. Overrides Object.toString() | line 87 |
Nested & additional classes
GetByte (nested type, lines 145–184)
class GetByte extends StateDispatch
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
GetByte() | 1 statement(s); calls super(). | line 147 |
Methods (1)
GetShort (nested type, lines 188–242)
class GetShort extends StateDispatch
Fields (3)
| Declaration | Value / initializer | Description | Source |
int count | | No comment in source; assigned in GetShort(). | line 190 |
int currentByte | | No comment in source; assigned in GetShort(). | line 192 |
short inVal | | No comment in source; assigned in GetShort(). | line 191 |
Constructors (1)
| Signature | Description | Source |
GetShort() | 3 statement(s); calls super(). | line 194 |
Methods (1)
| Signature | Description | Source |
public int processInput(HyperNodeReadVector tReadVector, int tLength) | 7 statement(s); calls System.exit(), readBuffer.get(), notifier.orStateFlags(), notifier.notifyAll(). Overrides StateDispatch.processInput() | line 202 |
GetChar (nested type, lines 246–294)
class GetChar extends StateDispatch
Fields (3)
| Declaration | Value / initializer | Description | Source |
private int currentByte | | No comment in source; assigned in GetChar(); used in processInput(). | line 249 |
public volatile int inLength | | No comment in source; assigned in GetChar(). | line 248 |
private int retVal | | No comment in source; assigned in GetChar(), processInput(). | line 250 |
Constructors (1)
| Signature | Description | Source |
GetChar() | 2 statement(s); calls super(). | line 252 |
Methods (1)
GetInt (nested type, lines 299–347)
class GetInt extends StateDispatch
Fields (3)
| Declaration | Value / initializer | Description | Source |
private int currentByte | | No comment in source; assigned in GetInt(); used in processInput(). | line 302 |
public volatile int inLength | | No comment in source; assigned in GetInt(). | line 301 |
private int retVal | | No comment in source; assigned in GetInt(), processInput(). | line 303 |
Constructors (1)
| Signature | Description | Source |
GetInt() | 2 statement(s); calls super(). | line 305 |
Methods (1)
GetLong (nested type, lines 351–396)
class GetLong extends StateDispatch
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
GetLong() | 1 statement(s); calls super(). | line 353 |
Methods (1)
GetString (nested type, lines 400–410)
class GetString extends StateDispatch
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
GetString() | 1 statement(s); calls super(). | line 402 |
Methods (1)
GetData (nested type, lines 415–427)
class GetData extends StateDispatch
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
GetData() | 1 statement(s); calls super(). | line 418 |
Methods (1)
OutOfChannelSpaceException (nested type, lines 429–435)
class OutOfChannelSpaceException extends Exception
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
OutOfChannelSpaceException() | 1 statement(s); calls super(). | line 431 |
Methods (0)
None declared.
IllegalStateMachineAddObjectNotifierException (nested type, lines 437–443)
class IllegalStateMachineAddObjectNotifierException extends Exception
Fields (0)
None declared.
Constructors (1)
| Signature | Description | Source |
IllegalStateMachineAddObjectNotifierException() | 1 statement(s); calls super(). | line 439 |
Methods (0)
None declared.
Examples
Real usage taken from elsewhere in the HyperView 3.2 source (file and line shown; source path src/com/multiversesocial/hyperview/).
instantiation — HyperConnectionNode.java, line 129
129 stateMachine = new StateMachine(this,(StateMachineListener)null);
subclass — ServerStateMachine.java, line 8
8 public class ServerStateMachine extends StateMachine
9 {
declaration — HyperNodeReadVector.java, line 17
17 StateMachine stateMachine = null;