SK.gnome.dwarf.thread
Class Handler

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.thread.Handler
All Implemented Interfaces:
java.lang.Runnable, Service, Stoppable
Direct Known Subclasses:
NioTCPHandler, TCPHandler, UDPHandler

public abstract class Handler
extends ThreadService
implements Stoppable

Abstract service for handling the client requests.

This class processes the client requests. It works in cooperation with the MultiThreadServer.

In order to develop a real handler the abstract handle(Object) method must be overriden.


Field Summary
 
Fields inherited from class SK.gnome.dwarf.thread.ThreadService
daemon, thread
 
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
Handler(java.lang.String name)
          Creates a new Handler.
 
Method Summary
protected  boolean enableThread()
          Enables or disables the service thread.
protected abstract  void handle(java.lang.Object obj)
          Handles the client request.
 void init(Server parent)
          Initializes the service.
protected  void loop()
          Performs the handling operation.
 void start()
          Starts the service.
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
finish, run, setDaemon, shutdown, stop
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, 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
 

Constructor Detail

Handler

public Handler(java.lang.String name)
Creates a new Handler.

Method Detail

init

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

It requires that the parent server is an instance of MultiThreadServer class.

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

start

public void start()
           throws ServiceException
Description copied from class: ThreadService
Starts the service.

If the ThreadService.enableThread() method returns true, it creates and starts a new thread. The thread's name corresponds to the service name and the thread's Runnable target is the service itself since it implements the Runnable interface. The reference to the thread object is stored in the ThreadService.thread field.

It throws a IllegalStateException if the ThreadService.thread field is not null and its isAlive() method returns true.

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

enableThread

protected boolean enableThread()
Enables or disables the service thread.

This method always returns true, so the new thread is always started.

Overrides:
enableThread in class ThreadService
Returns:
true if the thread is enabled

loop

protected void loop()
Performs the handling operation.

First calls the parent server's MultiThreadServer.dequeue(int) method and then passes the obtained request object to the handle(Object) method for further processing. After that handler returns the obtained request to the server via its MultiThreadServer.finish(Object) method.

Overrides:
loop in class ThreadService

handle

protected abstract void handle(java.lang.Object obj)
Handles the client request.

The abstract method for processing the client requests. It must be overriden in order to implement a real handler. The client request is generally represented by the obj argument. Since it is an instance of the basic java.lang.Object class, it can represent an arbitrary client request.



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