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>

public interface IModule<T extends ModuleConfig> extends IModuleBase<T>, IEventProducer

Generic interface for all modules in the system.

Since:
Nov 12, 2010
  • Field Details

  • Method Details

    • setParentHub

      void 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. 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

      void setConfiguration(T config)
      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

      boolean waitForState(ModuleEvent.ModuleState state, long timeout) throws SensorHubException
      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 for
      timeout - 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

      void init() throws SensorHubException
      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 either ModuleEvent.ModuleState.INITIALIZING or ModuleEvent.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 with getCurrentError()
    • updateConfig

      void updateConfig(T config) throws SensorHubException
      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

      void start() throws SensorHubException
      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 either ModuleEvent.ModuleState.STARTING or ModuleEvent.ModuleState.STARTED.
      Module should be in ModuleEvent.ModuleState.INITIALIZED state before calling this method.
      Specified by:
      start in interface IModuleBase<T extends ModuleConfig>
      Throws:
      SensorHubException - if an error occurs during synchronous execution. If an error occurs asynchronously, it can be retrieved with getCurrentError()
    • stop

      void stop() throws SensorHubException
      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 either ModuleEvent.ModuleState.STOPPING or ModuleEvent.ModuleState.STOPPED.
      Specified by:
      stop in interface IModuleBase<T extends ModuleConfig>
      Throws:
      SensorHubException - if an error occurs during synchronous execution. If an error occurs asynchronously, it can be retrieved with getCurrentError()
    • saveState

      void saveState(IModuleStateManager saver) throws SensorHubException
      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

      void loadState(IModuleStateManager loader) throws SensorHubException
      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

      void cleanup() throws SensorHubException
      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

      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.
      Specified by:
      registerListener in interface IEventProducer
      Parameters:
      listener -
    • unregisterListener

      void unregisterListener(IEventListener listener)
      Unregisters a listener and thus stop receiving events generayed by this module
      Specified by:
      unregisterListener in interface IEventProducer
      Parameters:
      listener -