Class SocketFrameHandler

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.DataInputStream _inputStream
      Socket's inputstream - data from the broker - synchronized on
      private java.util.concurrent.locks.Lock _inputStreamLock  
      private java.io.DataOutputStream _outputStream
      Socket's outputstream - data to the broker - synchronized on
      private java.util.concurrent.locks.Lock _outputStreamLock  
      private java.util.concurrent.ExecutorService _shutdownExecutor
      Optional ExecutorService for final flush.
      private java.net.Socket _socket
      The underlying socket
      private static org.slf4j.Logger LOGGER  
      private int maxInboundMessageBodySize  
      static int SOCKET_CLOSING_TIMEOUT
      Time to linger before closing the socket forcefully.
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketFrameHandler​(java.net.Socket socket)  
      SocketFrameHandler​(java.net.Socket socket, java.util.concurrent.ExecutorService shutdownExecutor, int maxInboundMessageBodySize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the underlying data connection (complaint not permitted).
      void flush()
      Flush the underlying data connection.
      java.net.InetAddress getAddress()
      Retrieve address of peer.
      java.io.DataInputStream getInputStream()  
      java.net.InetAddress getLocalAddress()
      Retrieve the local host.
      int getLocalPort()
      Retrieve the local port number.
      int getPort()
      Retrieve port number of peer.
      int getTimeout()
      Get the underlying socket's read timeout in milliseconds.
      void initialize​(AMQConnection connection)  
      Frame readFrame()
      Read a Frame from the underlying data connection.
      void sendHeader()
      Send the initial connection header, thus kickstarting the AMQP protocol version negotiation process and putting the underlying connection in a state such that the next layer of startup can proceed.
      void sendHeader​(int major, int minor)
      Write a 0-8-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.
      void sendHeader​(int major, int minor, int revision)
      Write a 0-9-1-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.
      void setTimeout​(int timeoutMs)
      Set the underlying socket's read timeout in milliseconds, if applicable.
      void writeFrame​(Frame frame)
      Write a Frame to the underlying data connection.
      • Methods inherited from class java.lang.Object

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

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • _socket

        private final java.net.Socket _socket
        The underlying socket
      • _shutdownExecutor

        private final java.util.concurrent.ExecutorService _shutdownExecutor
        Optional ExecutorService for final flush.
      • _inputStream

        private final java.io.DataInputStream _inputStream
        Socket's inputstream - data from the broker - synchronized on
      • _inputStreamLock

        private final java.util.concurrent.locks.Lock _inputStreamLock
      • _outputStream

        private final java.io.DataOutputStream _outputStream
        Socket's outputstream - data to the broker - synchronized on
      • _outputStreamLock

        private final java.util.concurrent.locks.Lock _outputStreamLock
      • maxInboundMessageBodySize

        private final int maxInboundMessageBodySize
      • SOCKET_CLOSING_TIMEOUT

        public static final int SOCKET_CLOSING_TIMEOUT
        Time to linger before closing the socket forcefully.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SocketFrameHandler

        public SocketFrameHandler​(java.net.Socket socket)
                           throws java.io.IOException
        Parameters:
        socket - the socket to use
        Throws:
        java.io.IOException
      • SocketFrameHandler

        public SocketFrameHandler​(java.net.Socket socket,
                                  java.util.concurrent.ExecutorService shutdownExecutor,
                                  int maxInboundMessageBodySize)
                           throws java.io.IOException
        Parameters:
        socket - the socket to use
        Throws:
        java.io.IOException
    • Method Detail

      • getInputStream

        public java.io.DataInputStream getInputStream()
      • setTimeout

        public void setTimeout​(int timeoutMs)
                        throws java.net.SocketException
        Description copied from interface: FrameHandler
        Set the underlying socket's read timeout in milliseconds, if applicable.
        Specified by:
        setTimeout in interface FrameHandler
        Parameters:
        timeoutMs - The timeout in milliseconds
        Throws:
        java.net.SocketException
      • getTimeout

        public int getTimeout()
                       throws java.net.SocketException
        Description copied from interface: FrameHandler
        Get the underlying socket's read timeout in milliseconds.
        Specified by:
        getTimeout in interface FrameHandler
        Returns:
        The timeout in milliseconds
        Throws:
        java.net.SocketException
      • sendHeader

        public void sendHeader​(int major,
                               int minor)
                        throws java.io.IOException
        Write a 0-8-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.
        Parameters:
        major - major protocol version number
        minor - minor protocol version number
        Throws:
        java.io.IOException - if there is a problem accessing the connection
        See Also:
        sendHeader()
      • sendHeader

        public void sendHeader​(int major,
                               int minor,
                               int revision)
                        throws java.io.IOException
        Write a 0-9-1-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.
        Parameters:
        major - major protocol version number
        minor - minor protocol version number
        revision - protocol revision number
        Throws:
        java.io.IOException - if there is a problem accessing the connection
        See Also:
        sendHeader()
      • sendHeader

        public void sendHeader()
                        throws java.io.IOException
        Description copied from interface: FrameHandler
        Send the initial connection header, thus kickstarting the AMQP protocol version negotiation process and putting the underlying connection in a state such that the next layer of startup can proceed.
        Specified by:
        sendHeader in interface FrameHandler
        Throws:
        java.io.IOException - if there is a problem accessing the connection
      • readFrame

        public Frame readFrame()
                        throws java.io.IOException
        Description copied from interface: FrameHandler
        Read a Frame from the underlying data connection.
        Specified by:
        readFrame in interface FrameHandler
        Returns:
        an incoming Frame, or null if there is none
        Throws:
        java.io.IOException - if there is a problem accessing the connection
        java.net.SocketTimeoutException - if the underlying read times out
      • writeFrame

        public void writeFrame​(Frame frame)
                        throws java.io.IOException
        Description copied from interface: FrameHandler
        Write a Frame to the underlying data connection.
        Specified by:
        writeFrame in interface FrameHandler
        Parameters:
        frame - the Frame to transmit
        Throws:
        java.io.IOException - if there is a problem accessing the connection
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: FrameHandler
        Flush the underlying data connection.
        Specified by:
        flush in interface FrameHandler
        Throws:
        java.io.IOException - if there is a problem accessing the connection
      • close

        public void close()
        Description copied from interface: FrameHandler
        Close the underlying data connection (complaint not permitted).
        Specified by:
        close in interface FrameHandler