org.acplt.oncrpc.server
Class OncRpcTcpServerTransport

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

public class OncRpcTcpServerTransport
extends OncRpcServerTransport

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

See Also:
OncRpcServerTransport, OncRpcTcpConnectionServerTransport, OncRpcUdpServerTransport

Field Summary
private  int bufferSize
          Size of send/receive buffers to use when encoding/decoding XDR data.
private  java.util.LinkedList openTransports
          Collection containing currently open transports.
private  java.net.ServerSocket socket
          TCP socket used for stream-based communication with ONC/RPC clients.
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
OncRpcTcpServerTransport(OncRpcDispatchable dispatcher, int port, int program, int version, int bufferSize)
          Create a new instance of a OncRpcTcpServerTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
OncRpcTcpServerTransport(OncRpcDispatchable dispatcher, int port, OncRpcServerTransportRegistrationInfo[] info, int bufferSize)
          Create a new instance of a OncRpcTcpServerTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server.
 
Method Summary
protected  void beginEncoding(OncRpcCallInformation callInfo, OncRpcServerReplyMessage state)
          Do not call.
 void close()
          Close the server transport and free any resources associated with it.
protected  void endDecoding()
          Do not call.
protected  void endEncoding()
          Do not call.
 int getTransmissionTimeout()
          Retrieve the current timeout used during transmission phases (call and reply phases).
protected  XdrDecodingStream getXdrDecodingStream()
          Do not call.
protected  XdrEncodingStream getXdrEncodingStream()
          Do not call.
 void listen()
          Creates a new thread and uses this thread to listen to incoming ONC/RPC requests, then dispatches them and finally sends back the appropriate reply messages.
 void register()
          Register the TCP/IP port where this server transport waits for incoming requests with the ONC/RPC portmapper.
protected  void removeTransport(OncRpcTcpConnectionServerTransport transport)
          Removes a TCP/IP server transport from the list of currently open transports.
protected  void reply(OncRpcCallInformation callInfo, OncRpcServerReplyMessage state, XdrAble reply)
          Do not call.
 void retrieveCall(XdrAble call)
          Do not call.
 void setTransmissionTimeout(int milliseconds)
          Set the timeout used during transmission of data.
 
Methods inherited from class org.acplt.oncrpc.server.OncRpcServerTransport
getPort, unregister
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

socket

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

bufferSize

private int bufferSize
Size of send/receive buffers to use when encoding/decoding XDR data.

openTransports

private java.util.LinkedList openTransports
Collection containing currently open transports.

transmissionTimeout

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

OncRpcTcpServerTransport

public OncRpcTcpServerTransport(OncRpcDispatchable dispatcher,
                                int port,
                                int program,
                                int version,
                                int bufferSize)
                         throws OncRpcException,
                                java.io.IOException
Create a new instance of a OncRpcTcpServerTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This particular server transport only waits for incoming connection requests and then creates OncRpcTcpConnectionServerTransport server transports to handle individual connections. 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.
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.

OncRpcTcpServerTransport

public OncRpcTcpServerTransport(OncRpcDispatchable dispatcher,
                                int port,
                                OncRpcServerTransportRegistrationInfo[] info,
                                int bufferSize)
                         throws OncRpcException,
                                java.io.IOException
Create a new instance of a OncRpcTcpServerTransport which encapsulates TCP/IP-based XDR streams of an ONC/RPC server. This particular server transport only waits for incoming connection requests and then creates OncRpcTcpConnectionServerTransport server transports to handle individual connections.
Parameters:
dispatcher - Reference to interface of an object capable of dispatching (handling) ONC/RPC calls.
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.
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. In addition, all server transports handling the individual TCP/IP connections will also be closed. The handler threads will therefore either terminate directly or when they try to sent back replies.

Overrides:
close in class OncRpcServerTransport

removeTransport

protected void removeTransport(OncRpcTcpConnectionServerTransport transport)
Removes a TCP/IP server transport from the list of currently open transports.
Parameters:
transport - Server transport to remove from the list of currently open transports for this listening transport.

register

public void register()
              throws OncRpcException
Register the TCP/IP port where this server transport waits for incoming requests with the ONC/RPC portmapper.
Throws:
OncRpcException - if the portmapper could not be contacted successfully.
Overrides:
register in class OncRpcServerTransport

retrieveCall

public void retrieveCall(XdrAble call)
                  throws OncRpcException,
                         java.io.IOException
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
retrieveCall in class OncRpcServerTransport

getXdrDecodingStream

protected XdrDecodingStream getXdrDecodingStream()
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
getXdrDecodingStream in class OncRpcServerTransport

endDecoding

protected void endDecoding()
                    throws OncRpcException,
                           java.io.IOException
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
endDecoding in class OncRpcServerTransport

getXdrEncodingStream

protected XdrEncodingStream getXdrEncodingStream()
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
getXdrEncodingStream in class OncRpcServerTransport

beginEncoding

protected void beginEncoding(OncRpcCallInformation callInfo,
                             OncRpcServerReplyMessage state)
                      throws OncRpcException,
                             java.io.IOException
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
beginEncoding in class OncRpcServerTransport

endEncoding

protected void endEncoding()
                    throws OncRpcException,
                           java.io.IOException
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
endEncoding in class OncRpcServerTransport

reply

protected void reply(OncRpcCallInformation callInfo,
                     OncRpcServerReplyMessage state,
                     XdrAble reply)
              throws OncRpcException,
                     java.io.IOException
Do not call.
Throws:
java.lang.Error - because this method must not be called for a listening server transport.
Overrides:
reply in class OncRpcServerTransport

listen

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

For every incomming TCP/IP connection a handler thread is created to handle ONC/RPC calls on this particular connection.

Overrides:
listen in class OncRpcServerTransport

setTransmissionTimeout

public void setTransmissionTimeout(int milliseconds)
Set the timeout used during transmission of data. If the flow of data when sending calls or receiving replies blocks longer than the given timeout, an exception is thrown. The timeout must be > 0.
Parameters:
milliseconds - Transmission timeout in milliseconds.

getTransmissionTimeout

public int getTransmissionTimeout()
Retrieve the current timeout used during transmission phases (call and reply phases).
Returns:
Current transmission timeout.