Package com.rabbitmq.client.impl
Class AMQConnection
- java.lang.Object
-
- com.rabbitmq.client.impl.ShutdownNotifierComponent
-
- com.rabbitmq.client.impl.AMQConnection
-
- All Implemented Interfaces:
Connection
,NetworkConnection
,ShutdownNotifier
,java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
RecoveryAwareAMQConnection
public class AMQConnection extends ShutdownNotifierComponent implements Connection, NetworkConnection
Concrete class representing and managing an AMQP connection to a broker.To create a broker connection, use
ConnectionFactory
. SeeConnection
for an example.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AMQConnection.DefaultConnectionInfo
private class
AMQConnection.MainLoop
private class
AMQConnection.SocketCloseWait
-
Field Summary
Fields Modifier and Type Field Description private BlockingCell<java.lang.Object>
_appContinuation
Object used for blocking main application thread when doing all the necessary connection shutdown operationsprivate boolean
_brokerInitiatedShutdown
Flag indicating whether the client received Connection.Close message from the brokerprivate AMQChannel
_channel0
The special channel 0 (not managed by the_channelManager
)private ChannelManager
_channelManager
Object that manages a set of channelsprivate java.util.Map<java.lang.String,java.lang.Object>
_clientProperties
private ExceptionHandler
_exceptionHandler
Handler for (uncaught) exceptions that crop up in theAMQConnection.MainLoop
.private FrameHandler
_frameHandler
Frame source/sinkprivate int
_frameMax
Maximum frame length, or zero if no limit is setprivate int
_heartbeat
Currently-configured heart-beat interval, in seconds.private HeartbeatSender
_heartbeatSender
Manages heart-beat sending for this connectionprivate boolean
_inConnectionNegotiation
Flag indicating we are still negotiating the connection in startprivate int
_missedHeartbeats
Count of socket-timeouts that have happened without any incoming framesprivate boolean
_running
Flag controlling the main driver loop's terminationprivate java.util.Map<java.lang.String,java.lang.Object>
_serverProperties
Saved server properties field from connection.startprivate java.lang.String
_virtualHost
protected ConsumerWorkService
_workService
private java.util.Collection<BlockedListener>
blockedListeners
static double
CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER
private int
channelRpcTimeout
private boolean
channelShouldCheckRpcResponseType
private static Version
clientVersion
private ObservationCollector.ConnectionInfo
connectionInfo
private java.util.concurrent.ExecutorService
consumerWorkServiceExecutor
private CredentialsProvider
credentialsProvider
private CredentialsRefreshService
credentialsRefreshService
private ErrorOnWriteListener
errorOnWriteListener
private java.util.concurrent.atomic.AtomicBoolean
finalShutdownStarted
private int
handshakeTimeout
private java.util.concurrent.ScheduledExecutorService
heartbeatExecutor
private java.lang.String
id
private java.lang.Thread
ioLoopThread
private java.util.concurrent.atomic.AtomicBoolean
ioLoopThreadSet
private static org.slf4j.Logger
LOGGER
private java.lang.Thread
mainLoopThread
private static int
MAX_UNSIGNED_SHORT
private int
maxInboundMessageBodySize
protected MetricsCollector
metricsCollector
protected ObservationCollector
observationCollector
private java.util.List<RecoveryCanBeginListener>
recoveryCanBeginListeners
private int
requestedChannelMax
private int
requestedFrameMax
private int
requestedHeartbeat
private SaslConfig
saslConfig
private java.util.concurrent.ExecutorService
shutdownExecutor
private int
shutdownTimeout
private static long
SOCKET_CLOSE_TIMEOUT
private java.util.concurrent.ThreadFactory
threadFactory
private TrafficListener
trafficListener
private int
workPoolTimeout
-
Constructor Summary
Constructors Constructor Description AMQConnection(ConnectionParams params, FrameHandler frameHandler)
AMQConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector, ObservationCollector observationCollector)
Construct a new connection
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
Public API - Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
abort(int timeout)
Public API - Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
abort(int closeCode, java.lang.String closeMessage)
Public API - Abort this connection and all its channels.void
abort(int closeCode, java.lang.String closeMessage, int timeout)
Public API - Abort this connection and all its channels.BlockedListener
addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback)
Add a lambda-basedBlockedListener
.void
addBlockedListener(BlockedListener listener)
Add aBlockedListener
.void
addRecoveryCanBeginListener(RecoveryCanBeginListener fn)
private static void
checkPreconditions()
Private API - check required preconditions and protocol invariantsprivate static boolean
checkUnsignedShort(int value)
void
clearBlockedListeners()
Remove allBlockedListener
s.void
close()
Public API - Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
close(int timeout)
Public API - Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'.void
close(int closeCode, java.lang.String closeMessage)
Public API - Close this connection and all its channels.void
close(int closeCode, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause)
Protected API - Delegates tothe six-argument close method
, passing -1 for the timeout, and false for the abort flag.void
close(int closeCode, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause, int timeout, boolean abort)
Protected API - Close this connection with the given code, message, source and timeout value for all the close operations to complete.void
close(int closeCode, java.lang.String closeMessage, int timeout)
Public API - Close this connection and all its channels.private void
closeMainLoopThreadIfNecessary()
protected void
configureChannelManager(ChannelManager channelManager)
(package private) ObservationCollector.ConnectionInfo
connectionInfo()
Channel
createChannel()
Public API - Create a new channel, using an internally allocated channel number.Channel
createChannel(int channelNumber)
Public API - Create a new channel, using the specified channel number if possible.(package private) AMQChannel
createChannel0()
static java.util.Map<java.lang.String,java.lang.Object>
defaultClientProperties()
Retrieve a copy of the default table of client properties that will be sent to the server during connection startup.void
disconnectChannel(ChannelN channel)
Protected API - respond, in the driver thread, to a ShutdownSignal.void
doFinalShutdown()
private APIprivate void
ensureIsOpen()
private void
finishShutdown(ShutdownSignalException sse)
void
flush()
Public API - flush the output buffersjava.net.InetAddress
getAddress()
Retrieve the host.int
getChannelMax()
Get the negotiated maximum channel number.int
getChannelRpcTimeout()
java.util.Map<java.lang.String,java.lang.Object>
getClientProperties()
Get a copy of the map of client properties sent to the serverjava.lang.String
getClientProvidedName()
Returns client-provided connection name, if any.ExceptionHandler
getExceptionHandler()
Protected API - retrieve the current ExceptionHandlerFrameHandler
getFrameHandler()
int
getFrameMax()
Get the negotiated maximum frame size.int
getHeartbeat()
Get the negotiated heartbeat interval.private java.lang.String
getHostAddress()
java.lang.String
getId()
Public API - Returns a unique ID for this connection.java.net.InetAddress
getLocalAddress()
Retrieve the local host.int
getLocalPort()
Retrieve the local port number.(package private) int
getMaxInboundMessageBodySize()
int
getPort()
Retrieve the port number.java.util.Map<java.lang.String,java.lang.Object>
getServerProperties()
Retrieve the server properties.java.util.concurrent.ThreadFactory
getThreadFactory()
TrafficListener
getTrafficListener()
void
handleConnectionClose(Command closeCommand)
private void
handleFailure(java.lang.Throwable ex)
void
handleHeartbeatFailure()
private APIvoid
handleIoError(java.lang.Throwable ex)
private APIboolean
handleReadFrame(Frame frame)
private APIprivate void
handleSocketTimeout()
Called when a frame-read operation times outboolean
hasBrokerInitiatedShutdown()
private void
initializeConsumerWorkService()
private void
initializeHeartbeatSender()
protected ChannelManager
instantiateChannelManager(int channelMax, java.util.concurrent.ThreadFactory threadFactory)
void
ioLoopThread(java.lang.Thread thread)
boolean
isRunning()
private boolean
mainLoopReadThreadNotNull()
protected int
negotiateChannelMax(int requestedChannelMax, int serverMax)
Private API, allows for easier simulation of bogus clients.private static int
negotiatedMaxValue(int clientValue, int serverValue)
private void
notifyRecoveryCanBeginListeners()
private boolean
notInMainLoopThread()
boolean
processControlCommand(Command c)
Handles incoming control commands on channel zero.private void
readFrame(Frame frame)
boolean
removeBlockedListener(BlockedListener listener)
Remove aBlockedListener
.void
removeRecoveryCanBeginListener(RecoveryCanBeginListener fn)
void
setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout.void
setId(java.lang.String id)
Public API - Sets a unique ID for this connection.void
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Makes it possible to override thread factory that is used to instantiate connection network I/O loop.ShutdownSignalException
shutdown(Method reason, boolean initiatedByApplication, java.lang.Throwable cause, boolean notifyRpc)
Protected API - causes all attached channels to terminate (shutdown) with a ShutdownSignal built from the argument, and stops this connection from accepting further work from the application.void
start()
Start up the connection, including the MainLoop thread.void
startMainLoop()
Package private API, allows for easier testing.private ShutdownSignalException
startShutdown(Method reason, boolean initiatedByApplication, java.lang.Throwable cause, boolean notifyRpc)
java.lang.String
toString()
boolean
willCheckRpcResponseType()
boolean
willShutDownConsumerExecutor()
Public APIvoid
writeFrame(Frame f)
Public API - sends a frame directly to the broker.-
Methods inherited from class com.rabbitmq.client.impl.ShutdownNotifierComponent
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener, setShutdownCauseIfOpen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.rabbitmq.client.Connection
openChannel, openChannel
-
Methods inherited from interface com.rabbitmq.client.ShutdownNotifier
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener
-
-
-
-
Field Detail
-
MAX_UNSIGNED_SHORT
private static final int MAX_UNSIGNED_SHORT
- See Also:
- Constant Field Values
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER
public static final double CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER
- See Also:
- Constant Field Values
-
consumerWorkServiceExecutor
private final java.util.concurrent.ExecutorService consumerWorkServiceExecutor
-
heartbeatExecutor
private final java.util.concurrent.ScheduledExecutorService heartbeatExecutor
-
shutdownExecutor
private final java.util.concurrent.ExecutorService shutdownExecutor
-
mainLoopThread
private java.lang.Thread mainLoopThread
-
ioLoopThreadSet
private final java.util.concurrent.atomic.AtomicBoolean ioLoopThreadSet
-
ioLoopThread
private volatile java.lang.Thread ioLoopThread
-
threadFactory
private java.util.concurrent.ThreadFactory threadFactory
-
id
private java.lang.String id
-
recoveryCanBeginListeners
private final java.util.List<RecoveryCanBeginListener> recoveryCanBeginListeners
-
errorOnWriteListener
private final ErrorOnWriteListener errorOnWriteListener
-
workPoolTimeout
private final int workPoolTimeout
-
finalShutdownStarted
private final java.util.concurrent.atomic.AtomicBoolean finalShutdownStarted
-
connectionInfo
private volatile ObservationCollector.ConnectionInfo connectionInfo
-
clientVersion
private static final Version clientVersion
-
_channel0
private final AMQChannel _channel0
The special channel 0 (not managed by the_channelManager
)
-
_workService
protected ConsumerWorkService _workService
-
_frameHandler
private final FrameHandler _frameHandler
Frame source/sink
-
_running
private volatile boolean _running
Flag controlling the main driver loop's termination
-
_exceptionHandler
private final ExceptionHandler _exceptionHandler
Handler for (uncaught) exceptions that crop up in theAMQConnection.MainLoop
.
-
_appContinuation
private final BlockingCell<java.lang.Object> _appContinuation
Object used for blocking main application thread when doing all the necessary connection shutdown operations
-
_brokerInitiatedShutdown
private volatile boolean _brokerInitiatedShutdown
Flag indicating whether the client received Connection.Close message from the broker
-
_inConnectionNegotiation
private volatile boolean _inConnectionNegotiation
Flag indicating we are still negotiating the connection in start
-
_heartbeatSender
private HeartbeatSender _heartbeatSender
Manages heart-beat sending for this connection
-
_virtualHost
private final java.lang.String _virtualHost
-
_clientProperties
private final java.util.Map<java.lang.String,java.lang.Object> _clientProperties
-
saslConfig
private final SaslConfig saslConfig
-
requestedHeartbeat
private final int requestedHeartbeat
-
requestedChannelMax
private final int requestedChannelMax
-
requestedFrameMax
private final int requestedFrameMax
-
handshakeTimeout
private final int handshakeTimeout
-
shutdownTimeout
private final int shutdownTimeout
-
credentialsProvider
private final CredentialsProvider credentialsProvider
-
blockedListeners
private final java.util.Collection<BlockedListener> blockedListeners
-
metricsCollector
protected final MetricsCollector metricsCollector
-
observationCollector
protected final ObservationCollector observationCollector
-
channelRpcTimeout
private final int channelRpcTimeout
-
channelShouldCheckRpcResponseType
private final boolean channelShouldCheckRpcResponseType
-
trafficListener
private final TrafficListener trafficListener
-
credentialsRefreshService
private final CredentialsRefreshService credentialsRefreshService
-
_frameMax
private volatile int _frameMax
Maximum frame length, or zero if no limit is set
-
_missedHeartbeats
private volatile int _missedHeartbeats
Count of socket-timeouts that have happened without any incoming frames
-
_heartbeat
private volatile int _heartbeat
Currently-configured heart-beat interval, in seconds. 0 meaning none.
-
_channelManager
private volatile ChannelManager _channelManager
Object that manages a set of channels
-
_serverProperties
private volatile java.util.Map<java.lang.String,java.lang.Object> _serverProperties
Saved server properties field from connection.start
-
maxInboundMessageBodySize
private final int maxInboundMessageBodySize
-
SOCKET_CLOSE_TIMEOUT
private static long SOCKET_CLOSE_TIMEOUT
-
-
Constructor Detail
-
AMQConnection
public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
-
AMQConnection
public AMQConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector, ObservationCollector observationCollector)
Construct a new connection- Parameters:
params
- parameters for it
-
-
Method Detail
-
defaultClientProperties
public static java.util.Map<java.lang.String,java.lang.Object> defaultClientProperties()
Retrieve a copy of the default table of client properties that will be sent to the server during connection startup. This method is called when each new ConnectionFactory instance is constructed.- Returns:
- a map of client properties
- See Also:
Connection.getClientProperties()
-
disconnectChannel
public final void disconnectChannel(ChannelN channel)
Protected API - respond, in the driver thread, to a ShutdownSignal.- Parameters:
channel
- the channel to disconnect
-
ensureIsOpen
private void ensureIsOpen() throws AlreadyClosedException
- Throws:
AlreadyClosedException
-
getAddress
public java.net.InetAddress getAddress()
Retrieve the host.- Specified by:
getAddress
in interfaceConnection
- Specified by:
getAddress
in interfaceNetworkConnection
- Returns:
- the hostname of the peer we're connected to.
-
getLocalAddress
public java.net.InetAddress getLocalAddress()
Description copied from interface:NetworkConnection
Retrieve the local host.- Specified by:
getLocalAddress
in interfaceNetworkConnection
- Returns:
- the client socket address.
-
getPort
public int getPort()
Retrieve the port number.- Specified by:
getPort
in interfaceConnection
- Specified by:
getPort
in interfaceNetworkConnection
- Returns:
- the port number of the peer we're connected to.
-
getLocalPort
public int getLocalPort()
Description copied from interface:NetworkConnection
Retrieve the local port number.- Specified by:
getLocalPort
in interfaceNetworkConnection
- Returns:
- the client socket port number
-
getFrameHandler
public FrameHandler getFrameHandler()
-
getServerProperties
public java.util.Map<java.lang.String,java.lang.Object> getServerProperties()
Retrieve the server properties.- Specified by:
getServerProperties
in interfaceConnection
- Returns:
- a map of the server properties. This typically includes the product name and version of the server.
-
createChannel0
AMQChannel createChannel0()
-
initializeConsumerWorkService
private void initializeConsumerWorkService()
-
initializeHeartbeatSender
private void initializeHeartbeatSender()
-
start
public void start() throws java.io.IOException, java.util.concurrent.TimeoutException
Start up the connection, including the MainLoop thread. Sends the protocol version negotiation header, and runs through Connection.Start/.StartOk, Connection.Tune/.TuneOk, and then calls Connection.Open and waits for the OpenOk. Sets heart-beat and frame max values after tuning has taken place.- Throws:
java.io.IOException
- if an error is encountered either before, or during, protocol negotiation; sub-classesProtocolVersionMismatchException
andPossibleAuthenticationFailureException
will be thrown in the corresponding circumstances.AuthenticationFailureException
will be thrown if the broker closes the connection with ACCESS_REFUSED. If an exception is thrown, connection resources allocated can all be garbage collected when the connection object is no longer referenced.java.util.concurrent.TimeoutException
-
instantiateChannelManager
protected ChannelManager instantiateChannelManager(int channelMax, java.util.concurrent.ThreadFactory threadFactory)
-
configureChannelManager
protected void configureChannelManager(ChannelManager channelManager)
-
startMainLoop
public void startMainLoop()
Package private API, allows for easier testing.
-
negotiateChannelMax
protected int negotiateChannelMax(int requestedChannelMax, int serverMax)
Private API, allows for easier simulation of bogus clients.
-
checkPreconditions
private static void checkPreconditions()
Private API - check required preconditions and protocol invariants
-
getChannelMax
public int getChannelMax()
Get the negotiated maximum channel number. Usable channel numbers range from 1 to this number, inclusive.- Specified by:
getChannelMax
in interfaceConnection
- Returns:
- the maximum channel number permitted for this connection.
-
getFrameMax
public int getFrameMax()
Get the negotiated maximum frame size.- Specified by:
getFrameMax
in interfaceConnection
- Returns:
- the maximum frame size, in octets; zero if unlimited
-
getHeartbeat
public int getHeartbeat()
Get the negotiated heartbeat interval.- Specified by:
getHeartbeat
in interfaceConnection
- Returns:
- the heartbeat interval, in seconds; zero if none
-
setHeartbeat
public void setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout. Should only be called during tuning.
-
setThreadFactory
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Makes it possible to override thread factory that is used to instantiate connection network I/O loop. Only necessary in the environments with restricted- Parameters:
threadFactory
- thread factory to use
-
getThreadFactory
public java.util.concurrent.ThreadFactory getThreadFactory()
- Returns:
- Thread factory used by this connection.
-
getClientProperties
public java.util.Map<java.lang.String,java.lang.Object> getClientProperties()
Description copied from interface:Connection
Get a copy of the map of client properties sent to the server- Specified by:
getClientProperties
in interfaceConnection
- Returns:
- a copy of the map of client properties
-
getClientProvidedName
public java.lang.String getClientProvidedName()
Description copied from interface:Connection
Returns client-provided connection name, if any. Note that the value returned does not uniquely identify a connection and cannot be used as a connection identifier in HTTP API requests.- Specified by:
getClientProvidedName
in interfaceConnection
- Returns:
- client-provided connection name, if any
- See Also:
ConnectionFactory.newConnection(Address[], String)
,ConnectionFactory.newConnection(ExecutorService, Address[], String)
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
Protected API - retrieve the current ExceptionHandler- Specified by:
getExceptionHandler
in interfaceConnection
- See Also:
ExceptionHandler
-
willShutDownConsumerExecutor
public boolean willShutDownConsumerExecutor()
Public API- Returns:
- true if this work service instance uses its own consumerWorkServiceExecutor (as opposed to a shared one)
-
createChannel
public Channel createChannel(int channelNumber) throws java.io.IOException
Public API - Create a new channel, using the specified channel number if possible.Use
Connection.openChannel(int)
if you want to use anOptional
to deal with a value.- Specified by:
createChannel
in interfaceConnection
- Parameters:
channelNumber
- the channel number to allocate- Returns:
- a new channel descriptor, or null if this channel number is already in use
- Throws:
java.io.IOException
- if an I/O problem is encountered
-
createChannel
public Channel createChannel() throws java.io.IOException
Public API - Create a new channel, using an internally allocated channel number. If automatic connection recovery is enabled, the channel returned by this method will beRecoverable
.Use
Connection.openChannel()
if you want to use anOptional
to deal with a value.- Specified by:
createChannel
in interfaceConnection
- Returns:
- a new channel descriptor, or null if none is available
- Throws:
java.io.IOException
- if an I/O problem is encountered
-
writeFrame
public void writeFrame(Frame f) throws java.io.IOException
Public API - sends a frame directly to the broker.- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Public API - flush the output buffers- Throws:
java.io.IOException
-
negotiatedMaxValue
private static int negotiatedMaxValue(int clientValue, int serverValue)
-
checkUnsignedShort
private static boolean checkUnsignedShort(int value)
-
handleReadFrame
public boolean handleReadFrame(Frame frame)
private API
-
isRunning
public boolean isRunning()
-
hasBrokerInitiatedShutdown
public boolean hasBrokerInitiatedShutdown()
-
readFrame
private void readFrame(Frame frame) throws java.io.IOException
- Throws:
java.io.IOException
-
handleHeartbeatFailure
public void handleHeartbeatFailure()
private API
-
handleIoError
public void handleIoError(java.lang.Throwable ex)
private API
-
handleFailure
private void handleFailure(java.lang.Throwable ex)
-
doFinalShutdown
public void doFinalShutdown()
private API
-
closeMainLoopThreadIfNecessary
private void closeMainLoopThreadIfNecessary()
-
notInMainLoopThread
private boolean notInMainLoopThread()
-
mainLoopReadThreadNotNull
private boolean mainLoopReadThreadNotNull()
-
notifyRecoveryCanBeginListeners
private void notifyRecoveryCanBeginListeners()
-
addRecoveryCanBeginListener
public void addRecoveryCanBeginListener(RecoveryCanBeginListener fn)
-
removeRecoveryCanBeginListener
public void removeRecoveryCanBeginListener(RecoveryCanBeginListener fn)
-
handleSocketTimeout
private void handleSocketTimeout() throws java.net.SocketTimeoutException
Called when a frame-read operation times out- Throws:
MissedHeartbeatException
- if heart-beats have been missedjava.net.SocketTimeoutException
-
processControlCommand
public boolean processControlCommand(Command c) throws java.io.IOException
Handles incoming control commands on channel zero.- Throws:
java.io.IOException
- See Also:
ChannelN.processAsync(com.rabbitmq.client.Command)
-
handleConnectionClose
public void handleConnectionClose(Command closeCommand)
-
shutdown
public ShutdownSignalException shutdown(Method reason, boolean initiatedByApplication, java.lang.Throwable cause, boolean notifyRpc)
Protected API - causes all attached channels to terminate (shutdown) with a ShutdownSignal built from the argument, and stops this connection from accepting further work from the application.ShutdownListener
s for the connection are notified when the main loop terminates.- Parameters:
reason
- description of reason for the exceptioninitiatedByApplication
- true if caused by a client commandcause
- trigger exception which caused shutdownnotifyRpc
- true if outstanding rpc should be informed of shutdown- Returns:
- a shutdown signal built using the given arguments
-
startShutdown
private ShutdownSignalException startShutdown(Method reason, boolean initiatedByApplication, java.lang.Throwable cause, boolean notifyRpc)
-
finishShutdown
private void finishShutdown(ShutdownSignalException sse)
-
close
public void close() throws java.io.IOException
Public API - Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. Waits for all the close operations to complete.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnection
- Throws:
java.io.IOException
- if an I/O problem is encountered
-
close
public void close(int timeout) throws java.io.IOException
Public API - Close this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. This method behaves in a similar way asConnection.close()
, with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
close
in interfaceConnection
- Parameters:
timeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- Throws:
java.io.IOException
- if an I/O problem is encountered
-
close
public void close(int closeCode, java.lang.String closeMessage) throws java.io.IOException
Public API - Close this connection and all its channels. Waits for all the close operations to complete.- Specified by:
close
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connection- Throws:
java.io.IOException
- if an I/O problem is encountered
-
close
public void close(int closeCode, java.lang.String closeMessage, int timeout) throws java.io.IOException
Public API - Close this connection and all its channels. Waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
close
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectiontimeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity- Throws:
java.io.IOException
- if an I/O problem is encountered
-
abort
public void abort()
Public API - Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. Forces the connection to close. Any encountered exceptions in the close operations are silently discarded.- Specified by:
abort
in interfaceConnection
-
abort
public void abort(int closeCode, java.lang.String closeMessage)
Public API - Abort this connection and all its channels. Forces the connection to close and waits for all the close operations to complete. Any encountered exceptions in the close operations are silently discarded.- Specified by:
abort
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connection
-
abort
public void abort(int timeout)
Public API - Abort this connection and all its channels with theAMQP.REPLY_SUCCESS
close code and message 'OK'. This method behaves in a similar way asConnection.abort()
, with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.- Specified by:
abort
in interfaceConnection
- Parameters:
timeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
-
abort
public void abort(int closeCode, java.lang.String closeMessage, int timeout)
Public API - Abort this connection and all its channels. Forces the connection to close and waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close. Any encountered exceptions in the close operations are silently discarded.- Specified by:
abort
in interfaceConnection
- Parameters:
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectiontimeout
- timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
-
close
public void close(int closeCode, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause) throws java.io.IOException
Protected API - Delegates tothe six-argument close method
, passing -1 for the timeout, and false for the abort flag.- Throws:
java.io.IOException
-
close
public void close(int closeCode, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause, int timeout, boolean abort) throws java.io.IOException
Protected API - Close this connection with the given code, message, source and timeout value for all the close operations to complete. Specifies if any encountered exceptions should be ignored.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getHostAddress
private java.lang.String getHostAddress()
-
addBlockedListener
public void addBlockedListener(BlockedListener listener)
Description copied from interface:Connection
Add aBlockedListener
.- Specified by:
addBlockedListener
in interfaceConnection
- Parameters:
listener
- the listener to add
-
addBlockedListener
public BlockedListener addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback)
Description copied from interface:Connection
Add a lambda-basedBlockedListener
.- Specified by:
addBlockedListener
in interfaceConnection
- Parameters:
blockedCallback
- the callback when the connection is blockedunblockedCallback
- the callback when the connection is unblocked- Returns:
- the listener that wraps the callback
- See Also:
BlockedListener
,BlockedCallback
,UnblockedCallback
-
removeBlockedListener
public boolean removeBlockedListener(BlockedListener listener)
Description copied from interface:Connection
Remove aBlockedListener
.- Specified by:
removeBlockedListener
in interfaceConnection
- Parameters:
listener
- the listener to remove- Returns:
true
if the listener was found and removed,false
otherwise
-
clearBlockedListeners
public void clearBlockedListeners()
Description copied from interface:Connection
Remove allBlockedListener
s.- Specified by:
clearBlockedListeners
in interfaceConnection
-
getId
public java.lang.String getId()
Public API - Returns a unique ID for this connection. This ID must be unique, otherwise some services like the metrics collector won't work properly. This ID doesn't have to be provided by the client, services that require it will be assigned automatically if not set.- Specified by:
getId
in interfaceConnection
- Returns:
- unique ID for this connection.
-
setId
public void setId(java.lang.String id)
Public API - Sets a unique ID for this connection. This ID must be unique, otherwise some services like the metrics collector won't work properly. This ID doesn't have to be provided by the client, services that require it will be assigned automatically if not set.- Specified by:
setId
in interfaceConnection
-
ioLoopThread
public void ioLoopThread(java.lang.Thread thread)
-
getChannelRpcTimeout
public int getChannelRpcTimeout()
-
willCheckRpcResponseType
public boolean willCheckRpcResponseType()
-
getTrafficListener
public TrafficListener getTrafficListener()
-
getMaxInboundMessageBodySize
int getMaxInboundMessageBodySize()
-
connectionInfo
ObservationCollector.ConnectionInfo connectionInfo()
-
-