org.apache.jdo.impl.fostore
Class FOStoreServerConnectionImpl

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.FOStoreServerConnectionImpl
All Implemented Interfaces:
FOStoreConnection, FOStoreServerConnection

class FOStoreServerConnectionImpl
extends java.lang.Object
implements FOStoreServerConnection

This class implements the FOStoreServerConnection contract. It is used in two modes: local and remote. In local mode, the default constructor is used. In remote mode, the constructor that takes a Socket is used. The connection after construction does not contain any information about the data store. After the login request is successfully executed, the Database information is known. Subsequent requests know the Database.


Field Summary
private  FOStoreInput clientDataInput
          Used by server to read client's requests.
private  java.lang.String dbname
          The local database name.
private  FOStoreDatabase fodb
          The local database
(package private) static org.apache.commons.logging.Log logger
          Logger
private static I18NHelper msg
          I18N support.
private  boolean okToReleaseDatabase
          Indicates if releaseDatabase can really do so.
private  java.lang.String root
          Root in filesystem at which database will be created.
private  FOStoreOutput serverData
          Used by server to write its replies.
private  java.net.Socket socket
          The socket over which we communicate to the client.
private  java.io.DataInputStream socketDataInputStream
          The input stream from the socket.
private  java.io.OutputStream socketOutputStream
          The output stream from the socket.
 
Constructor Summary
FOStoreServerConnectionImpl()
          Creates new FOStoreServerConnectionImpl for the local case.
FOStoreServerConnectionImpl(java.net.Socket socket, java.lang.String root)
          Creates new FOStoreServerConnectionImpl for the remote case.
 
Method Summary
 boolean addExtent(DBExtent dbExtent)
          Adds the extent to this connections set of extents that have been changed during a transaction.
 void close()
          Close this connection; release all resources.
 void closeDatabase()
          Close the database associated with this connection.
 void commit()
          Commits the work done in this connection.
 Reply createReply(RequestId requestId)
          Provides a Reply to which the server can write replies to the client's requests.
private  java.lang.String databasePath(java.lang.String dbname)
           
 FOStoreDatabase getDatabase()
          Provides the database to be used by the server using this connection.
 FOStoreInput getInputFromClient()
          Provides a DataInput from which the server can read the client's requests.
 FOStoreOutput getOutputForClient()
          Provides a DataOutput to which the server can write data for the client.
 java.io.DataInput getOutputFromServer()
          Provides a DataInput from which the local client can read the server's replies.
 void openDatabase(java.lang.String dbname, java.lang.String user, long timestamp, byte[] secret, boolean create)
          Open the database if it exists, and verify the user authentication.
 void processRequests()
          Process requests from client.
 void readInputFromClient()
          Read the input stream from the socket.
(package private)  void releaseDatabase()
          Release the database associated with this connection.
 void rollback()
          Rolls back the work done in this connection.
 void sendToClient()
          Sends all the reply data to the client.
 void setClientInput(FOStoreInput fi)
          Set client data stream.
 void setOkToReleaseDatabase(boolean ok)
          Indicates whether or not releaseDatabase can actually release the database.
 void writeOutputToClient()
          Writes the output to the client socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msg

private static final I18NHelper msg
I18N support.


logger

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


serverData

private FOStoreOutput serverData
Used by server to write its replies.


clientDataInput

private FOStoreInput clientDataInput
Used by server to read client's requests.


socket

private final java.net.Socket socket
The socket over which we communicate to the client.


root

private final java.lang.String root
Root in filesystem at which database will be created.


socketDataInputStream

private java.io.DataInputStream socketDataInputStream
The input stream from the socket. Set after connect; reset at socket.close().


socketOutputStream

private java.io.OutputStream socketOutputStream
The output stream from the socket. Set after connect; reset at socket.close().


dbname

private java.lang.String dbname
The local database name.


fodb

private FOStoreDatabase fodb
The local database


okToReleaseDatabase

private boolean okToReleaseDatabase
Indicates if releaseDatabase can really do so.

Constructor Detail

FOStoreServerConnectionImpl

public FOStoreServerConnectionImpl()
Creates new FOStoreServerConnectionImpl for the local case.


FOStoreServerConnectionImpl

public FOStoreServerConnectionImpl(java.net.Socket socket,
                                   java.lang.String root)
Creates new FOStoreServerConnectionImpl for the remote case.

Method Detail

commit

public void commit()
            throws FOStoreDatabaseException
Commits the work done in this connection. The database must already be connected. Stores in the database (a) the extents that have been changed and (b) the database's DBInfo.

Specified by:
commit in interface FOStoreServerConnection
Throws:
FOStoreDatabaseException

rollback

public void rollback()
              throws FOStoreDatabaseException
Rolls back the work done in this connection.

Specified by:
rollback in interface FOStoreServerConnection
Throws:
FOStoreDatabaseException

createReply

public Reply createReply(RequestId requestId)
                  throws java.io.IOException
Provides a Reply to which the server can write replies to the client's requests.

Specified by:
createReply in interface FOStoreServerConnection
Returns:
Reply object for writing information about one reply.
Throws:
java.io.IOException

getInputFromClient

public FOStoreInput getInputFromClient()
Provides a DataInput from which the server can read the client's requests.

Specified by:
getInputFromClient in interface FOStoreServerConnection
Returns:
DataInput for reading requests.

readInputFromClient

public void readInputFromClient()
                         throws java.io.IOException
Description copied from interface: FOStoreServerConnection
Read the input stream from the socket.

Specified by:
readInputFromClient in interface FOStoreServerConnection
Throws:
java.io.IOException

sendToClient

public void sendToClient()
                  throws java.io.IOException,
                         FOStoreDatabaseException
Description copied from interface: FOStoreServerConnection
Sends all the reply data to the client.

Specified by:
sendToClient in interface FOStoreServerConnection
Throws:
java.io.IOException
FOStoreDatabaseException
See Also:
FOStoreServerConnection.sendToClient()

addExtent

public boolean addExtent(DBExtent dbExtent)
Adds the extent to this connections set of extents that have been changed during a transaction. They will be put to the database when sendToClient is invoked.

Specified by:
addExtent in interface FOStoreServerConnection

openDatabase

public void openDatabase(java.lang.String dbname,
                         java.lang.String user,
                         long timestamp,
                         byte[] secret,
                         boolean create)
                  throws FOStoreDatabaseException,
                         java.lang.InterruptedException
Open the database if it exists, and verify the user authentication. If the database does not exist, create it.

Specified by:
openDatabase in interface FOStoreServerConnection
Throws:
FOStoreDatabaseException
java.lang.InterruptedException

getDatabase

public FOStoreDatabase getDatabase()
Provides the database to be used by the server using this connection.

Specified by:
getDatabase in interface FOStoreServerConnection
Returns:
A database.

getOutputForClient

public FOStoreOutput getOutputForClient()
Provides a DataOutput to which the server can write data for the client. This is not normally used for writing data associated with a single reply (use createReply for that purpose).

Specified by:
getOutputForClient in interface FOStoreServerConnection
Returns:
FOStoreOutput for writing data to client.

getOutputFromServer

public java.io.DataInput getOutputFromServer()
Provides a DataInput from which the local client can read the server's replies. Reset for the next output request.

Specified by:
getOutputFromServer in interface FOStoreServerConnection

writeOutputToClient

public void writeOutputToClient()
                         throws java.io.IOException
Writes the output to the client socket. Reset for the next output request.

Specified by:
writeOutputToClient in interface FOStoreServerConnection
Throws:
java.io.IOException

setClientInput

public void setClientInput(FOStoreInput fi)
Description copied from interface: FOStoreServerConnection
Set client data stream. Only used in local case.

Specified by:
setClientInput in interface FOStoreServerConnection

processRequests

public void processRequests()
Description copied from interface: FOStoreServerConnection
Process requests from client.

Specified by:
processRequests in interface FOStoreServerConnection

setOkToReleaseDatabase

public void setOkToReleaseDatabase(boolean ok)
Indicates whether or not releaseDatabase can actually release the database.

Specified by:
setOkToReleaseDatabase in interface FOStoreServerConnection

releaseDatabase

void releaseDatabase()
               throws java.lang.InterruptedException
Release the database associated with this connection.

Throws:
java.lang.InterruptedException

closeDatabase

public void closeDatabase()
                   throws FOStoreDatabaseException
Close the database associated with this connection.

Specified by:
closeDatabase in interface FOStoreServerConnection
Throws:
FOStoreDatabaseException

close

public void close()
           throws FOStoreDatabaseException
Close this connection; release all resources.

Throws:
FOStoreDatabaseException

databasePath

private final java.lang.String databasePath(java.lang.String dbname)
Returns:
A String for the databse's pathnamne. It is based on the given dbname, plus the root, if one was given when this connection was created.