Class Component<S extends Service,C>

java.lang.Object
me.legrange.service.Component<S,C>
Type Parameters:
S - Type of the service required by this component
C - Type of the configuration class

public abstract class Component<S extends Service,C> extends Object
Extended by packaged service components to gain access to useful functionality in the service.
Author:
gideon
  • Constructor Details

    • Component

      protected Component(S service)
      Create a component associated with the given service.
      Parameters:
      service - The service of which this component is a part of.
  • Method Details

    • start

      public abstract void start(C config) throws ComponentException
      Start the component. Implementations need to do anything here they need done before the component's functionality is available.
      Parameters:
      config - The component's configuration.
      Throws:
      ComponentException - Thrown if there is a problem starting the component
    • stop

      public void stop() throws ComponentException
      Stop the component. Implementations can override this to release resources, close connections or do other kinds of cleanup.
      Throws:
      ComponentException - Throw if there is a proble stopping the component
    • getName

      public abstract String getName()
      Get the name of the component. This is unique and is used to find the component's configuration in the service config.
      Returns:
      The component's name.
    • requiresConfig

      public boolean requiresConfig()
      Call to determine if the component requires configuration. By default this is true, but if a component does not require any configuration, it can be overriden to return false which will cause the system not to try to locate it's configuration.
    • service

      protected final S service()
      Access the service that owns this component. Utility method to get access to functionality required by the component.
      Returns:
      The service
    • getComponent

      public final <C extends Component> C getComponent(Class<C> clazz) throws ComponentNotFoundException
      Throws:
      ComponentNotFoundException
    • requireComponent

      protected final <C extends Component> C requireComponent(Class<C> clazz) throws ServiceException
      Throws:
      ServiceException