Package me.legrange.service
Class Service<Conf>
java.lang.Object
me.legrange.service.Service<Conf>
- Type Parameters:
Conf- The type of the configuration class for this service.
- Author:
- gideon
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <C extends Component>
CgetComponent(Class<C> clazz) Get the running component for the given component class.protected ConfReturn the service configuration.final booleanstatic voidprotected voidonStop()Stop the service.final <C extends Component>
CrequireComponent(Class<C> clazz) final voidsleep(int seconds) protected abstract voidstart()Start the service.final voidfinal voidstop()voidSubmit a task for running to the thread pool.
-
Constructor Details
-
Service
public Service()
-
-
Method Details
-
main
-
start
- Throws:
ServiceException
-
stop
- Throws:
ServiceException
-
getComponent
Get the running component for the given component class.- Type Parameters:
C- The type of the component- Parameters:
clazz- The class representing the component- Returns:
- The component
- Throws:
ComponentNotFoundException- Thrown if the component requested cannot be found
-
requireComponent
- Throws:
ServiceException
-
isRunning
public final boolean isRunning() -
start
Start the service. This needs to be implemented by the implementation subclass to get work done.- Throws:
ServiceException- Thrown if the service cannot be started
-
onStop
Stop the service. This can be implemented by the implementation subclass to release resources, do cleanup or accomplish other shut down tasks.- Throws:
ServiceException- Thrown if there is a problem stopping the service
-
getConfig
Return the service configuration.- Returns:
- The configuration object
-
submit
Submit a task for running to the thread pool.- Parameters:
task- The task to run.
-
sleep
public final void sleep(int seconds)
-