org.acplt.oncrpc.server
Class OncRpcTcpConnectionServerTransport

java.lang.Object
  |
  +--org.acplt.oncrpc.server.OncRpcServerTransport
        |
        +--org.acplt.oncrpc.server.OncRpcTcpConnectionServerTransport

public class OncRpcTcpConnectionServerTransport
extends OncRpcServerTransport

Instances of class OncRpcTcpServerTransport encapsulate TCP/IP-based XDR streams of ONC/RPC servers. This server transport class is responsible for receiving ONC/RPC calls over TCP/IP.

See Also:
OncRpcServerTransport, OncRpcTcpServerTransport, OncRpcUdpServerTransport

Field Summary
private  OncRpcTcpServerTransport parent
          Reference to the TCP/IP transport which created us to handle a new ONC/RPC connection.
private  boolean pendingDecoding
          Indicates that BeginDecoding has been called for the receiving XDR stream, so that it should be closed later using EndDecoding.
private  boolean pendingEncoding
          Indicates that BeginEncoding has been called for the sending XDR stream, so in face of exceptions we can not send an error reply to the client but only drop the connection.
private  XdrTcpDecodingStream receivingXdr
          XDR decoding stream used when receiving requests via TCP/IP from ONC/RPC clients.
private  XdrTcpEncodingStream sendingXdr
          XDR encoding stream used for sending replies via TCP/IP back to an ONC/RPC client.
private  java.net.Socket socket
          TCP socket used for stream-based communication with ONC/RPC clients.
private  OncRpcTcpSocketHelper socketHelper
          Socket helper object supplying missing methods for JDK 1.1 backwards compatibility.
protected  int transmissionTimeout
          Timeout during the phase where data is received within calls, or data is sent within replies.
 
Fields inherited from class org.acplt.oncrpc.server.OncRpcServerTransport
dispatcher, info, port
 
Constructor Summary
OncRpcTcpConnectionServerTransport(OncRpcDispatchable dispatcher, java.net.Socket socket, int program, int version, int bufferSize, OncRpcTcpServerTransport parent, int transmissionTimeout)
          Create a new instance of a OncRpcTcpSConnectionerverTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
OncRpcTcpConnectionServerTransport(OncRpcDispatchable dispatcher, java.net.Socket socket, OncRpcServerTransportRegistrationInfo[] info, int bufferSize, OncRpcTcpServerTransport parent, int transmissionTimeout)
          Create a new instance of a OncRpcTcpSConnectionerverTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
 
Method Summary
private  void _listen()
          The real workhorse handling incoming requests, dispatching them and sending back replies.
protected  void beginEncoding(OncRpcCallInformation callInfo, OncRpcServerReplyMessage state)
          Begins the sending phase for ONC/RPC replies.
 void close()
          Close the server transport and free any resources associated with it.
protected  void endDecoding()
          Finishes call parameter deserialization.
protected  void endEncoding()
          Finishes encoding the reply to this ONC/RPC call.
protected  void finalize()
          Finalize object by making sure that we're removed from the list of open transports which our parent transport maintains.
protected  XdrDecodingStream getXdrDecodingStream()
          Returns XDR stream which can be used for deserializing the parameters of this ONC/RPC call.
protected  XdrEncodingStream getXdrEncodingStream()
          Returns XDR stream which can be used for eserializing the reply to this ONC/RPC call.
 void listen()
          Creates a new thread and uses this thread to handle the new connection to receive ONC/RPC requests, then dispatching them and finally sending back reply messages.
 void register()
          Do not call.
protected  void reply(OncRpcCallInformation callInfo, OncRpcServerReplyMessage state, XdrAble reply)
          Send back an ONC/RPC reply to the original caller.
 void retrieveCall(XdrAble call)
          Retrieves the parameters sent within an ONC/RPC call message.
 
Methods inherited from class org.acplt.oncrpc.server.OncRpcServerTransport
getPort, unregister
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

socket

private java.net.Socket socket
TCP socket used for stream-based communication with ONC/RPC clients.

socketHelper

private OncRpcTcpSocketHelper socketHelper
Socket helper object supplying missing methods for JDK 1.1 backwards compatibility. So much for compile once, does not run everywhere.

sendingXdr

private XdrTcpEncodingStream sendingXdr
XDR encoding stream used for sending replies via TCP/IP back to an ONC/RPC client.

receivingXdr

private XdrTcpDecodingStream receivingXdr
XDR decoding stream used when receiving requests via TCP/IP from ONC/RPC clients.

pendingDecoding

private boolean pendingDecoding
Indicates that BeginDecoding has been called for the receiving XDR stream, so that it should be closed later using EndDecoding.

pendingEncoding

private boolean pendingEncoding
Indicates that BeginEncoding has been called for the sending XDR stream, so in face of exceptions we can not send an error reply to the client but only drop the connection.

parent

private OncRpcTcpServerTransport parent
Reference to the TCP/IP transport which created us to handle a new ONC/RPC connection.

transmissionTimeout

protected int transmissionTimeout
Timeout during the phase where data is received within calls, or data is sent within replies.
Constructor Detail

OncRpcTcpConnectionServerTransport

public OncRpcTcpConnectionServerTransport(OncRpcDispatchable dispatcher,
                                          java.net.Socket socket,
                                          int program,
                                          int version,
                                          int bufferSize,
                                          OncRpcTcpServerTransport parent,
                                          int transmissionTimeout)
                                   throws OncRpcException,
                                          java.io.IOException
Create a new instance of a OncRpcTcpSConnectionerverTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This particular server transport handles individual ONC/RPC connections over TCP/IP. This constructor is a convenience constructor for those transports handling only a single ONC/RPC program and version number.
Parameters:
dispatcher - Reference to interface of an object capable of dispatching (handling) ONC/RPC calls.
socket - TCP/IP-based socket of new connection.
port - Number of port where the server will wait for incoming calls.
program - Number of ONC/RPC program handled by this server transport.
version - Version number of ONC/RPC program handled.
bufferSize - Size of buffer used when receiving and sending chunks of XDR fragments over TCP/IP. The fragments built up to form ONC/RPC call and reply messages.
parent - Parent server transport which created us.
transmissionTimeout - Inherited transmission timeout.

OncRpcTcpConnectionServerTransport

public OncRpcTcpConnectionServerTransport(OncRpcDispatchable dispatcher,
                                          java.net.Socket socket,
                                          OncRpcServerTransportRegistrationInfo[] info,
                                          int bufferSize,
                                          OncRpcTcpServerTransport parent,
                                          int transmissionTimeout)
                                   throws OncRpcException,
                                          java.io.IOException
Create a new instance of a OncRpcTcpSConnectionerverTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This particular server transport handles individual ONC/RPC connections over TCP/IP.
Parameters:
dispatcher - Reference to interface of an object capable of dispatching (handling) ONC/RPC calls.
socket - TCP/IP-based socket of new connection.
port - Number of port where the server will wait for incoming calls.
info - Array of program and version number tuples of the ONC/RPC programs and versions handled by this transport.
bufferSize - Size of buffer used when receiving and sending chunks of XDR fragments over TCP/IP. The fragments built up to form ONC/RPC call and reply messages.
parent - Parent server transport which created us.
transmissionTimeout - Inherited transmission timeout.
Method Detail

close

public void close()
Close the server transport and free any resources associated with it.

Note that the server transport is not deregistered. You'll have to do it manually if you need to do so. The reason for this behaviour is, that the portmapper removes all entries regardless of the protocol (TCP/IP or UDP/IP) for a given ONC/RPC program number and version.

Calling this method on a OncRpcTcpServerTransport results in the listening TCP network socket immediately being closed. The handler thread will therefore either terminate directly or when it tries to sent back replies.

Overrides:
close in class OncRpcServerTransport

finalize

protected void finalize()
Finalize object by making sure that we're removed from the list of open transports which our parent transport maintains.
Overrides:
finalize in class java.lang.Object

register

public void register()
              throws OncRpcException
Do not call.
Throws:
java.lang.Error - because this method must not be called for an individual TCP/IP-based server transport.
Overrides:
register in class OncRpcServerTransport

retrieveCall

public void retrieveCall(XdrAble call)
                  throws OncRpcException,
                         java.io.IOException
Retrieves the parameters sent within an ONC/RPC call message. It also makes sure that the deserialization process is properly finished after the call parameters have been retrieved. Under the hood this method therefore calls XdrDecodingStream.endDecoding() to free any pending resources from the decoding stage.
Throws:
OncRpcException - if an ONC/RPC exception occurs, like the data could not be successfully deserialized.
java.io.IOException - if an I/O exception occurs, like transmission failures over the network, etc.
Overrides:
retrieveCall in class OncRpcServerTransport

getXdrDecodingStream

protected XdrDecodingStream getXdrDecodingStream()
Returns XDR stream which can be used for deserializing the parameters of this ONC/RPC call. This method belongs to the lower-level access pattern when handling ONC/RPC calls.
Overrides:
getXdrDecodingStream in class OncRpcServerTransport

endDecoding

protected void endDecoding()
                    throws OncRpcException,
                           java.io.IOException
Finishes call parameter deserialization. Afterwards the XDR stream returned by getXdrDecodingStream() must not be used any more. This method belongs to the lower-level access pattern when handling ONC/RPC calls.
Throws:
OncRpcException - if an ONC/RPC exception occurs, like the data could not be successfully deserialized.
java.io.IOException - if an I/O exception occurs, like transmission failures over the network, etc.
Overrides:
endDecoding in class OncRpcServerTransport

getXdrEncodingStream

protected XdrEncodingStream getXdrEncodingStream()
Returns XDR stream which can be used for eserializing the reply to this ONC/RPC call. This method belongs to the lower-level access pattern when handling ONC/RPC calls.
Overrides:
getXdrEncodingStream in class OncRpcServerTransport

beginEncoding

protected void beginEncoding(OncRpcCallInformation callInfo,
                             OncRpcServerReplyMessage state)
                      throws OncRpcException,
                             java.io.IOException
Begins the sending phase for ONC/RPC replies. This method belongs to the lower-level access pattern when handling ONC/RPC calls.
Parameters:
callInfo - Information about ONC/RPC call for which we are about to send back the reply.
state - ONC/RPC reply header indicating success or failure.
Throws:
OncRpcException - if an ONC/RPC exception occurs, like the data could not be successfully serialized.
java.io.IOException - if an I/O exception occurs, like transmission
Overrides:
beginEncoding in class OncRpcServerTransport

endEncoding

protected void endEncoding()
                    throws OncRpcException,
                           java.io.IOException
Finishes encoding the reply to this ONC/RPC call. Afterwards you must not use the XDR stream returned by getXdrEncodingStream() any longer.
Throws:
OncRpcException - if an ONC/RPC exception occurs, like the data could not be successfully serialized.
java.io.IOException - if an I/O exception occurs, like transmission failures over the network, etc.
Overrides:
endEncoding in class OncRpcServerTransport

reply

protected void reply(OncRpcCallInformation callInfo,
                     OncRpcServerReplyMessage state,
                     XdrAble reply)
              throws OncRpcException,
                     java.io.IOException
Send back an ONC/RPC reply to the original caller. This is rather a low-level method, typically not used by applications. Dispatcher handling ONC/RPC calls have to use the OncRpcCallInformation.reply(XdrAble) method instead on the call object supplied to the handler.
Parameters:
callInfo - information about the original call, which are necessary to send back the reply to the appropriate caller.
state - ONC/RPC reply message header indicating success or failure and containing associated state information.
reply - If not null, then this parameter references the reply to be serialized after the reply message header.
Throws:
OncRpcException - if an ONC/RPC exception occurs, like the data could not be successfully serialized.
java.io.IOException - if an I/O exception occurs, like transmission failures over the network, etc.
Overrides:
reply in class OncRpcServerTransport
See Also:
OncRpcCallInformation, OncRpcDispatchable

listen

public void listen()
Creates a new thread and uses this thread to handle the new connection to receive ONC/RPC requests, then dispatching them and finally sending back reply messages. Control in the calling thread immediately returns after the handler thread has been created.

Currently only one call after the other is dispatched, so no multithreading is done when receiving multiple calls. Instead, later calls have to wait for the current call to finish before they are handled.

Overrides:
listen in class OncRpcServerTransport

_listen

private void _listen()
The real workhorse handling incoming requests, dispatching them and sending back replies.