org.exolab.core.service
Class ServiceGroup

java.lang.Object
  extended byorg.exolab.core.service.ServiceGroup
Direct Known Subclasses:
ServiceManager

public class ServiceGroup
extends java.lang.Object

ServiceGroup is responsible for managing a collection of Serviceable objects.
All serviceable objects are named and no two sevices can have the same name.

Version:
$Revision: 1.2 $ $Date: 2003/06/09 06:28:41 $
Author:
Jim Alateras
See Also:
BasicService, Service, Serviceable

Constructor Summary
ServiceGroup()
          Create a new service group
 
Method Summary
 void add(java.lang.String name, Serviceable service)
          Add the named service to the collection of managed services.
 Serviceable getServiceByName(java.lang.String name)
          Return the service specified by name, or null if one does not exist
 java.util.Iterator getServiceNames()
          Return an enumeration of the registered service names
 void remove(Serviceable service)
          Remove the specified service from the ServiceGroup.
 void remove(java.lang.String name)
          Remove the named service from the ServiceGroup.
 void removeAll()
          Remove all registered services.
 void startAll()
          Start all the services in their registered order.
 void stopAll()
          Stop all the services in their reverse registered order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceGroup

public ServiceGroup()
Create a new service group

Method Detail

add

public void add(java.lang.String name,
                Serviceable service)
         throws ServiceAlreadyExistsException,
                ServiceManagerException
Add the named service to the collection of managed services. The service must be in the STOPPED state before it can be added to the manager.

The startAll() method will start the services in the order that they were added to the ServiceGroup. Therefore if one service is dependent on another ensure that they are added in the correct order. Similarly stopAll() will stop the services in the reverse order to which they were started.

Parameters:
name - the name of the sevice
service - the service to add
Throws:
ServiceAlreadyExistsException - if a service exists with the same name
ServiceManagerException - if the service is not in the stopped state

remove

public void remove(java.lang.String name)
            throws ServiceDoesNotExistException,
                   ServiceManagerException
Remove the named service from the ServiceGroup. The service must be in the 'stopped' state before it can be removed.

Parameters:
name - the name of the service to remove
Throws:
ServiceDoesNotExistException - if the named service doesn't exist
ServiceManagerException - if a client tries to remove a service that is not stopped.

remove

public void remove(Serviceable service)
            throws ServiceDoesNotExistException,
                   ServiceManagerException
Remove the specified service from the ServiceGroup. It delegates the responsiblity to remove(String) method.

Parameters:
service - the service to remove
Throws:
ServiceDoesNotExistException - if the service isn't registered
ServiceManagerException - if a client tries to remove a service that is not stopped.

getServiceNames

public java.util.Iterator getServiceNames()
Return an enumeration of the registered service names

Returns:
an enumeration of service names

getServiceByName

public Serviceable getServiceByName(java.lang.String name)
Return the service specified by name, or null if one does not exist

Parameters:
name - the service name
Returns:
the service, or null if non-existent

startAll

public void startAll()
              throws ServiceManagerException
Start all the services in their registered order. If a service is already running then it is ignored. If one or more services could not be started then the ServiceManagerException is raised. The exception will only indicate the first service that failed to start.

Throws:
ServiceManagerException

stopAll

public void stopAll()
Stop all the services in their reverse registered order. If a sevice is already stopped then it is ignored. If one or more services could not be stopped an appropriate error will be logged


removeAll

public void removeAll()
Remove all registered services. All services are stopped before removal



Copyright © 1999-2005 The Exolab Group. All Rights Reserved.