|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.rabbitmq.client.impl.ShutdownNotifierComponent
com.rabbitmq.client.impl.AMQConnection
public class AMQConnection
Concrete class representing and managing an AMQP connection to a broker.
To connect to a broker,
AMQConnection conn = new AMQConnection(hostName, portNumber); conn.open(userName, portNumber, virtualHost);
ChannelN ch1 = conn.createChannel(1); ch1.open("");
Field Summary | |
---|---|
BlockingCell<java.lang.Object> |
_appContinuation
Object used for blocking main application thread when doing all the necessary connection shutdown operations |
boolean |
_brokerInitiatedShutdown
Flag indicating whether the client received Connection.Close message from the broker |
AMQChannel |
_channel0
The special channel 0 |
ChannelManager |
_channelManager
Object that manages a set of channels |
ExceptionHandler |
_exceptionHandler
Handler for (otherwise-unhandled) exceptions that crop up in the mainloop. |
FrameHandler |
_frameHandler
Frame source/sink |
int |
_frameMax
Maximum frame length, or zero if no limit is set |
int |
_heartbeat
Currently-configured heartbeat interval, in seconds. |
Address[] |
_knownHosts
Hosts retrieved from the connection.open-ok |
long |
_lastActivityTime
Timestamp of last time we wrote a frame - used for deciding when to send a heartbeat |
int |
_missedHeartbeats
Count of socket-timeouts that have happened without any incoming frames |
ConnectionParameters |
_params
Initialization parameters |
boolean |
_running
Flag controlling the main driver loop's termination |
static int |
CONNECTION_CLOSING_TIMEOUT
Timeout used while waiting for a connection.close-ok (milliseconds) |
static int |
HANDSHAKE_TIMEOUT
Timeout used while waiting for AMQP handshaking to complete (milliseconds) |
Fields inherited from class com.rabbitmq.client.impl.ShutdownNotifierComponent |
---|
_shutdownCause, listeners |
Constructor Summary | |
---|---|
AMQConnection(ConnectionParameters params,
FrameHandler frameHandler)
Construct a new connection to a broker. |
|
AMQConnection(ConnectionParameters params,
FrameHandler frameHandler,
ExceptionHandler exceptionHandler)
Construct a new connection to a broker. |
Method Summary | |
---|---|
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,
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. |
java.util.Map<java.lang.String,java.lang.Object> |
buildClientPropertiesTable()
|
void |
checkPreconditions()
Private API - check required preconditions and protocol invariants |
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,
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 to the
six-argument close method , passing 0 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. |
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. |
void |
disconnectChannel(int channelNumber)
Protected API - respond, in the driver thread, to a ShutdownSignal. |
void |
ensureIsOpen()
|
int |
getChannelMax()
Get the negotiated maximum channel number. |
ExceptionHandler |
getExceptionHandler()
Protected API - retrieve the current ExceptionHandler |
int |
getFrameMax()
Get the negotiated maximum frame size. |
int |
getHeartbeat()
Get the negotiated heartbeat interval. |
java.lang.String |
getHost()
Retrieve the host. |
Address[] |
getKnownHosts()
Retrieve the known hosts. |
ConnectionParameters |
getParameters()
Retrieve the connection parameters. |
int |
getPort()
Retrieve the port number. |
void |
handleConnectionClose(Command closeCommand)
|
void |
handleSocketTimeout()
Private API - Called when a frame-read operation times out. |
void |
maybeSendHeartbeat()
Private API - Checks lastActivityTime and heartbeat, sending a heartbeat frame if conditions are right. |
boolean |
processControlCommand(Command c)
Handles incoming control commands on channel zero. |
Frame |
readFrame()
Private API - reads a single frame from the connection to the broker, or returns null if the read times out. |
void |
setFrameMax(int value)
Protected API - set the max frame size. |
void |
setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout. |
ShutdownSignalException |
shutdown(java.lang.Object reason,
boolean initiatedByApplication,
java.lang.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(boolean insist)
Start up the connection, including the MainLoop thread. |
java.lang.String |
toString()
|
void |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.rabbitmq.client.ShutdownNotifier |
---|
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener |
Field Detail |
---|
public static final int HANDSHAKE_TIMEOUT
public static final int CONNECTION_CLOSING_TIMEOUT
public final ConnectionParameters _params
public final AMQChannel _channel0
public ChannelManager _channelManager
public final FrameHandler _frameHandler
public volatile boolean _running
public int _frameMax
public final ExceptionHandler _exceptionHandler
public BlockingCell<java.lang.Object> _appContinuation
public boolean _brokerInitiatedShutdown
public volatile long _lastActivityTime
public int _missedHeartbeats
public int _heartbeat
public Address[] _knownHosts
Constructor Detail |
---|
public AMQConnection(ConnectionParameters params, FrameHandler frameHandler)
params
- the initialization parameters for a connectionframeHandler
- interface to an object that will handle the frame I/O for this connectionpublic AMQConnection(ConnectionParameters params, FrameHandler frameHandler, ExceptionHandler exceptionHandler)
params
- the initialization parameters for a connectionframeHandler
- interface to an object that will handle the frame I/O for this connectionexceptionHandler
- interface to an object that will handle any special exceptions encountered while using this connectionMethod Detail |
---|
public final void disconnectChannel(int channelNumber)
channelNumber
- the number of the channel to disconnectpublic void ensureIsOpen() throws AlreadyClosedException
AlreadyClosedException
public java.lang.String getHost()
getHost
in interface Connection
public int getPort()
getPort
in interface Connection
public ConnectionParameters getParameters()
getParameters
in interface Connection
public Address[] getKnownHosts()
getKnownHosts
in interface Connection
AMQP.Connection.OpenOk
open-ok methodpublic void start(boolean insist) throws java.io.IOException, RedirectException
insist
- true if broker redirects are disallowed
RedirectException
- if the server is redirecting us to a different host/port
java.io.IOException
- if an error is encounteredpublic void checkPreconditions()
public int getChannelMax()
Connection.getParameters()
.ConnectionParameters.getRequestedChannelMax()
.
getChannelMax
in interface Connection
public int getFrameMax()
Connection.getParameters()
.ConnectionParameters.getRequestedFrameMax()
.
getFrameMax
in interface Connection
public void setFrameMax(int value)
public int getHeartbeat()
Connection.getParameters()
.ConnectionParameters.getRequestedHeartbeat()
.
getHeartbeat
in interface Connection
public void setHeartbeat(int heartbeat)
public ExceptionHandler getExceptionHandler()
public Channel createChannel(int channelNumber) throws java.io.IOException
createChannel
in interface Connection
channelNumber
- the channel number to allocate
java.io.IOException
- if an I/O problem is encounteredpublic Channel createChannel() throws java.io.IOException
createChannel
in interface Connection
java.io.IOException
- if an I/O problem is encounteredpublic Frame readFrame() throws java.io.IOException
java.io.IOException
public void writeFrame(Frame f) throws java.io.IOException
java.io.IOException
public java.util.Map<java.lang.String,java.lang.Object> buildClientPropertiesTable()
public void maybeSendHeartbeat() throws java.io.IOException
java.io.IOException
public void handleSocketTimeout() throws MissedHeartbeatException
MissedHeartbeatException
- if too many silent timeouts have gone bypublic boolean processControlCommand(Command c) throws java.io.IOException
java.io.IOException
public void handleConnectionClose(Command closeCommand)
public ShutdownSignalException shutdown(java.lang.Object reason, boolean initiatedByApplication, java.lang.Throwable cause, boolean notifyRpc)
public void close() throws java.io.IOException
AMQP.REPLY_SUCCESS
close code
and message 'OK'.
Waits for all the close operations to complete.
close
in interface Connection
java.io.IOException
- if an I/O problem is encounteredpublic void close(int timeout) throws java.io.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 infinity
java.io.IOException
- if an I/O problem is encounteredpublic void close(int closeCode, java.lang.String closeMessage) throws java.io.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 connection
java.io.IOException
- if an I/O problem is encounteredpublic void close(int closeCode, java.lang.String closeMessage, int timeout) throws java.io.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 infinity
java.io.IOException
- 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, java.lang.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, java.lang.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, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause) throws java.io.IOException
the
six-argument close method
, passing 0 for the timeout, and
false for the abort flag.
java.io.IOException
public void close(int closeCode, java.lang.String closeMessage, boolean initiatedByApplication, java.lang.Throwable cause, int timeout, boolean abort) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |