org.apache.jdo.impl.fostore
Class FOStoreRemoteConnection

java.lang.Object
  extended byjava.net.URLConnection
      extended byorg.apache.jdo.impl.fostore.FOStoreClientConnectionImpl
          extended byorg.apache.jdo.impl.fostore.FOStoreRemoteConnection
All Implemented Interfaces:
FOStoreClientConnection, FOStoreConnection

public class FOStoreRemoteConnection
extends FOStoreClientConnectionImpl

Represents a connection to a store that runs in a JVM separate from that of a client.

This class is public so that clients can access the value of DEFAULT_PORT.

Version:
1.0
Author:
Craig Russell

Field Summary
private  java.io.DataOutputStream clientRequests
          The DataOutputStream from the socket for requests for the server.
(package private)  FOStoreConnectionFactory connectionFactory
           
(package private)  FOStoreConnectionId connectionId
           
static int DEFAULT_PORT
          The default port number
(package private) static org.apache.commons.logging.Log logger
          Logger
(package private)  Message message
          Message to handle connection-to-connection messages (login).
private  java.io.DataInput serverReplies
          The DataInputStream from the socket for replies from the server.
private  java.net.Socket socket
          The socket used to communicate with the remote server.
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
 
Constructor Summary
(package private) FOStoreRemoteConnection(java.net.URL url)
          Creates new FOStoreRemoteConnection
 
Method Summary
 void close()
          Return this connection to the connection pool.
 void closeDatabase()
          Close the database associated with this connection.
 void connect()
          Connect to the data store.
 FOStoreConnectionFactory getConnectionFactory()
          Get the connection Factory used to create this connection.
 FOStoreConnectionId getConnectionId()
          Get the connection id used to create this connection.
 java.io.DataInput getInputFromServer()
          Provides DataInput from which the client can read replies from the server.
protected  java.lang.String localizePath(java.lang.String path)
           
protected  void login()
          Log in to the datastore.
 void sendToStore(byte[] buffer, int offset, int length)
          Write bytes to the store.
 void setConnectionFactory(FOStoreConnectionFactory cf)
          Set the connection id used to create this connection.
 void setConnectionId(FOStoreConnectionId id)
          Set the connection id used to create this connection.
 
Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getPermission, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setRequestProperty, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port number

See Also:
Constant Field Values

socket

private java.net.Socket socket
The socket used to communicate with the remote server.


serverReplies

private java.io.DataInput serverReplies
The DataInputStream from the socket for replies from the server.


clientRequests

private java.io.DataOutputStream clientRequests
The DataOutputStream from the socket for requests for the server.


message

Message message
Message to handle connection-to-connection messages (login).


connectionFactory

FOStoreConnectionFactory connectionFactory

connectionId

FOStoreConnectionId connectionId

logger

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

Constructor Detail

FOStoreRemoteConnection

FOStoreRemoteConnection(java.net.URL url)
Creates new FOStoreRemoteConnection

Parameters:
url - the url of the server.
Method Detail

connect

public void connect()
             throws java.io.IOException
Connect to the data store. The user name and password are stored in the connectionId.

Throws:
java.io.IOException - if a network error occurs

getInputFromServer

public java.io.DataInput getInputFromServer()
                                     throws java.io.IOException
Provides DataInput from which the client can read replies from the server.

Returns:
DataInput from which the client can read replies.
Throws:
java.io.IOException - if any problems.

sendToStore

public void sendToStore(byte[] buffer,
                        int offset,
                        int length)
                 throws java.io.IOException
Write bytes to the store. This is the only method to actually write data bytes from the Message to the server. As soon as the remote side has read the bytes, it processes the message and sends the reply.

Parameters:
buffer - the data buffer
offset - the offset within the buffer
length - the number of bytes to write
Throws:
java.io.IOException - if any problems.

closeDatabase

public void closeDatabase()
                   throws java.io.IOException,
                          FOStoreDatabaseException
Close the database associated with this connection. This closes the socket associated, which causes the remote database to be closed.

Throws:
java.io.IOException - if any problems with the socket.
FOStoreDatabaseException - if any problems with the database (not used here).

localizePath

protected java.lang.String localizePath(java.lang.String path)
Specified by:
localizePath in class FOStoreClientConnectionImpl
Returns:
The path as given, with the leading '/' removed if there is one.

close

public void close()
           throws java.io.IOException
Return this connection to the connection pool.

Specified by:
close in interface FOStoreClientConnection
Throws:
java.io.IOException

login

protected void login()
              throws java.io.IOException
Log in to the datastore. This will be done for both local and remote connections.

Throws:
java.io.IOException

setConnectionFactory

public void setConnectionFactory(FOStoreConnectionFactory cf)
Description copied from interface: FOStoreClientConnection
Set the connection id used to create this connection. This is used to determine which connection pool is used.

Specified by:
setConnectionFactory in interface FOStoreClientConnection

getConnectionFactory

public FOStoreConnectionFactory getConnectionFactory()
Get the connection Factory used to create this connection. Connections are pooled based on this connection Factory.

Specified by:
getConnectionFactory in interface FOStoreClientConnection

setConnectionId

public void setConnectionId(FOStoreConnectionId id)
Set the connection id used to create this connection. This is used to determine which connection pool is used.

Specified by:
setConnectionId in interface FOStoreClientConnection

getConnectionId

public FOStoreConnectionId getConnectionId()
Get the connection id used to create this connection. The id encapsulates URL, user, and password. Connections are pooled based on this connection id.

Specified by:
getConnectionId in interface FOStoreClientConnection