public class

AMQConnection

extends ShutdownNotifierComponent
implements Connection
java.lang.Object
   ↳ com.rabbitmq.client.impl.ShutdownNotifierComponent
     ↳ com.rabbitmq.client.impl.AMQConnection

Class Overview

Concrete class representing and managing an AMQP connection to a broker.

To create a broker connection, use ConnectionFactory. See Connection for an example.

Summary

Constants
int HANDSHAKE_TIMEOUT Timeout used while waiting for AMQP handshaking to complete (milliseconds)
Public Constructors
AMQConnection(String username, String password, FrameHandler frameHandler, ExecutorService executor, String virtualHost, Map<StringObject> clientProperties, int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat, SaslConfig saslConfig)
Construct a new connection using a default ExeceptionHandler
AMQConnection(String username, String password, FrameHandler frameHandler, ExecutorService executor, String virtualHost, Map<StringObject> clientProperties, int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat, SaslConfig saslConfig, ExceptionHandler execeptionHandler)
Construct a new connection
Public Methods
void abort(int closeCode, String closeMessage, int timeout)
Public API - Abort this connection and all its channels.
void abort(int closeCode, String closeMessage)
Public API - Abort this connection and all its channels.
void abort(int timeout)
Public API - Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
void abort()
Public API - Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
void close(int closeCode, String closeMessage)
Public API - Close this connection and all its channels.
void close()
Public API - Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
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 timeout)
Public API - Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
void close(int closeCode, String closeMessage, int timeout)
Public API - Close this connection and all its channels.
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.
final static Map<StringObject> defaultClientProperties()
Retrieve a copy of the default table of client properties that will be sent to the server during connection startup.
final void disconnectChannel(ChannelN channel)
Protected API - respond, in the driver thread, to a ShutdownSignal.
InetAddress getAddress()
Retrieve the host.
int getChannelMax()
Get the negotiated maximum channel number.
Map<StringObject> getClientProperties()
Get a copy of the map of client properties sent to the server
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.
int getPort()
Retrieve the port number.
Map<StringObject> getServerProperties()
Retrieve the server properties.
void handleConnectionClose(Command closeCommand)
boolean processControlCommand(Command c)
Handles incoming control commands on channel zero.
void setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout.
ShutdownSignalException shutdown(Object reason, boolean initiatedByApplication, Throwable cause, boolean notifyRpc)
Protected API - causes all attached channels to terminate 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.
String toString()
void writeFrame(Frame f)
Public API - sends a frame directly to the broker.
[Expand]
Inherited Methods
From class com.rabbitmq.client.impl.ShutdownNotifierComponent
From class java.lang.Object
From interface com.rabbitmq.client.Connection
From interface com.rabbitmq.client.ShutdownNotifier

Constants

public static final int HANDSHAKE_TIMEOUT

Timeout used while waiting for AMQP handshaking to complete (milliseconds)

Constant Value: 10000 (0x00002710)

Public Constructors

public AMQConnection (String username, String password, FrameHandler frameHandler, ExecutorService executor, String virtualHost, Map<StringObject> clientProperties, int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat, SaslConfig saslConfig)

Construct a new connection using a default ExeceptionHandler

Parameters
username name used to establish connection
password for username
frameHandler for sending and receiving frames on this connection
executor thread pool service for consumer threads for channels on this connection
clientProperties client info used in negotiating with the server
requestedFrameMax max size of frame offered
requestedChannelMax max number of channels offered
requestedHeartbeat heart-beat in seconds offered
saslConfig sasl configuration hook

public AMQConnection (String username, String password, FrameHandler frameHandler, ExecutorService executor, String virtualHost, Map<StringObject> clientProperties, int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat, SaslConfig saslConfig, ExceptionHandler execeptionHandler)

Construct a new connection

Parameters
username name used to establish connection
password for username
frameHandler for sending and receiving frames on this connection
executor thread pool service for consumer threads for channels on this connection
clientProperties client info used in negotiating with the server
requestedFrameMax max size of frame offered
requestedChannelMax max number of channels offered
requestedHeartbeat heart-beat in seconds offered
saslConfig sasl configuration hook
execeptionHandler handler for exceptions using this connection

Public Methods

public void abort (int closeCode, 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.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity

public void abort (int closeCode, 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.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection

public void abort (int timeout)

Public API - Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. This method behaves in a similar way as 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.

Parameters
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity

public void abort ()

Public API - Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. Forces the connection to close. Any encountered exceptions in the close operations are silently discarded.

public void close (int closeCode, String closeMessage)

Public API - Close this connection and all its channels. Waits for all the close operations to complete.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
Throws
IOException

public void close ()

Public API - Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. Waits for all the close operations to complete.

Throws
IOException

public 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.

Throws
IOException

public 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. Specifies if any encountered exceptions should be ignored.

Throws
IOException

public void close (int timeout)

Public API - Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. This method behaves in a similar way as 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.

Parameters
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
Throws
IOException

public void close (int closeCode, String closeMessage, int timeout)

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.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
Throws
IOException

public Channel createChannel ()

Public API - Create a new channel, using an internally allocated channel number.

Returns
  • a new channel descriptor, or null if none is available
Throws
IOException

public Channel createChannel (int channelNumber)

Public API - Create a new channel, using the specified channel number if possible.

Parameters
channelNumber the channel number to allocate
Returns
  • a new channel descriptor, or null if this channel number is already in use
Throws
IOException

public static final Map<StringObject> 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

public final void disconnectChannel (ChannelN channel)

Protected API - respond, in the driver thread, to a ShutdownSignal.

Parameters
channel the channel to disconnect

public InetAddress getAddress ()

Retrieve the host.

Returns
  • the hostname of the peer we're connected to.

public int getChannelMax ()

Get the negotiated maximum channel number. Usable channel numbers range from 1 to this number, inclusive.

Returns
  • the maximum channel number permitted for this connection.

public Map<StringObject> getClientProperties ()

Get a copy of the map of client properties sent to the server

Returns
  • a copy of the map of client properties

public ExceptionHandler getExceptionHandler ()

Protected API - retrieve the current ExceptionHandler

public FrameHandler getFrameHandler ()

public int getFrameMax ()

Get the negotiated maximum frame size.

Returns
  • the maximum frame size, in octets; zero if unlimited

public int getHeartbeat ()

Get the negotiated heartbeat interval.

Returns
  • the heartbeat interval, in seconds; zero if none

public int getPort ()

Retrieve the port number.

Returns
  • the port number of the peer we're connected to.

public Map<StringObject> getServerProperties ()

Retrieve the server properties.

Returns
  • a map of the server properties. This typically includes the product name and version of the server.

public void handleConnectionClose (Command closeCommand)

public boolean processControlCommand (Command c)

Handles incoming control commands on channel zero.

Throws
IOException

public void setHeartbeat (int heartbeat)

Protected API - set the heartbeat timeout. Should only be called during tuning.

public ShutdownSignalException shutdown (Object reason, boolean initiatedByApplication, Throwable cause, boolean notifyRpc)

Protected API - causes all attached channels to terminate with a ShutdownSignal built from the argument, and stops this connection from accepting further work from the application.

Returns
  • a shutdown signal built using the given arguments

public void start ()

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
IOException if an error is encountered either before, or during, protocol negotiation; sub-classes ProtocolVersionMismatchException and PossibleAuthenticationFailureException will be thrown in the corresponding circumstances. If an exception is thrown, connection resources allocated can all be garbage collected when the connection object is no longer referenced.

public String toString ()

public void writeFrame (Frame f)

Public API - sends a frame directly to the broker.

Throws
IOException