public class AMQConnection extends ShutdownNotifierComponent implements Connection, NetworkConnection
To create a broker connection, use ConnectionFactory
. See Connection
for an example.
Modifier and Type | Field and Description |
---|---|
protected ConsumerWorkService |
_workService |
static double |
CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER |
protected MetricsCollector |
metricsCollector |
Constructor and Description |
---|
AMQConnection(ConnectionParams params,
FrameHandler frameHandler) |
AMQConnection(ConnectionParams params,
FrameHandler frameHandler,
MetricsCollector metricsCollector)
Construct a new connection
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Public API - Abort this connection and all its channels
with the
AMQP.REPLY_SUCCESS close code
and message 'OK'. |
void |
abort(int timeout)
Public API - Abort this connection and all its channels
with the
AMQP.REPLY_SUCCESS close code
and message 'OK'. |
void |
abort(int closeCode,
String closeMessage)
Public API - Abort this connection and all its channels.
|
void |
abort(int closeCode,
String closeMessage,
int timeout)
Public API - Abort this connection and all its channels.
|
BlockedListener |
addBlockedListener(BlockedCallback blockedCallback,
UnblockedCallback unblockedCallback)
Add a lambda-based
BlockedListener . |
void |
addBlockedListener(BlockedListener listener)
Add a
BlockedListener . |
void |
addRecoveryCanBeginListener(RecoveryCanBeginListener fn) |
void |
clearBlockedListeners()
Remove all
BlockedListener s. |
void |
close()
Public API - Close this connection and all its channels
with the
AMQP.REPLY_SUCCESS close code
and message 'OK'. |
void |
close(int timeout)
Public API - Close this connection and all its channels
with the
AMQP.REPLY_SUCCESS close code
and message 'OK'. |
void |
close(int closeCode,
String closeMessage)
Public API - Close this connection and all its channels.
|
void |
close(int closeCode,
String closeMessage,
boolean initiatedByApplication,
Throwable cause)
Protected API - Delegates to
the
six-argument close method , passing -1 for the timeout, and
false for the abort flag. |
void |
close(int closeCode,
String closeMessage,
boolean initiatedByApplication,
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,
String closeMessage,
int timeout)
Public API - Close this connection and all its channels.
|
protected void |
configureChannelManager(ChannelManager channelManager) |
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.
|
static Map<String,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 API
|
void |
flush()
Public API - flush the output buffers
|
InetAddress |
getAddress()
Retrieve the host.
|
int |
getChannelMax()
Get the negotiated maximum channel number.
|
int |
getChannelRpcTimeout() |
Map<String,Object> |
getClientProperties()
Get a copy of the map of client properties sent to the server
|
String |
getClientProvidedName()
Returns client-provided connection name, if any.
|
ExceptionHandler |
getExceptionHandler()
Protected API - retrieve the current ExceptionHandler
|
FrameHandler |
getFrameHandler() |
int |
getFrameMax()
Get the negotiated maximum frame size.
|
int |
getHeartbeat()
Get the negotiated heartbeat interval.
|
String |
getId()
Public API - Returns a unique ID for this connection.
|
InetAddress |
getLocalAddress()
Retrieve the local host.
|
int |
getLocalPort()
Retrieve the local port number.
|
int |
getPort()
Retrieve the port number.
|
Map<String,Object> |
getServerProperties()
Retrieve the server properties.
|
ThreadFactory |
getThreadFactory() |
TrafficListener |
getTrafficListener() |
void |
handleConnectionClose(Command closeCommand) |
void |
handleHeartbeatFailure()
private API
|
void |
handleIoError(Throwable ex)
private API
|
boolean |
handleReadFrame(Frame frame)
private API
|
boolean |
hasBrokerInitiatedShutdown() |
protected ChannelManager |
instantiateChannelManager(int channelMax,
ThreadFactory threadFactory) |
boolean |
isRunning() |
protected int |
negotiateChannelMax(int requestedChannelMax,
int serverMax)
Private API, allows for easier simulation of bogus clients.
|
boolean |
processControlCommand(Command c)
Handles incoming control commands on channel zero.
|
boolean |
removeBlockedListener(BlockedListener listener)
Remove a
BlockedListener . |
void |
removeRecoveryCanBeginListener(RecoveryCanBeginListener fn) |
void |
setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout.
|
void |
setId(String id)
Public API - Sets a unique ID for this connection.
|
void |
setThreadFactory(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,
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.
|
String |
toString() |
boolean |
willCheckRpcResponseType() |
boolean |
willShutDownConsumerExecutor()
Public API
|
void |
writeFrame(Frame f)
Public API - sends a frame directly to the broker.
|
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener, setShutdownCauseIfOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
openChannel, openChannel
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener
public static final double CHANNEL_SHUTDOWN_TIMEOUT_MULTIPLIER
protected ConsumerWorkService _workService
protected final MetricsCollector metricsCollector
public AMQConnection(ConnectionParams params, FrameHandler frameHandler)
public AMQConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector)
params
- parameters for itpublic static Map<String,Object> defaultClientProperties()
Connection.getClientProperties()
public final void disconnectChannel(ChannelN channel)
channel
- the channel to disconnectpublic InetAddress getAddress()
getAddress
in interface Connection
getAddress
in interface NetworkConnection
public InetAddress getLocalAddress()
NetworkConnection
getLocalAddress
in interface NetworkConnection
public int getPort()
getPort
in interface Connection
getPort
in interface NetworkConnection
public int getLocalPort()
NetworkConnection
getLocalPort
in interface NetworkConnection
public FrameHandler getFrameHandler()
public Map<String,Object> getServerProperties()
getServerProperties
in interface Connection
public void start() throws IOException, TimeoutException
IOException
- if an error is encountered
either before, or during, protocol negotiation;
sub-classes ProtocolVersionMismatchException
and
PossibleAuthenticationFailureException
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.TimeoutException
protected ChannelManager instantiateChannelManager(int channelMax, ThreadFactory threadFactory)
protected void configureChannelManager(ChannelManager channelManager)
public void startMainLoop()
protected int negotiateChannelMax(int requestedChannelMax, int serverMax)
public int getChannelMax()
getChannelMax
in interface Connection
public int getFrameMax()
getFrameMax
in interface Connection
public int getHeartbeat()
getHeartbeat
in interface Connection
public void setHeartbeat(int heartbeat)
public void setThreadFactory(ThreadFactory threadFactory)
threadFactory
- thread factory to usepublic ThreadFactory getThreadFactory()
public Map<String,Object> getClientProperties()
Connection
getClientProperties
in interface Connection
public String getClientProvidedName()
Connection
getClientProvidedName
in interface Connection
ConnectionFactory.newConnection(Address[], String)
,
ConnectionFactory.newConnection(ExecutorService, Address[], String)
public ExceptionHandler getExceptionHandler()
getExceptionHandler
in interface Connection
ExceptionHandler
public boolean willShutDownConsumerExecutor()
public Channel createChannel(int channelNumber) throws IOException
Use Connection.openChannel(int)
if you want to use an Optional
to deal
with a value.
createChannel
in interface Connection
channelNumber
- the channel number to allocateIOException
- if an I/O problem is encounteredpublic Channel createChannel() throws IOException
Recoverable
.
Use Connection.openChannel()
if you want to use an Optional
to deal
with a value.
createChannel
in interface Connection
IOException
- if an I/O problem is encounteredpublic void writeFrame(Frame f) throws IOException
IOException
public void flush() throws IOException
IOException
public boolean handleReadFrame(Frame frame)
public boolean isRunning()
public boolean hasBrokerInitiatedShutdown()
public void handleHeartbeatFailure()
public void handleIoError(Throwable ex)
public void doFinalShutdown()
public void addRecoveryCanBeginListener(RecoveryCanBeginListener fn)
public void removeRecoveryCanBeginListener(RecoveryCanBeginListener fn)
public boolean processControlCommand(Command c) throws IOException
IOException
ChannelN.processAsync(com.rabbitmq.client.Command)
public void handleConnectionClose(Command closeCommand)
public ShutdownSignalException shutdown(Method reason, boolean initiatedByApplication, Throwable cause, boolean notifyRpc)
ShutdownListener
s for the
connection are notified when the main loop terminates.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 shutdownpublic void close() throws IOException
AMQP.REPLY_SUCCESS
close code
and message 'OK'.
Waits for all the close operations to complete.close
in interface Connection
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if an I/O problem is encounteredpublic void close(int timeout) throws IOException
AMQP.REPLY_SUCCESS
close code
and message 'OK'.
This method behaves in a similar way as Connection.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.close
in interface Connection
timeout
- timeout (in milliseconds) for completing all the close-related
operations, use -1 for infinityIOException
- if an I/O problem is encounteredpublic void close(int closeCode, String closeMessage) throws IOException
close
in interface Connection
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectionIOException
- if an I/O problem is encounteredpublic void close(int closeCode, String closeMessage, int timeout) throws IOException
close
in interface Connection
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 infinityIOException
- if an I/O problem is encounteredpublic void abort()
AMQP.REPLY_SUCCESS
close code
and message 'OK'.
Forces the connection to close.
Any encountered exceptions in the close operations are silently discarded.abort
in interface Connection
public void abort(int closeCode, String closeMessage)
abort
in interface Connection
closeCode
- the close code (See under "Reply Codes" in the AMQP specification)closeMessage
- a message indicating the reason for closing the connectionpublic void abort(int timeout)
AMQP.REPLY_SUCCESS
close code
and message 'OK'.
This method behaves in a similar way as Connection.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.abort
in interface Connection
timeout
- timeout (in milliseconds) for completing all the close-related
operations, use -1 for infinitypublic void abort(int closeCode, String closeMessage, int timeout)
abort
in interface Connection
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 infinitypublic void close(int closeCode, String closeMessage, boolean initiatedByApplication, Throwable cause) throws IOException
the
six-argument close method
, passing -1 for the timeout, and
false for the abort flag.IOException
public void close(int closeCode, String closeMessage, boolean initiatedByApplication, Throwable cause, int timeout, boolean abort) throws IOException
IOException
public void addBlockedListener(BlockedListener listener)
Connection
BlockedListener
.addBlockedListener
in interface Connection
listener
- the listener to addpublic BlockedListener addBlockedListener(BlockedCallback blockedCallback, UnblockedCallback unblockedCallback)
Connection
BlockedListener
.addBlockedListener
in interface Connection
blockedCallback
- the callback when the connection is blockedunblockedCallback
- the callback when the connection is unblockedBlockedListener
,
BlockedCallback
,
UnblockedCallback
public boolean removeBlockedListener(BlockedListener listener)
Connection
BlockedListener
.removeBlockedListener
in interface Connection
listener
- the listener to removetrue
if the listener was found and removed,
false
otherwisepublic void clearBlockedListeners()
Connection
BlockedListener
s.clearBlockedListeners
in interface Connection
public String getId()
getId
in interface Connection
public void setId(String id)
setId
in interface Connection
public int getChannelRpcTimeout()
public boolean willCheckRpcResponseType()
public TrafficListener getTrafficListener()
Copyright © 2022 VMware, Inc. or its affiliates.. All rights reserved.