|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread com.codexombie.jspasm.Engine
public final class Engine
This is the run-time core of the state engine system. This thread is responsible for controlling the dispatchers and data structures of the whole system.
The engine can be configured to run with one of three thread schemes:
setThreadScheme()
with a
string parameter value of "engine"
, "model"
or
"entity"
(the string is not case-sensitive and can contain
leading or trailing white space). Passing a null value or an empty string
sets the default mode. For the thread-per-engine scheme, use
setThreadCount()
to set the number of threads.
When setting up an Engine the recommended sequence of operations is:
Engine.start()
);
shutdown()
then
Engine.join()
to wait for it to terminate.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
static java.util.Properties |
cfgProp
Configuration properties, if any. |
static int |
THREAD_PER_ENGINE
Preset value for thread-per-engine thread scheme. |
static int |
THREAD_PER_ENTITY
Preset value for thread-per-entity thread scheme. |
static int |
THREAD_PER_MODEL
Preset value for thread-per-model thread scheme. |
static int |
THREAD_SCHEME_MAX
Preset value for thread-pool thread scheme. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Engine(java.lang.String id)
Constructor. |
Method Summary | |
---|---|
void |
addModel(Model model)
Add a model to the Engine's internal data. |
AbsEntity |
createEntity(java.lang.String modelId,
java.lang.String entityId,
java.lang.Object[] initArgs)
Creates a new Entity for a specific Model. |
void |
generateEvent(java.lang.String entityId,
java.lang.String eventSpecId)
Generate an event with no arguments for delivery to a specified entity. |
void |
generateEvent(java.lang.String entityId,
java.lang.String eventSpecId,
java.lang.Object[] args)
Generate an event for delivery to a specified entity. |
void |
run()
|
void |
setExceptionHandler(IExceptionHandler exceptionHandler)
Set the exception handler. |
void |
setStateChangeHandler(IStateChangeHandler stateChangeHandler)
Set the state change handler. |
void |
setThreadCount(int threadCount)
Sets the thread count for the per-engine mode. |
void |
setThreadScheme(int threadSchemeValue)
Set the thread scheme. |
void |
setThreadScheme(java.lang.String threadSchemeString)
Set the thread scheme. |
void |
shutdown()
Order the Engine thread to terminate. |
void |
start()
|
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int THREAD_PER_ENGINE
Preset value for thread-per-engine thread scheme.
public static final int THREAD_PER_MODEL
Preset value for thread-per-model thread scheme.
public static final int THREAD_PER_ENTITY
Preset value for thread-per-entity thread scheme.
public static final int THREAD_SCHEME_MAX
Preset value for thread-pool thread scheme.
public static java.util.Properties cfgProp
Configuration properties, if any. By default this will be empty (not
null). The location of a property file can be provided as a system
property on the command line (using the
-Djspasm.configuration=location
setting).
Constructor Detail |
---|
public Engine(java.lang.String id)
Constructor.
id
- The name to give to the engine.Method Detail |
---|
public void addModel(Model model) throws StateModelConfigurationException
Add a model to the Engine's internal data.
model
- The model to register.
StateModelConfigurationException
- if the supplied model is null or already registered.public AbsEntity createEntity(java.lang.String modelId, java.lang.String entityId, java.lang.Object[] initArgs) throws StateProcessingException, java.lang.InstantiationException, java.lang.IllegalAccessException
Creates a new Entity for a specific Model. The Entity class is as defined by the Model.
modelId
- The model to create the entity in.entityId
- The unique id to give to the entity.initArgs
- The initialization arguments (must match the arguments for the
Model's initial state).
StateProcessingException
- if any arguments are null, the model does not exist or the
entity id already exists.
java.lang.InstantiationException
- if the entity cannot be instantiated.
java.lang.IllegalAccessException
- if the state method of the initialization state cannot be
executed.public void generateEvent(java.lang.String entityId, java.lang.String eventSpecId, java.lang.Object[] args) throws StateProcessingException
Generate an event for delivery to a specified entity.
entityId
- The target of the event.eventSpecId
- The event type to be generated.args
- The event arguments.
StateProcessingException
- if any arguments are null, the event or entity names do not
exist, etc.public void generateEvent(java.lang.String entityId, java.lang.String eventSpecId) throws StateProcessingException
Generate an event with no arguments for delivery to a specified entity.
entityId
- The target of the event.eventSpecId
- The event type to be generated.
StateProcessingException
- if any arguments are null, the event or entity names do not
exist, etc.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void start()
start
in class java.lang.Thread
public void setExceptionHandler(IExceptionHandler exceptionHandler)
Set the exception handler. Exception handling is disabled by setting the
exception handler to null
.
exceptionHandler
- Exception handler instance, or null
.public void setStateChangeHandler(IStateChangeHandler stateChangeHandler)
Set the state change handler. Change handling is disabled by setting the
state change handler to null
.
stateChangeHandler
- StateChangeHandler instance, or null
.public void setThreadCount(int threadCount)
Sets the thread count for the per-engine mode.
threadCount
- public void setThreadScheme(int threadSchemeValue) throws java.lang.Exception
Set the thread scheme.
threadSchemeValue
- The thread scheme value.
java.lang.Exception
- if the engine is already running or the scheme value is
invalid.public void setThreadScheme(java.lang.String threadSchemeString) throws java.lang.Exception
Set the thread scheme.
threadSchemeString
- The thread scheme name.
java.lang.Exception
- if the engine is already running or the scheme name is not
recognized.public void shutdown()
Order the Engine thread to terminate.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |