Package me.legrange.service
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 componentC- Type of the configuration class
Extended by packaged service components to gain access to useful
functionality in the service.
- Author:
- gideon
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <C extends Component>
CgetComponent(Class<C> clazz) abstract StringgetName()Get the name of the component.protected final <C extends Component>
CrequireComponent(Class<C> clazz) booleanCall to determine if the component requires configuration.protected final Sservice()Access the service that owns this component.abstract voidStart the component.voidstop()Stop the component.
-
Constructor Details
-
Component
Create a component associated with the given service.- Parameters:
service- The service of which this component is a part of.
-
-
Method Details
-
start
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
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
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
Access the service that owns this component. Utility method to get access to functionality required by the component.- Returns:
- The service
-
getComponent
- Throws:
ComponentNotFoundException
-
requireComponent
- Throws:
ServiceException
-