org.apache.jdo.impl.fostore
Class Message

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.Message

class Message
extends java.lang.Object

Represents a set of one or more requests that will be sent to the store.

Author:
Dave Bristor
See Also:
Request

Field Summary
private  java.util.HashSet clids
          Set of CLIDs associated with ActivateClass requests that are in this Message.
private  Connector connector
          Connector for which this message acts as a transport.
(package private) static org.apache.commons.logging.Log logger
          Logger
private static I18NHelper msg
          I18N support.
private  int numRequests
          Indicates the number of requests that have been written into this Message.
private  int numRequestStash
          Contains the position in the output of the numRequest stashed by initOutput.
private  FOStoreOutput out
          This contains the Message's actual data for the store.
private  java.util.HashMap requests
          Set of request objects that are in the process of carrying out their function; maps from a RequestId to Request.
private static int VERSION_NUMBER
          The version number of the current protocol.
 
Constructor Summary
(package private) Message()
           
(package private) Message(Connector connector)
          Constructor for Message.
 
Method Summary
(package private)  void addCLID(CLID clid)
          Add the given CLID to the set of CLIDs maintained by this Message.
private  void closeConnection(FOStoreClientConnection con)
          Close the connection to the store.
(package private)  boolean containsCLID(CLID clid)
          Returns true if the given CLID is in this Message's set of CLIDs.
 void dump()
          Dump the complete current contents of the message buffer.
private  void finishOutput()
          Finish the output buffer by updating the stash with number of requests.
(package private)  Connector getConnector()
           
 FOStoreOutput getOutput()
          Return the FOStoreOutput stream for requests to be inserted.
(package private)  Request getRequest(RequestId requestId)
          Provides the Request corresponding to the give requestId, removing it from the internal map of requests (i.e., subsequent getRequest invocations for the same requestId will return null).
(package private)  boolean hasRequests()
          Returns true if this message has requests for the store.
private  void initOutput()
          Initialize the output buffer with version number and a stash for number of requests.
(package private)  void processInStore(FOStoreClientConnection con, boolean okToReleaseConnection)
          Write this message to the given connection, and read replies from that connection, processing replies as they are read.
(package private)  void putRequest(RequestId requestId, Request request)
          Maps the given request to the given requestId.
private  void receiveFromStore(FOStoreClientConnection con, boolean okToReleaseConnection)
          Receive the replies from the store and process them.
private  void sendToStore(FOStoreClientConnection con)
          Send the current Message buffer to the store.
(package private) static void verifyVersionNumber(java.io.DataInput in)
          Verify a Message's version number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connector

private final Connector connector
Connector for which this message acts as a transport.


requests

private final java.util.HashMap requests
Set of request objects that are in the process of carrying out their function; maps from a RequestId to Request. When a request is created, it adds itself to this map. When a request's reply is received, it is looked up by RequestId in this map, removed, and the Request object given the reply.


clids

private final java.util.HashSet clids
Set of CLIDs associated with ActivateClass requests that are in this Message. It is cleared by initOutput.


out

private final FOStoreOutput out
This contains the Message's actual data for the store.


numRequests

private int numRequests
Indicates the number of requests that have been written into this Message.


numRequestStash

private int numRequestStash
Contains the position in the output of the numRequest stashed by initOutput. This is modified and used only by initOutput and finishOutput.


VERSION_NUMBER

private static final int VERSION_NUMBER
The version number of the current protocol. In future, this version number can be used to identify mismatches in protocol. The format is (short)major; (byte)minor; (byte)patch Only use major for compatibility checks; always bump major when incompatibly changing protocol.

See Also:
Constant Field Values

msg

private static final I18NHelper msg
I18N support.


logger

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

Constructor Detail

Message

Message(Connector connector)
Constructor for Message. The output stream is initialized to contain the version number and a stash for the number of requests.

Parameters:
connector - The Connector on whose behalf this Message is serving as a transport. May be null.

Message

Message()
Method Detail

getConnector

Connector getConnector()
Returns:
The connector associated with this Message.

getOutput

public FOStoreOutput getOutput()
Return the FOStoreOutput stream for requests to be inserted.

Returns:
the FOStoreOutput under construction

processInStore

void processInStore(FOStoreClientConnection con,
                    boolean okToReleaseConnection)
Write this message to the given connection, and read replies from that connection, processing replies as they are read.

Parameters:
con - the FOStoreClientConnection for this message
See Also:
for stream header reader.

sendToStore

private void sendToStore(FOStoreClientConnection con)
Send the current Message buffer to the store. The data contained in out is written as one block of data. The connection's sendToStore is responsible for sending the data and handling the processing at the server side.

Parameters:
con - the FOStoreClientConnection

receiveFromStore

private void receiveFromStore(FOStoreClientConnection con,
                              boolean okToReleaseConnection)
Receive the replies from the store and process them.

Parameters:
con - the FOStoreConnection with the replies.

putRequest

void putRequest(RequestId requestId,
                Request request)
Maps the given request to the given requestId.

Parameters:
requestId - Identifies a request within a JVM.
request - A request for some operation on the store for which a reply is expected.

getRequest

Request getRequest(RequestId requestId)
Provides the Request corresponding to the give requestId, removing it from the internal map of requests (i.e., subsequent getRequest invocations for the same requestId will return null).

Parameters:
requestId - Identifier for a particular request in this JVM.
Returns:
The Request identified by the given identifier or null if there is no such Request.

hasRequests

boolean hasRequests()
Returns true if this message has requests for the store.

Returns:
true if there are any messages.

initOutput

private void initOutput()
Initialize the output buffer with version number and a stash for number of requests.


finishOutput

private void finishOutput()
Finish the output buffer by updating the stash with number of requests.


closeConnection

private void closeConnection(FOStoreClientConnection con)
Close the connection to the store.

Parameters:
con - the connection to close.

verifyVersionNumber

static void verifyVersionNumber(java.io.DataInput in)
                         throws java.io.IOException
Verify a Message's version number.

Throws:
javax.jdo.JDOFatalUserException - if the version number does not match that in the caller's JVM.
java.io.IOException

addCLID

void addCLID(CLID clid)
Add the given CLID to the set of CLIDs maintained by this Message.


containsCLID

boolean containsCLID(CLID clid)
Returns true if the given CLID is in this Message's set of CLIDs.


dump

public void dump()
Dump the complete current contents of the message buffer.