public abstract class BaseEngine extends java.lang.Object implements SpeechEventDispatcher
Engine interface.
Actual JSAPI implementations might want to extend or modify this
implementation.| Modifier and Type | Field and Description |
|---|---|
protected AudioManager |
audioManager
The
AudioManager for this Engine. |
protected static long |
CLEAR_ALL_STATE
Utility state for clearing the
engineState. |
protected java.util.Collection |
engineListeners
List of
EngineListeners registered for
EngineEvents on this Engine. |
protected EngineModeDesc |
engineModeDesc
The
EngineModeDesc for this Engine. |
protected EngineProperties |
engineProperties
The
EngineProperties for this Engine. |
protected long |
engineState
A bitmask holding the current state of this
Engine. |
protected java.lang.Object |
engineStateLock
An
Object used for synchronizing access to
engineState. |
| Constructor and Description |
|---|
BaseEngine()
Creates a new
Engine in the
DEALLOCATED state. |
BaseEngine(EngineModeDesc desc)
Creates a new
Engine in the
DEALLOCATED state. |
| Modifier and Type | Method and Description |
|---|---|
void |
addEngineListener(EngineListener listener)
Requests notification of
EngineEvents from this
Engine. |
void |
allocate()
Allocates the resources required for this
Engine and
puts it into the ALLOCATED state. |
protected void |
checkEngineState(long state)
Convenience method that throws an
EngineStateError
if any of the bits in the passed state are set in the
state. |
protected abstract BaseEngineProperties |
createEngineProperties()
Factory constructor for EngineProperties object.
|
void |
deallocate()
Frees the resources of this
Engine that were
acquired during allocation and during operation and return this
Engine to the DEALLOCATED. |
void |
dispatchSpeechEvent(SpeechEvent event)
Dispatches a
SpeechEvent. |
void |
fireEngineAllocated(EngineEvent event)
Utility function that sends an
ENGINE_ALLOCATED
event to all EngineListeners registered with this
Engine. |
void |
fireEngineAllocatingResources(EngineEvent event)
Utility function that sends an
ENGINE_ALLOCATING_RESOURCES event to all
EngineListeners registered with this
Engine. |
void |
fireEngineDeallocated(EngineEvent event)
Utility function that sends an
ENGINE_DEALLOCATED event to all
EngineListeners registered with this
Engine. |
void |
fireEngineDeallocatingResources(EngineEvent event)
Utility function that sends a
ENGINE_DEALLOCATING_RESOURCES event to all
EngineListeners registered with this
Engine. |
void |
fireEnginePaused(EngineEvent event)
Utility function that sends an
ENGINE_PAUSED event
to all
EngineListeners registered with this
Engine. |
void |
fireEngineResumed(EngineEvent event)
Utility function that sends an
ENGINE_RESUMED event
to all
EngineListeners registered with this
Engine. |
AudioManager |
getAudioManager()
Returns an object that provides management of the audio input
or output of this
Engine. |
EngineModeDesc |
getEngineModeDesc()
Gets the current operating properties and mode of
this
Engine. |
EngineProperties |
getEngineProperties()
Gets the
EngineProperties of this Engine. |
long |
getEngineState()
Returns a or'ed set of flags indicating the current state of
this
Engine. |
VocabManager |
getVocabManager()
Returns an object that provides management of the vocabulary for
this
Engine. |
protected abstract void |
handleAllocate()
Called from the
allocate method. |
protected abstract void |
handleDeallocate()
Called from the
deallocate method. |
protected abstract void |
handlePause()
Called from the
pause method. |
protected abstract void |
handleResume()
Called from the
resume method. |
void |
pause()
Pauses the audio stream for this
Engine and put
this Engine into the PAUSED state. |
protected void |
postEngineAllocated(long oldState,
long newState)
Utility function that generates an
ENGINE_ALLOCATED event and posts it
to the event queue. |
protected void |
postEngineAllocatingResources(long oldState,
long newState)
Utility function that generates an
ENGINE_ALLOCATING_RESOURCES event and
posts it to the event queue. |
protected void |
postEngineDeallocated(long oldState,
long newState)
Utility function that generates an
ENGINE_DEALLOCATED event and posts it
to the event queue. |
protected void |
postEngineDeallocatingResources(long oldState,
long newState)
Utility function that generates
ENGINE_DEALLOCATING_RESOURCES event and
posts it to the event queue. |
protected void |
postEnginePaused(long oldState,
long newState)
Utility function that generates an
ENGINE_PAUSED event and posts it
to the event queue. |
protected void |
postEngineResumed(long oldState,
long newState)
Utility function that generates an
ENGINE_RESUMED
event and posts it to the event queue. |
void |
removeEngineListener(EngineListener listener)
Removes an
EngineListener from the list of
EngineListeners. |
void |
resume()
Resumes the audio stream for this
Engine and put
this Engine into the RESUMED state. |
protected void |
setEngineModeDesc(EngineModeDesc desc)
Sets the current operating properties and mode of
this
Engine. |
protected long[] |
setEngineState(long clear,
long set)
Updates this
Engine state by clearing defined bits,
then setting other specified bits. |
protected java.lang.String |
stateToString(long state)
Returns a
String of the names of all the
Engine states in the given Engine
state. |
boolean |
testEngineState(long state)
Returns
true if this state of this
Engine matches the specified state. |
java.lang.String |
toString()
Returns the engine name and mode for debug purposes.
|
void |
waitEngineState(long state)
Blocks the calling thread until this
Engine
is in a specified state. |
protected long engineState
Engine.protected java.lang.Object engineStateLock
Object used for synchronizing access to
engineState.engineStateprotected java.util.Collection engineListeners
EngineListeners registered for
EngineEvents on this Engine.protected AudioManager audioManager
AudioManager for this Engine.protected EngineModeDesc engineModeDesc
EngineModeDesc for this Engine.protected EngineProperties engineProperties
EngineProperties for this Engine.protected static final long CLEAR_ALL_STATE
engineState.public BaseEngine()
Engine in the
DEALLOCATED state.public BaseEngine(EngineModeDesc desc)
Engine in the
DEALLOCATED state.desc - the operating mode of this Enginepublic long getEngineState()
Engine.
An EngineEvent is issued each time this
Engine changes state.
The getEngineState method can be called successfully
in any Engine state.
EnginegetEngineState(),
waitEngineState(long)public void waitEngineState(long state)
throws java.lang.InterruptedException,
java.lang.IllegalArgumentException
Engine
is in a specified state.
All state bits specified in the state parameter
must be set in order for the method to return, as defined
for the testEngineState method. If the state
parameter defines an unreachable state
(e.g. PAUSED | RESUMED) an exception is thrown.
The waitEngineState method can be called successfully
in any Engine state.
state - a bitmask of the state to wait forjava.lang.InterruptedException - if another thread has interrupted this thread.java.lang.IllegalArgumentException - if the specified state is unreachabletestEngineState(long),
getEngineState()public boolean testEngineState(long state)
throws java.lang.IllegalArgumentException
true if this state of this
Engine matches the specified state.
The test performed is not an exact match to the current
state. Only the specified states are tested. For
example the following returns true only if the
Synthesizer queue is empty, irrespective
of the pause/resume and allocation states.
if (synth.testEngineState(Synthesizer.QUEUE_EMPTY)) ...
The testEngineState method is equivalent to:
if ((engine.getEngineState() & state) == state)
The testEngineState method can be called
successfully in any Engine state.
state - a bitmask of the states to test fortrue if this Engine matches
state; otherwise falsejava.lang.IllegalArgumentException - if the specified state is unreachableprotected long[] setEngineState(long clear,
long set)
Engine state by clearing defined bits,
then setting other specified bits.public void allocate()
throws EngineException,
EngineStateError
Engine and
puts it into the ALLOCATED state. When this method
returns successfully the ALLOCATED bit of this
Engine state is set, and the
testEngineState(Engine.ALLOCATED) method returns
true.
During the processing of the method, this Engine is
temporarily in the ALLOCATING_RESOURCES state.
EngineException - if this Engine cannot be allocatedEngineStateError - if this Engine is in the
DEALLOCATING_RESOURCES statedeallocate()protected abstract void handleAllocate()
throws EngineException
allocate method. Override this in
subclasses.EngineException - if problems are encounteredallocate()public void deallocate()
throws EngineException,
EngineStateError
Engine that were
acquired during allocation and during operation and return this
Engine to the DEALLOCATED. When this
method returns the DEALLOCATED bit of this
Engine state is set so the
testEngineState(Engine.DEALLOCATED) method returns
true.
During the processing of the method, this
Engine is temporarily in the
DEALLOCATING_RESOURCES state.
A deallocated engine can be re-started with a subsequent
call to allocate.
EngineException - if this Engine cannot be
deallocatedEngineStateError - if this Engine is in the
ALLOCATING_RESOURCES stateallocate()protected abstract void handleDeallocate()
throws EngineException
deallocate method. Override this in
subclasses.EngineException - if this Engine cannot be
deallocated.public void pause()
throws EngineStateError
Engine and put
this Engine into the PAUSED state.EngineStateError - if this Engine is in the
DEALLOCATING_RESOURCES or
DEALLOCATED state.protected abstract void handlePause()
pause method. Override this in subclasses.public void resume()
throws AudioException,
EngineStateError
Engine and put
this Engine into the RESUMED state.AudioException - if unable to gain access to the audio channelEngineStateError - if this Engine is in the
DEALLOCATING_RESOURCES or
DEALLOCATED stateprotected abstract void handleResume()
resume method. Override in subclasses.public AudioManager getAudioManager()
Engine.Enginepublic VocabManager getVocabManager()
throws EngineStateError
Engine. Returns null if this
Engine does not support vocabulary management.EngineEngineStateError - if this Engine in the
DEALLOCATING_RESOURCES or
DEALLOCATED statepublic EngineProperties getEngineProperties()
EngineProperties of this Engine.
Must be set in subclasses.EngineProperties of this Engine.public EngineModeDesc getEngineModeDesc()
throws java.lang.SecurityException
Engine.Enginejava.lang.SecurityExceptionprotected void setEngineModeDesc(EngineModeDesc desc)
Engine.desc - the new operating mode of this Enginepublic void addEngineListener(EngineListener listener)
EngineEvents from this
Engine.listener - the listener to add.public void removeEngineListener(EngineListener listener)
EngineListener from the list of
EngineListeners.listener - the listener to remove.protected void postEngineAllocated(long oldState,
long newState)
ENGINE_ALLOCATED event and posts it
to the event queue. Eventually
fireEngineAllocated will be called
by the dispatchSpeechEvent as a result of this
action.oldState - the old state of this EnginenewState - the new state of this EnginefireEngineAllocated(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEngineAllocated(EngineEvent event)
ENGINE_ALLOCATED
event to all EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_ALLOCATED eventpostEngineAllocated(long, long),
dispatchSpeechEvent(SpeechEvent)protected void postEngineAllocatingResources(long oldState,
long newState)
ENGINE_ALLOCATING_RESOURCES event and
posts it to the event queue. Eventually
fireEngineAllocatingResources
will be called by dispatchSpeechEvent as a
result of this action.oldState - the old state of this EnginenewState - the new state of this EnginefireEngineAllocatingResources(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEngineAllocatingResources(EngineEvent event)
ENGINE_ALLOCATING_RESOURCES event to all
EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_ALLOCATING_RESOURCES eventpostEngineAllocatingResources(long, long),
dispatchSpeechEvent(SpeechEvent)protected void postEngineDeallocated(long oldState,
long newState)
ENGINE_DEALLOCATED event and posts it
to the event queue. Eventually
fireEngineDeallocated will be called
by dispatchSpeechEvent as a result of this action.oldState - the old state of this EnginenewState - the new state of this EnginefireEngineDeallocated(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEngineDeallocated(EngineEvent event)
ENGINE_DEALLOCATED event to all
EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_DEALLOCATED eventpostEngineDeallocated(long, long),
dispatchSpeechEvent(SpeechEvent)protected void postEngineDeallocatingResources(long oldState,
long newState)
ENGINE_DEALLOCATING_RESOURCES event and
posts it to the event queue. Eventually
fireEngineAllocatingResources will be called
by dispatchSpeechEvent as a result of this action.oldState - the old state of this EnginenewState - the new state of this EnginefireEngineDeallocatingResources(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEngineDeallocatingResources(EngineEvent event)
ENGINE_DEALLOCATING_RESOURCES event to all
EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_DEALLOCATING_RESOURCES eventpostEngineDeallocatingResources(long, long),
dispatchSpeechEvent(SpeechEvent)protected void postEnginePaused(long oldState,
long newState)
ENGINE_PAUSED event and posts it
to the event queue. Eventually
fireEnginePaused will be called
by dispatchSpeechEvent as a result of this action.oldState - the old state of this EnginenewState - the new state of this EnginefireEnginePaused(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEnginePaused(EngineEvent event)
ENGINE_PAUSED event
to all
EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_PAUSED eventpostEnginePaused(long, long),
dispatchSpeechEvent(SpeechEvent)protected void postEngineResumed(long oldState,
long newState)
ENGINE_RESUMED
event and posts it to the event queue. Eventually
fireEngineResumed will be called
by dispatchSpeechEvent as a result of this action.oldState - the old state of this EnginenewState - the new state of this EnginefireEngineResumed(EngineEvent),
dispatchSpeechEvent(SpeechEvent)public void fireEngineResumed(EngineEvent event)
ENGINE_RESUMED event
to all
EngineListeners registered with this
Engine. Called by dispatchSpeechEvent.event - the ENGINE_RESUMED eventpostEngineResumed(long, long),
dispatchSpeechEvent(SpeechEvent)protected abstract BaseEngineProperties createEngineProperties()
BaseEngineProperties object specific to
a subclass.protected void checkEngineState(long state)
throws EngineStateError
EngineStateError
if any of the bits in the passed state are set in the
state.state - the Engine state to checkEngineStateError - if any of the bits in the passed state
are set in the stateprotected java.lang.String stateToString(long state)
String of the names of all the
Engine states in the given Engine
state.state - the bitmask of statesString containing the names of all the
states set in statepublic void dispatchSpeechEvent(SpeechEvent event)
SpeechEvent.
The dispatcher should notify all EngineListeners
from this method. The SpeechEvent was added
via the various post methods of this class.dispatchSpeechEvent in interface SpeechEventDispatcherevent - the SpeechEvent to dispatchpostEngineAllocatingResources(long, long),
postEngineAllocated(long, long),
postEngineDeallocatingResources(long, long),
postEngineDeallocated(long, long),
postEnginePaused(long, long),
postEngineResumed(long, long)public java.lang.String toString()
toString in class java.lang.Object