|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This iterface defines the API for managing and monitoring service life-cycle. A kernel can be constructed with the following code:
Services can be registered, unregistered, started and stopped. The lifecycle model is loosly based on the J2ee Management Specification (JSR 77). All lifecycle transitions are broadcasted via a ServiceMonitor. Each kernel must have a name that is unique with in the KernelFactory (there should only be one KernelFactory per VM but class loader tricks can result in several KernelFactory) This class is loosely based on the J2ee management MEJB and JMX MBeanServer interfaces.Kernel kernel = KernelFactory.newInstance().createKernel(name);
Method Summary | |
void |
addKernelMonitor(KernelMonitor kernelMonitor)
Adds a kernel monitor. |
void |
addServiceMonitor(ServiceMonitor serviceMonitor)
Adds a service monitor for all services registered with the kernel. |
void |
addServiceMonitor(ServiceMonitor serviceMonitor,
ServiceName serviceName)
Adds a service monitor for a specific service. |
void |
destroy()
Destroys this kernel. |
java.lang.ClassLoader |
getClassLoaderFor(ServiceName serviceName)
Gets the class loader associated with the specifed service. |
java.lang.String |
getKernelName()
Gets the unique name of this kernel within the KernelFactory. |
java.lang.Object |
getService(java.lang.Class type)
Gets the first running service registered with the kernel that is an instance of the specified type. |
java.lang.Object |
getService(ServiceName serviceName)
Gets the service registered under the specified name. |
java.util.List |
getServiceFactories(java.lang.Class type)
Gets the all of the service factories registered with the kernel that create an instances of the specified type. |
ServiceFactory |
getServiceFactory(java.lang.Class type)
Gets the first service factory registered with the kernel that creates an instance of the specified type. |
ServiceFactory |
getServiceFactory(ServiceName serviceName)
Gets the service factory registered under the specified name. |
java.util.List |
getServices(java.lang.Class type)
Gets the all of running service registered with the kernel that are an instances of the specified type. |
long |
getServiceStartTime(ServiceName serviceName)
Gets the time the specified service entered the RUNNING state since the epoch (January 1, 1970, 00:00:00) in milliseconds. |
ServiceState |
getServiceState(ServiceName serviceName)
Gets the ServiceState of the specified service. |
boolean |
isRegistered(ServiceName serviceName)
Determines if there is a service registered under the specified name. |
boolean |
isRunning()
Gets the running status of the kernel. |
boolean |
isServiceEnabled(ServiceName serviceName)
Determines if the service can be instantiated in a kernel. |
void |
registerService(ServiceName serviceName,
ServiceFactory serviceFactory,
java.lang.ClassLoader classLoader)
Registers a service with this kernel. |
void |
removeKernelMonitor(KernelMonitor kernelMonitor)
Removes a kernel monitor. |
void |
removeServiceMonitor(ServiceMonitor serviceMonitor)
Removes a service monitor. |
void |
setServiceEnabled(ServiceName serviceName,
boolean enabled)
Sets the enabled status of a service. |
void |
startService(ServiceName serviceName)
Immediately starts the service using the SYNCHRONOUS start strategy. |
void |
startService(ServiceName serviceName,
StartStrategy startStrategy)
Immediately starts the service using the specified start strategy. |
void |
startServiceRecursive(ServiceName serviceName)
Immediately starts the service, and if the start ultimately completes successfully, all services owned by the specified service, all services that are owned by those services, and so on, will be started using the startServiceRecursive(ServiceName) method. |
void |
startServiceRecursive(ServiceName serviceName,
StartStrategy startStrategy)
Immediately starts the service, and if the start ultimately completes successfully, all services owned by the specified service, all services that are owned by those services, and so on, will be started using the startServiceRecursive(ServiceName, StartStrategy) method. |
void |
stopService(ServiceName serviceName)
Immediately stops the service using the SYNCHRONOUS stop strategy. |
void |
stopService(ServiceName serviceName,
StopStrategy stopStrategy)
Immediately stops the service using the specified stop strategy. |
void |
unregisterService(ServiceName serviceName)
Unregisters a service from this kernel. |
void |
unregisterService(ServiceName serviceName,
StopStrategy stopStrategy)
Unregisters a service from this kernel. |
void |
waitForDestruction()
Waits for the kernel to be destroyed. |
Method Detail |
public void destroy()
public void waitForDestruction()
public boolean isRunning()
public java.lang.String getKernelName()
public void registerService(ServiceName serviceName, ServiceFactory serviceFactory, java.lang.ClassLoader classLoader) throws ServiceAlreadyExistsException, ServiceRegistrationException
serviceName
- the unique name of the service in the kernelserviceFactory
- the factory used to create the serviceclassLoader
- the class loader to use for this service
ServiceAlreadyExistsException
- if service is already registered with the specified name
ServiceRegistrationException
- if the service is not restartable and an error occured while starting the servicepublic void unregisterService(ServiceName serviceName) throws ServiceNotFoundException, ServiceRegistrationException
serviceName
- the unique name of the service in the kernel
ServiceNotFoundException
- if there is no service registered under the specified name
ServiceRegistrationException
- if the service could not be stoppedpublic void unregisterService(ServiceName serviceName, StopStrategy stopStrategy) throws ServiceNotFoundException, ServiceRegistrationException
serviceName
- the unique name of the service in the kernelstopStrategy
- the strategy that determines how unsatisfied conditions are handled
ServiceNotFoundException
- if there is no service registered under the specified name
ServiceRegistrationException
- if the service could not be stoppedpublic boolean isRegistered(ServiceName serviceName)
serviceName
- the unique name of the service
public ServiceState getServiceState(ServiceName serviceName) throws ServiceNotFoundException
serviceName
- the unique name of the service in the kernel
ServiceNotFoundException
- if there is no service registered under the specified namepublic long getServiceStartTime(ServiceName serviceName) throws ServiceNotFoundException
serviceName
- the unique name of the service in the kernel
ServiceNotFoundException
- if there is no service registered under the specified namepublic void startService(ServiceName serviceName) throws ServiceNotFoundException, IllegalServiceStateException, UnsatisfiedConditionsException, java.lang.Exception
serviceName
- the unique name of the service to start
ServiceNotFoundException
- if there is no service registered under the specified name
IllegalServiceStateException
- if the service is restartable and is in the STOPPING state or if the
service is disabled
UnsatisfiedConditionsException
- if some of the start conditions can not be immediately satisfied
java.lang.Exception
- if service construction threw an Exceptionpublic void startService(ServiceName serviceName, StartStrategy startStrategy) throws ServiceNotFoundException, IllegalServiceStateException, UnsatisfiedConditionsException, java.lang.Exception
serviceName
- the unique name of the service to startstartStrategy
- the strategy that determines how unsatisfied conditions and construction exceptions are handled
ServiceNotFoundException
- if there is no service registered under the specified name
IllegalServiceStateException
- if the service is restartable and is in the STOPPING state or if the
service is disabled
UnsatisfiedConditionsException
- if some of the start conditions can not be immediately satisfied
java.lang.Exception
- if service construction threw an Exceptionpublic void startServiceRecursive(ServiceName serviceName) throws ServiceNotFoundException, IllegalServiceStateException, UnsatisfiedConditionsException, java.lang.Exception
serviceName
- the unique name of the service to start recursively
ServiceNotFoundException
- if there is no service registered under the specified name
IllegalServiceStateException
- if the service is restartable and is in the STOPPING state or if the
service is disabled
UnsatisfiedConditionsException
- if some of the start conditions can not be immediately satisfied
java.lang.Exception
- if service construction threw an Exceptionpublic void startServiceRecursive(ServiceName serviceName, StartStrategy startStrategy) throws ServiceNotFoundException, IllegalServiceStateException, UnsatisfiedConditionsException, java.lang.Exception
serviceName
- the unique name of the service to start recursivelystartStrategy
- the strategy that determines how unsatisfied conditions and construction exceptions are handled
ServiceNotFoundException
- if there is no service registered under the specified name
IllegalServiceStateException
- if the service is restartable and is in the STOPPING state or if the
service is disabled
UnsatisfiedConditionsException
- if some of the start conditions can not be immediately satisfied
java.lang.Exception
- if service construction threw an Exceptionpublic void stopService(ServiceName serviceName) throws ServiceNotFoundException, UnsatisfiedConditionsException
serviceName
- the unique name of the service to stop
ServiceNotFoundException
- if there is no service registered under the specified name
UnsatisfiedConditionsException
public void stopService(ServiceName serviceName, StopStrategy stopStrategy) throws ServiceNotFoundException, UnsatisfiedConditionsException
serviceName
- the unique name of the service to stopstopStrategy
- the strategy that determines how unsatisfied conditions are handled
ServiceNotFoundException
- if there is no service registered under the specified name
UnsatisfiedConditionsException
public boolean isServiceEnabled(ServiceName serviceName) throws ServiceNotFoundException
kernel.getServiceFactory(serviceName).isEnabled();
serviceName
- the unique name of the service
ServiceNotFoundException
- if there is no service registered under the specified namepublic void setServiceEnabled(ServiceName serviceName, boolean enabled) throws ServiceNotFoundException
kernel.getServiceFactory(serviceName).setEnabled(enabled);
serviceName
- the unique name of the serviceenabled
- the new enabled state of this factory
ServiceNotFoundException
- if there is no service registered under the specified namepublic java.lang.Object getService(ServiceName serviceName) throws ServiceNotFoundException, java.lang.IllegalArgumentException
serviceName
- the unique name of the service
ServiceNotFoundException
- if there is no service registered under the specified name
java.lang.IllegalArgumentException
- if the service is not in the RUNNING, or STARTING statepublic java.lang.Object getService(java.lang.Class type)
type
- the of the desired service
public java.util.List getServices(java.lang.Class type)
type
- the of the desired service
public ServiceFactory getServiceFactory(ServiceName serviceName) throws ServiceNotFoundException
serviceName
- the unique name of the service
ServiceNotFoundException
- if there is no service registered under the specified namepublic ServiceFactory getServiceFactory(java.lang.Class type)
type
- the of the desired service
public java.util.List getServiceFactories(java.lang.Class type)
type
- the of the desired service
public java.lang.ClassLoader getClassLoaderFor(ServiceName serviceName) throws ServiceNotFoundException
serviceName
- the unique name of the service
ServiceNotFoundException
- if there is no service registered under the specified namepublic void addKernelMonitor(KernelMonitor kernelMonitor)
kernelMonitor
- the kernel monitor to addpublic void removeKernelMonitor(KernelMonitor kernelMonitor)
kernelMonitor
- the kernel monitor to removepublic void addServiceMonitor(ServiceMonitor serviceMonitor)
Note: the order in which service monitors are notified is not specified.addServiceMonitor(serviceMonitor, null);
serviceMonitor
- the service monitor to addpublic void addServiceMonitor(ServiceMonitor serviceMonitor, ServiceName serviceName)
serviceMonitor
- the service monitor to addserviceName
- the unique name of the service to monitor or null to monitor all servicespublic void removeServiceMonitor(ServiceMonitor serviceMonitor)
serviceMonitor
- the service monitor to remove
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |