ConfigType
- public interface IModule<ConfigType extends ModuleConfig> extends IEventProducer
Generic interface for all modules in the system.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CANNOT_INIT_MSG |
static java.lang.String |
CANNOT_LOAD_MSG |
static java.lang.String |
CANNOT_START_MSG |
static java.lang.String |
CANNOT_STOP_MSG |
static java.lang.String |
CANNOT_UPDATE_MSG |
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Cleans up all ressources used by the module when deleted
All persistent resources created by the module should be cleaned
when this is called
|
ConfigType |
getConfiguration()
Retrieves a copy of the module configuration
(i.e.
|
java.lang.Throwable |
getCurrentError() |
ModuleEvent.ModuleState |
getCurrentState() |
java.lang.String |
getLocalID()
Helper method to get the module's local ID
|
java.lang.String |
getName()
Helper method to get the module's name
|
java.lang.String |
getStatusMessage() |
void |
init()
Initializes the module synchronously with the current configuration.
Implementations of this method must block until the module is successfully initialized or send an exception. Module lifecycle events may not be generated when calling this method directly. |
void |
init(ConfigType config)
Initializes the module synchronously with the specified configuration.
Implementations of this method must block until the module is successfully initialized or send an exception. This is equivalent to calling setConfiguration(ModuleConfig)
and then init() with no arguments.Module lifecycle events may not be generated when calling this method directly. |
boolean |
isInitialized()
Checks if module is initialized
|
boolean |
isStarted()
Checks if module is started
|
void |
loadState(IModuleStateManager loader)
Restores the state of this module
Implementations of this method must block until the module state is successfully loaded or send an exception. |
void |
registerListener(IEventListener listener)
Registers a listener to receive events generated by this module.
When this method is called, the current state of the module is also notified synchronously to guarantee that the listener always receives it. |
void |
requestInit(boolean force)
Requests to initialize the module with the current configuration.
Implementations of this method block until the module is initialized or return immediately while they wait for the proper init conditions. When this method returns without error the module state is guaranteed to be ModuleEvent.ModuleState.INITIALIZING |
void |
requestStart()
Requests the module to start.
Implementations of this method may block until the module is started or return immediately while they wait for the proper start conditions. When this method returns without error the module state is guaranteed to be ModuleEvent.ModuleState.STARTING |
void |
requestStop()
Requests the module to stop.
Implementations of this method may block until the module is stopped or return immediately while they wait for the proper stop conditions. When this method returns without error the module state is guaranteed to be ModuleEvent.ModuleState.STOPPING |
void |
saveState(IModuleStateManager saver)
Saves the state of this module.
Implementations of this method must block until the module state is successfully saved or send an exception. |
void |
setConfiguration(ConfigType config)
Sets the module configuration
|
void |
start()
Starts the module synchronously with the current configuration.
Implementations of this method must block until the module is successfully started or send an exception. Module lifecycle events may not be generated when calling this method directly. init() should always be called before start(). |
void |
stop()
Stops the module.
All temporary resources created by the module should be cleaned when this is called (ex: memory, files, connections, etc.) Implementations of this method must block until the module is successfully stopped or send an exception. Module lifecycle events may not be generated when calling this method directly. stop() can be called right after init() even if start() hasn't been called. |
void |
unregisterListener(IEventListener listener)
Unregisters a listener and thus stop receiving events generayed by this module
|
void |
updateConfig(ConfigType config)
Updates the module's configuration dynamically.
The module must honor this new configuration unless an error is detected. |
boolean |
waitForState(ModuleEvent.ModuleState state,
long timeout)
Waits until the module reaches the specified state or times out.
This method will return immediately if the state has already been reached. |
static final java.lang.String CANNOT_LOAD_MSG
static final java.lang.String CANNOT_INIT_MSG
static final java.lang.String CANNOT_START_MSG
static final java.lang.String CANNOT_STOP_MSG
static final java.lang.String CANNOT_UPDATE_MSG
void setConfiguration(ConfigType config)
config
- ConfigType getConfiguration()
java.lang.String getName()
java.lang.String getLocalID()
boolean isInitialized()
boolean isStarted()
ModuleEvent.ModuleState getCurrentState()
boolean waitForState(ModuleEvent.ModuleState state, long timeout)
state
- state to wait fortimeout
- maximum time to wait in milliseconds or <= 0 to wait foreverjava.lang.String getStatusMessage()
java.lang.Throwable getCurrentError()
void requestInit(boolean force) throws SensorHubException
ModuleEvent.ModuleState.INITIALIZING
force
- set to true to force a reinit, even if module was already initializedSensorHubException
- if module could not enter initialization phasevoid init() throws SensorHubException
SensorHubException
void init(ConfigType config) throws SensorHubException
setConfiguration(ModuleConfig)
and then init()
with no arguments.config
- SensorHubException
void updateConfig(ConfigType config) throws SensorHubException
config
- SensorHubException
void requestStart() throws SensorHubException
ModuleEvent.ModuleState.STARTING
SensorHubException
- if startup could not be initiatedvoid start() throws SensorHubException
SensorHubException
void requestStop() throws SensorHubException
ModuleEvent.ModuleState.STOPPING
SensorHubException
- if shutdown could not be initiatedvoid stop() throws SensorHubException
SensorHubException
void saveState(IModuleStateManager saver) throws SensorHubException
saver
- SensorHubException
void loadState(IModuleStateManager loader) throws SensorHubException
loader
- SensorHubException
void cleanup() throws SensorHubException
SensorHubException
void registerListener(IEventListener listener)
registerListener
in interface IEventProducer
listener
- void unregisterListener(IEventListener listener)
unregisterListener
in interface IEventProducer
listener
-