org.apache.jdo.impl.fostore
Class RequestHandler

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.RequestHandler
Direct Known Subclasses:
ActivateClassHandler, BeginTxHandler, CommitHandler, CreateOIDHandler, DeleteHandler, DumpHandler, FetchHandler, GetClassHandler, GetExtentHandler, GetInstancesHandler, InsertHandler, LoginHandler, RollbackHandler

abstract class RequestHandler
extends java.lang.Object

This dispatches each request received by the store to the appropriate request-type-specific request handler. It is very dependent on the 'message full of data' means of communicating between client and store.

Author:
Dave Bristor

Nested Class Summary
(package private) static interface RequestHandler.HandlerFactory
          Means by which subclasses are created.
 
Field Summary
protected  FOStoreServerConnection con
          Connection on which the Request arrived.
protected  int length
          Length of the data in the Request.
(package private) static org.apache.commons.logging.Log logger
          Logger
private static I18NHelper msg
          I18N support.
protected  Reply reply
          Subclasses use this Reply instance to send data back to their corresponding client-side request.
 
Constructor Summary
protected RequestHandler(Reply reply, int length, FOStoreServerConnection con)
           
 
Method Summary
protected  boolean getOkToFinish()
          The RollbackHandler should override this and return false, so that finishers are not run when we are rolling back.
private static void giveUp(java.lang.Throwable ex)
          Invoke this when all attempts at communicating errors to the client have failed.
(package private) abstract  RequestFinisher handleRequest()
          Subclasses implement this to take care of individiual requests.
(package private) static void handleRequests(FOStoreServerConnection con)
          Handles all requests that can be read at this time from the given connection.
protected  void setOkToCommit(boolean okToCommit)
          The CommitHandler should override this and save the given value, then use it to determine whether or not to commit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reply

protected final Reply reply
Subclasses use this Reply instance to send data back to their corresponding client-side request.


length

protected final int length
Length of the data in the Request.


con

protected final FOStoreServerConnection con
Connection on which the Request arrived.


msg

private static final I18NHelper msg
I18N support.


logger

static final org.apache.commons.logging.Log logger
Logger

Constructor Detail

RequestHandler

protected RequestHandler(Reply reply,
                         int length,
                         FOStoreServerConnection con)
Parameters:
reply - Reply to which request handler should write all reply information.
length - Number of bytes in the connection's input that are for this request; subclasses must read all bytes so that other requests can work.
con - Connection from which request handler reads the request data.
Method Detail

getOkToFinish

protected boolean getOkToFinish()
The RollbackHandler should override this and return false, so that finishers are not run when we are rolling back.


setOkToCommit

protected void setOkToCommit(boolean okToCommit)
The CommitHandler should override this and save the given value, then use it to determine whether or not to commit.


handleRequests

static void handleRequests(FOStoreServerConnection con)
Handles all requests that can be read at this time from the given connection. Reads the number of requests, then reads each one and, in turn, invokes the handleRequest operation on each.

The data it generates for the client is documented; see ReplyHandler.processReplies(java.io.DataInput, org.apache.jdo.impl.fostore.Message).

If after all requests are thusly handled, none have indicated that the second round of handling, called finishing, is not to be done, then performs this second round. The finishers that are invoked are precisely those which were returned from each request's handleRequest invocation, and the finishers have their finish() methods invoked in the same order in which the requests were originally invoked.

Finally, writes the number of replies (at the beginning of the reply data, in a spot that was set aside for this purpose), and sends replies back to the client.

This method is very paranoid about error checking, which clutters it up some, but is necessary to ensure that the server keeps running.


giveUp

private static void giveUp(java.lang.Throwable ex)
Invoke this when all attempts at communicating errors to the client have failed. Hope that someone is watching the console!


handleRequest

abstract RequestFinisher handleRequest()
                                throws java.io.IOException,
                                       FOStoreDatabaseException
Subclasses implement this to take care of individiual requests.

Returns:
A RequestFinisher or null. If null, then no further work is required on behalf of this request. If a RequestFinisher is returned, then it is added to a list, and after all requests have been processed, the finishers in the list have their finish() method invoked on them. Finishers are invoked in the same order as the requests were.
Throws:
java.io.IOException
FOStoreDatabaseException