Class OncRpcUdpSocketHelper

java.lang.Object
org.acplt.oncrpc.OncRpcUdpSocketHelper

public class OncRpcUdpSocketHelper extends Object
Wraps JRE-specific networking code for UDP/IP-based client sockets. So much for compile once, make it unuseable everywhere.

The following JRE-dependent methods are wrapped and will just do nothing or return fake information on old JRE plattforms. The number after each method wrapper indicates the first JRE version supporting a particular feature:

  • setSendBufferSize() -- 1.2
  • setReceiveBufferSize() -- 1.2
  • The following methods have been around since JDK 1.1, so we do not need to wrap them as we will never support JDK 1.0 -- let it rest in piece(s):

    • getTcpNoDelay() / setTcpNoDelay()
    • getSoTimeout() / setSoTimeout()
    Version:
    $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/OncRpcUdpSocketHelper.java,v 1.3 2007/05/29 19:45:46 haraldalbrecht Exp $
    Author:
    Harald Albrecht
    • Field Summary

      Fields
      Modifier and Type
      Field
      Description
      private Method
      Method Socket.getReceiveBufferSize or null if not available in the class library of a particular JRE.
      private Method
      Method Socket.getSendBufferSize or null if not available in the class library of a particular JRE.
      private Method
      Method Socket.setReceiverBufferSize or null if not available in the class library of a particular JRE.
      private Method
      Method Socket.setSendBufferSize or null if not available in the class library of a particular JRE.
      The datagram socket for which we have to help out with some missing methods.
    • Constructor Summary

      Constructors
      Constructor
      Description
      Creates a datagram socket and binds it to an arbitrary available port on the local host machine.
    • Method Summary

      Modifier and Type
      Method
      Description
      int
      Get size of receive buffer for this socket.
      int
      Get size of send buffer for this socket.
      protected void
      Looks up methods of class DatagramSocket whether they are supported by the class libraries of the JRE we are currently executing on.
      void
      Sets the socket's receive buffer size as a hint to the underlying transport layer to use appropriately sized I/O buffers.
      void
      Sets the socket's send buffer size as a hint to the underlying transport layer to use appropriately sized I/O buffers.

      Methods inherited from class java.lang.Object

      clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Details

      • socket

        private DatagramSocket socket
        The datagram socket for which we have to help out with some missing methods.
      • methodSetSendBufferSize

        private Method methodSetSendBufferSize
        Method Socket.setSendBufferSize or null if not available in the class library of a particular JRE.
      • methodSetReceiveBufferSize

        private Method methodSetReceiveBufferSize
        Method Socket.setReceiverBufferSize or null if not available in the class library of a particular JRE.
      • methodGetSendBufferSize

        private Method methodGetSendBufferSize
        Method Socket.getSendBufferSize or null if not available in the class library of a particular JRE.
      • methodGetReceiveBufferSize

        private Method methodGetReceiveBufferSize
        Method Socket.getReceiveBufferSize or null if not available in the class library of a particular JRE.
    • Constructor Details

      • OncRpcUdpSocketHelper

        public OncRpcUdpSocketHelper(DatagramSocket socket)
        Creates a datagram socket and binds it to an arbitrary available port on the local host machine.
    • Method Details

      • setSendBufferSize

        public void setSendBufferSize(int size) throws SocketException
        Sets the socket's send buffer size as a hint to the underlying transport layer to use appropriately sized I/O buffers. If the class libraries of the underlying JRE do not support setting the send buffer size, this is silently ignored.
        Parameters:
        size - The size to which to set the send buffer size. This value must be greater than 0.
        Throws:
        SocketException - if the socket's send buffer size could not be set, because the transport layer decided against accepting the new buffer size.
        IllegalArgumentException - if size is 0 or negative.
      • getSendBufferSize

        public int getSendBufferSize() throws SocketException
        Get size of send buffer for this socket.
        Returns:
        Size of send buffer.
        Throws:
        SocketException - If the transport layer could not be queried for the size of this socket's send buffer.
      • setReceiveBufferSize

        public void setReceiveBufferSize(int size) throws SocketException
        Sets the socket's receive buffer size as a hint to the underlying transport layer to use appropriately sized I/O buffers. If the class libraries of the underlying JRE do not support setting the receive buffer size, this is silently ignored.
        Parameters:
        size - The size to which to set the receive buffer size. This value must be greater than 0.
        Throws:
        SocketException - if the socket's receive buffer size could not be set, because the transport layer decided against accepting the new buffer size.
        IllegalArgumentException - if size is 0 or negative.
      • getReceiveBufferSize

        public int getReceiveBufferSize() throws SocketException
        Get size of receive buffer for this socket.
        Returns:
        Size of receive buffer.
        Throws:
        SocketException - If the transport layer could not be queried for the size of this socket's receive buffer.
      • queryMethods

        protected void queryMethods()
        Looks up methods of class DatagramSocket whether they are supported by the class libraries of the JRE we are currently executing on.