Package org.sensorhub.api.module
Interface IModule<T extends ModuleConfig>
- Type Parameters:
T
- Type of module config
- All Superinterfaces:
IEventProducer
,IModuleBase<T>
- All Known Subinterfaces:
IClientModule<ConfigType>
,ICommNetwork<ConfigType>
,ICommProvider<ConfigType>
,IDataProducerModule<ConfigType>
,IHttpServer<T>
,IObsSystemDatabaseModule<ConfigType>
,IProcessModule<ConfigType>
,ISensorModule<ConfigType>
,IServiceModule<ConfigType>
Generic interface for all modules in the system.
- Since:
- Nov 12, 2010
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Cleans up all ressources used by the module when deleted All persistent resources created by the module should be cleaned when this is calledHelper method to get the module's descriptionHelper method to get the module's local IDorg.slf4j.Logger
void
init()
Requests the module to initialize with the current configuration.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.INITIALIZING
orModuleEvent.ModuleState.INITIALIZED
.
A configuration must be set before calling this method.boolean
Checks if module is initializedboolean
Checks if module is startedvoid
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
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
(T config) Sets the parent sensor hub and module configurationvoid
setParentHub
(ISensorHub hub) Sets the parent hub that is used to access hub-wise functionality.
This is automatically called once when the module is loaded with the ModuleRegistry associated to a sensor hub.void
start()
Requests the module to start.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.STARTING
orModuleEvent.ModuleState.STARTED
.
Module should be inModuleEvent.ModuleState.INITIALIZED
state before calling this method.void
stop()
Requests the module to stop.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.STOPPING
orModuleEvent.ModuleState.STOPPED
.void
unregisterListener
(IEventListener listener) Unregisters a listener and thus stop receiving events generayed by this modulevoid
updateConfig
(T 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.Methods inherited from interface org.sensorhub.api.module.IModuleBase
getConfiguration, getName, init
-
Field Details
-
CANNOT_LOAD_MSG
- See Also:
-
CANNOT_INIT_MSG
- See Also:
-
CANNOT_START_MSG
- See Also:
-
CANNOT_STOP_MSG
- See Also:
-
CANNOT_UPDATE_MSG
- See Also:
-
-
Method Details
-
setParentHub
Sets the parent hub that is used to access hub-wise functionality.
This is automatically called once when the module is loaded with the ModuleRegistry associated to a sensor hub. When instantiating the module manually, it must be called before any other method.- Parameters:
hub
-
-
getParentHub
ISensorHub getParentHub()- Returns:
- parent hub that loaded this module
-
setConfiguration
Sets the parent sensor hub and module configuration- Parameters:
config
-
-
getDescription
String getDescription()Helper method to get the module's description- Returns:
- description string
-
getLocalID
String getLocalID()Helper method to get the module's local ID- Returns:
- id string
-
isInitialized
boolean isInitialized()Checks if module is initialized- Returns:
- true if module is initialized, false otherwise
-
isStarted
boolean isStarted()Checks if module is started- Returns:
- true if module is started, false otherwise
-
getCurrentState
ModuleEvent.ModuleState getCurrentState()- Returns:
- the current state of the module
-
waitForState
Waits until the module reaches the specified state or times out.
This method will return immediately if the state has already been reached.- Parameters:
state
- state to wait fortimeout
- maximum time to wait in milliseconds or 0 to wait forever- Returns:
- true if module state has been reached, false in case of timeout or error
- Throws:
SensorHubException
- if an error occurs before the desired state is reached
-
getStatusMessage
String getStatusMessage()- Returns:
- the current status message
-
getCurrentError
Throwable getCurrentError()- Returns:
- the last error that occured executing the module
-
getLogger
org.slf4j.Logger getLogger()- Returns:
- the logger associated to this module
-
init
Requests the module to initialize with the current configuration.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.INITIALIZING
orModuleEvent.ModuleState.INITIALIZED
.
A configuration must be set before calling this method.- Throws:
SensorHubException
- if an error occurs during synchronous execution. If an error occurs asynchronously, it can be retrieved withgetCurrentError()
-
updateConfig
Updates the module's configuration dynamically.
The module must honor this new configuration unless an error is detected. It is the responsability of the module to initiate a restart if the new configuration requires it.- Parameters:
config
-- Throws:
SensorHubException
-
start
Requests the module to start.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.STARTING
orModuleEvent.ModuleState.STARTED
.
Module should be inModuleEvent.ModuleState.INITIALIZED
state before calling this method.- Specified by:
start
in interfaceIModuleBase<T extends ModuleConfig>
- Throws:
SensorHubException
- if an error occurs during synchronous execution. If an error occurs asynchronously, it can be retrieved withgetCurrentError()
-
stop
Requests the module to stop.
Implementations of this method can be synchronous or asynchronous, but when this method returns without error, the module state is guaranteed to be eitherModuleEvent.ModuleState.STOPPING
orModuleEvent.ModuleState.STOPPED
.- Specified by:
stop
in interfaceIModuleBase<T extends ModuleConfig>
- Throws:
SensorHubException
- if an error occurs during synchronous execution. If an error occurs asynchronously, it can be retrieved withgetCurrentError()
-
saveState
Saves the state of this module.
Implementations of this method must block until the module state is successfully saved or send an exception.- Parameters:
saver
-- Throws:
SensorHubException
-
loadState
Restores the state of this module
Implementations of this method must block until the module state is successfully loaded or send an exception.- Parameters:
loader
-- Throws:
SensorHubException
-
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- Throws:
SensorHubException
-
registerListener
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.- Specified by:
registerListener
in interfaceIEventProducer
- Parameters:
listener
-
-
unregisterListener
Unregisters a listener and thus stop receiving events generayed by this module- Specified by:
unregisterListener
in interfaceIEventProducer
- Parameters:
listener
-
-