SK.gnome.dwarf
Class GenericServer

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.GenericServer
All Implemented Interfaces:
Reportable, Server, Service
Direct Known Subclasses:
LogServer, MainServer, ThreadServer

public class GenericServer
extends GenericService
implements Server, Reportable

Provides a generic Server implementation.

It extends the base GenericService class by adding functionality for storing and manipulating of internal list of contained services.

Implementation note:
The contained services are stored internally in a java.util.List collection, therefore the getService(String) method searches for the services by iterating over the list elements.

Thread-safety note:
All methods dealing with the contained services are thread-safe and the list returned by the getServices() method is synchronized. However, if you need to iterate over the contained services, you must synchronize on the returned List object:

 List services = getServices();
 synchronized (services)
 { Iterator it = services.iterator();
   while (it.hasNext())
   { Service s = (Service)it.next();
      ...                             // do something with the given service
   }
 }
 


Field Summary
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
GenericServer(java.lang.String name)
          Constructs a new GenericServer.
 
Method Summary
 void addService(int index, Service service)
          Inserts a service to the server.
 void addService(Service service)
          Adds a service to the server.
protected  Authenticator getAuthenticator()
          Returns an authentication service.
protected  Logger getLogger()
          Returns a logging service.
 Parameters getParameters()
          Returns the service parameters.
 Service getService(java.lang.String name)
          Returns a service by its name.
 java.util.List getServices()
          Returns all services contained by the server.
 java.util.List getServices(java.lang.Class serviceClass)
          Returns the list of contained services which are instances of the given class.
 void init(Server parent)
          Initializes the server.
 Service removeService(java.lang.String name)
          Removes a service from the server.
 java.lang.String report()
          Returns the service report.
 void shutdown()
          Shuts down the server.
 void start()
          Starts the server.
 void stop()
          Stops the server.
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getName, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface SK.gnome.dwarf.Service
getFullName, getName, getState, log, log, login, logout
 

Constructor Detail

GenericServer

public GenericServer(java.lang.String name)
Constructs a new GenericServer.

Method Detail

addService

public void addService(Service service)
                throws ServiceException
Description copied from interface: Server
Adds a service to the server.

The service is added to the end of the service list.

Specified by:
addService in interface Server
Parameters:
service - the service being added to the server
Throws:
ServiceException - if the process fails for any other reason

getService

public Service getService(java.lang.String name)
Description copied from interface: Server
Returns a service by its name.

It returns null if the name argument is null or there is no service contained by the server with the given name.

The method must accept also a full service name with each name component separated by the slash character. In this case, it should traverse the service object subtree and find the nested service at any level.

Specified by:
getService in interface Server
Parameters:
name - the nested service name
Returns:
the service or null if there is no service with the given name

getServices

public java.util.List getServices()
Description copied from interface: Server
Returns all services contained by the server.

An empty list is returned if there are no services contained by the server, otherwise an unmodifiable list of contained services is returned.

The method is not traversing. If a service contained by the server is also a server, i.e. it contains another services, these nested services are not included in the resulting list.

Specified by:
getServices in interface Server
Returns:
the unmodifiable list of services

removeService

public Service removeService(java.lang.String name)
Description copied from interface: Server
Removes a service from the server.

It returns null if the name argument is null or there is no service in the server with the given name, otherwise it returns a reference to the removed service.

The method is not traversing. If a service contained by the server is also a server, i.e. it contains another services, these nested services are not searched for the given service to remove.

Specified by:
removeService in interface Server
Parameters:
name - the nested service name
Returns:
the removed service or null if there is no service with the given name

getParameters

public Parameters getParameters()
Returns the service parameters.

Returns a service implementing the Parameters interface, directly contained by this server. If no such service exists, it calls the overriden method.

Specified by:
getParameters in interface Service
Overrides:
getParameters in class GenericService

init

public void init(Server parent)
          throws ServiceException
Initializes the server.

First initializes the superclass and then initializes all services contained by the server by calling their Service.init(Server) methods. Services will be initialized in the order they were added to the server. It is left to the developer to take care of the eventual service dependencies.

Specified by:
init in interface Service
Overrides:
init in class GenericService
Throws:
ServiceException

start

public void start()
           throws ServiceException
Starts the server.

First starts the superclass and then starts all services contained by the server by calling their Service.start() methods. Services will be started in the order they were added to the server. It is left to the developer to take care of the eventual service dependencies.

Specified by:
start in interface Service
Overrides:
start in class GenericService
Throws:
ServiceException

stop

public void stop()
          throws ServiceException
Stops the server.

First stops the superclass and then stops all services contained by the server by calling their Service.stop() methods. Services will be stopped in the reverse order they were added to the server. It is left to the developer to take care of the eventual service dependencies.

The service must implement the Stoppable interface in order to allow this method to make the desired state transition.

Specified by:
stop in interface Service
Overrides:
stop in class GenericService
Throws:
ServiceException

shutdown

public void shutdown()
Shuts down the server.

First shuts down the superclass and then shuts down all services contained by the server by calling their Service.shutdown() methoda. Services will be processed in the reverse order they were added to the server. It is left to the developer to take care of the eventual service dependencies.

Specified by:
shutdown in interface Service
Overrides:
shutdown in class GenericService

addService

public void addService(int index,
                       Service service)
                throws ServiceException
Inserts a service to the server.

The service is inserted at the specified position to the list of contained services. The addService(Service) method uses this method to add the given service to the end of the service list.

Parameters:
service - the service being added to the server
Throws:
java.lang.NullPointerException - if the argument is null
java.lang.IllegalArgumentException - if a service with the same name exists
ServiceException - if an error occured during the adding

getServices

public java.util.List getServices(java.lang.Class serviceClass)
Returns the list of contained services which are instances of the given class.

If there are no such services contained by the server, an empty list is returned.

This method creates and returns a new modifiable List each time it is called.

The method is not traversing. If a service contained by the server is also a Server, i.e. it contains another services, these nested services are not included in the result.

Returns:
the list of services which are instances of the given class

report

public java.lang.String report()
Returns the service report.

Returns the report of all contained services which implements the Reportable interface and are not instances of either the Server or the Parameters interface. The individual service reports are separated by the platform-default line separator.

Specified by:
report in interface Reportable
Returns:
the report of all contained services

getLogger

protected Logger getLogger()
Returns a logging service.

Returns a reference to directly contained service, which implements the Logger interface. If no such service exists, the result of the overriden getLogger() method is returned.

Overrides:
getLogger in class GenericService
Returns:
the logging service

getAuthenticator

protected Authenticator getAuthenticator()
Returns an authentication service.

Returns a reference to directly contained service, which implements the Authenticator interface. If no such service exists, the result of the overriden' getAuthenticator() method is returned.

Overrides:
getAuthenticator in class GenericService
Returns:
the authentication service


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.