Package com.rabbitmq.client.impl
Class SocketFrameHandler
- java.lang.Object
-
- com.rabbitmq.client.impl.SocketFrameHandler
-
- All Implemented Interfaces:
FrameHandler,NetworkConnection
public class SocketFrameHandler extends java.lang.Object implements FrameHandler
A socket-based frame handler.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.DataInputStream_inputStreamSocket's inputstream - data from the broker - synchronized onprivate java.util.concurrent.locks.Lock_inputStreamLockprivate java.io.DataOutputStream_outputStreamSocket's outputstream - data to the broker - synchronized onprivate java.util.concurrent.locks.Lock_outputStreamLockprivate java.util.concurrent.ExecutorService_shutdownExecutorOptionalExecutorServicefor final flush.private java.net.Socket_socketThe underlying socketprivate static org.slf4j.LoggerLOGGERprivate intmaxInboundMessageBodySizestatic intSOCKET_CLOSING_TIMEOUTTime 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 voidclose()Close the underlying data connection (complaint not permitted).voidflush()Flush the underlying data connection.java.net.InetAddressgetAddress()Retrieve address of peer.java.io.DataInputStreamgetInputStream()java.net.InetAddressgetLocalAddress()Retrieve the local host.intgetLocalPort()Retrieve the local port number.intgetPort()Retrieve port number of peer.intgetTimeout()Get the underlying socket's read timeout in milliseconds.voidinitialize(AMQConnection connection)FramereadFrame()Read aFramefrom the underlying data connection.voidsendHeader()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.voidsendHeader(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.voidsendHeader(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.voidsetTimeout(int timeoutMs)Set the underlying socket's read timeout in milliseconds, if applicable.voidwriteFrame(Frame frame)Write aFrameto the underlying data connection.
-
-
-
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
OptionalExecutorServicefor 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
-
getAddress
public java.net.InetAddress getAddress()
Description copied from interface:NetworkConnectionRetrieve address of peer.- Specified by:
getAddressin interfaceNetworkConnection
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Description copied from interface:NetworkConnectionRetrieve the local host.- Specified by:
getLocalAddressin interfaceNetworkConnection- Returns:
- the client socket address.
-
getInputStream
public java.io.DataInputStream getInputStream()
-
getPort
public int getPort()
Description copied from interface:NetworkConnectionRetrieve port number of peer.- Specified by:
getPortin interfaceNetworkConnection
-
getLocalPort
public int getLocalPort()
Description copied from interface:NetworkConnectionRetrieve the local port number.- Specified by:
getLocalPortin interfaceNetworkConnection- Returns:
- the client socket port number
-
setTimeout
public void setTimeout(int timeoutMs) throws java.net.SocketExceptionDescription copied from interface:FrameHandlerSet the underlying socket's read timeout in milliseconds, if applicable.- Specified by:
setTimeoutin interfaceFrameHandler- Parameters:
timeoutMs- The timeout in milliseconds- Throws:
java.net.SocketException
-
getTimeout
public int getTimeout() throws java.net.SocketExceptionDescription copied from interface:FrameHandlerGet the underlying socket's read timeout in milliseconds.- Specified by:
getTimeoutin interfaceFrameHandler- Returns:
- The timeout in milliseconds
- Throws:
java.net.SocketException
-
sendHeader
public void sendHeader(int major, int minor) throws java.io.IOExceptionWrite 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 numberminor- 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.IOExceptionWrite 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 numberminor- minor protocol version numberrevision- 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.IOExceptionDescription copied from interface:FrameHandlerSend 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:
sendHeaderin interfaceFrameHandler- Throws:
java.io.IOException- if there is a problem accessing the connection
-
initialize
public void initialize(AMQConnection connection)
- Specified by:
initializein interfaceFrameHandler
-
readFrame
public Frame readFrame() throws java.io.IOException
Description copied from interface:FrameHandlerRead aFramefrom the underlying data connection.- Specified by:
readFramein interfaceFrameHandler- Returns:
- an incoming Frame, or null if there is none
- Throws:
java.io.IOException- if there is a problem accessing the connectionjava.net.SocketTimeoutException- if the underlying read times out
-
writeFrame
public void writeFrame(Frame frame) throws java.io.IOException
Description copied from interface:FrameHandlerWrite aFrameto the underlying data connection.- Specified by:
writeFramein interfaceFrameHandler- 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.IOExceptionDescription copied from interface:FrameHandlerFlush the underlying data connection.- Specified by:
flushin interfaceFrameHandler- Throws:
java.io.IOException- if there is a problem accessing the connection
-
close
public void close()
Description copied from interface:FrameHandlerClose the underlying data connection (complaint not permitted).- Specified by:
closein interfaceFrameHandler
-
-