Package me.legrange.service
Class Component<S extends Service,C>
- java.lang.Object
-
- me.legrange.service.Component<S,C>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <C extends Component>
CgetComponent(Class<C> clazz)abstract StringgetName()Get the name of the component.protected <C extends Component>
CrequireComponent(Class<C> clazz)booleanrequiresConfig()Call to determine if the component requires configuration.protected Sservice()Access the service that owns this component.abstract voidstart(C config)Start the component.voidstop()Stop the component.
-
-
-
Constructor Detail
-
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 Detail
-
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 ComponentExceptionStop 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
-
-