SK.gnome.dwarf.sample
Class QuoteHandler

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.thread.Handler
              extended bySK.gnome.dwarf.tcpip.TCPHandler
                  extended bySK.gnome.dwarf.sample.QuoteHandler
All Implemented Interfaces:
Reportable, java.lang.Runnable, Service, Stoppable

public class QuoteHandler
extends TCPHandler
implements Reportable

Handles the Quote of the Day Service (RFC 865) protocol.


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
QuoteHandler(java.lang.String name)
          Creates a new QuoteHandler.
 
Method Summary
protected  void handle(java.net.Socket socket)
          Handles the client connection.
 void init(Server parent)
          Initializes the service.
 java.lang.String report()
          Returns the service report.
 
Methods inherited from class SK.gnome.dwarf.tcpip.TCPHandler
handle
 
Methods inherited from class SK.gnome.dwarf.thread.Handler
enableThread, loop, start
 
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

QuoteHandler

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

Method Detail

init

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

It forces the parent server to be an instance of the QuoteServer class.

Since we need to call the server's QuoteServer.getQuote() method to obtain the quote strings, the initialization process must interrupt if the parent server is not an instance of the QuoteServer class. In order to do it we throw a IllegalServiceClassException to indicate the incompatible container type.

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

handle

protected void handle(java.net.Socket socket)
Handles the client connection.

This method does the actual Quote of the Day protocol handling.

The quote string is sent to the client via the socket output stream, followed by the CRLF character sequence. The quote string is obtained from the QuoteServer via its QuoteServer.getQuote() method.

Specified by:
handle in class TCPHandler

report

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

It returns the string representation of a socket beeing currently handled, or a string with single underscore character, if no socket is handled currently. If the handler is stopped at this time, it returns the "x" string instead.

Specified by:
report in interface Reportable
Returns:
current service state in a human-readable format


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