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 TypeMethodDescriptionvoidcleanup()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.Loggervoidinit()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.INITIALIZINGorModuleEvent.ModuleState.INITIALIZED.
A configuration must be set before calling this method.booleanChecks if module is initializedbooleanChecks if module is startedvoidloadState(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.voidregisterListener(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.voidsaveState(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.voidsetConfiguration(T config) Sets the parent sensor hub and module configurationvoidsetParentHub(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.voidstart()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.STARTINGorModuleEvent.ModuleState.STARTED.
Module should be inModuleEvent.ModuleState.INITIALIZEDstate before calling this method.voidstop()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.STOPPINGorModuleEvent.ModuleState.STOPPED.voidunregisterListener(IEventListener listener) Unregisters a listener and thus stop receiving events generayed by this modulevoidupdateConfig(T config) Updates the module's configuration dynamically.
The module must honor this new configuration unless an error is detected.booleanwaitForState(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.INITIALIZINGorModuleEvent.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.STARTINGorModuleEvent.ModuleState.STARTED.
Module should be inModuleEvent.ModuleState.INITIALIZEDstate before calling this method.- Specified by:
startin 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.STOPPINGorModuleEvent.ModuleState.STOPPED.- Specified by:
stopin 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:
registerListenerin interfaceIEventProducer- Parameters:
listener-
-
unregisterListener
Unregisters a listener and thus stop receiving events generayed by this module- Specified by:
unregisterListenerin interfaceIEventProducer- Parameters:
listener-
-