|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.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);Then open a channel and retrieve an access ticket:
ChannelN ch1 = conn.createChannel(1);
ch1.open("");
int ticket = ch1.accessRequest(realmName);
| Field Summary | |
|---|---|
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 |
ShutdownSignalException |
_shutdownCause
When this value is null, the connection is in an "open" state. |
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) |
| Constructor Summary | |
|---|---|
AMQConnection(ConnectionParameters params,
boolean insist,
FrameHandler frameHandler)
Construct a new connection to a broker. |
|
AMQConnection(ConnectionParameters params,
boolean insist,
FrameHandler frameHandler,
ExceptionHandler exceptionHandler)
Construct a new connection to a broker. |
|
| Method Summary | |
|---|---|
java.util.Map<java.lang.String,java.lang.Object> |
buildClientPropertiesTable()
|
void |
checkPreconditions()
Private API - check required preconditions and protocol invariants |
void |
close(int closeCode,
java.lang.String closeMessage)
Public API - Close this connection with the given code and message. |
void |
close(int closeCode,
java.lang.String closeMessage,
boolean initiatedByApplication,
java.lang.Throwable cause)
Protected API - Close this connection with the given code, message and source. |
Channel |
createChannel()
Public API - creates a new channel using an internally allocated channel number. |
Channel |
createChannel(int channelNumber)
Public API - creates a new channel using the specified channel number. |
void |
disconnectChannel(int channelNumber)
Protected API - respond, in the driver thread, to a ShutdownSignal. |
void |
ensureIsOpen()
|
int |
getChannelMax()
Get the negotiated maximum number of channels allowed. |
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. |
boolean |
isOpen()
|
void |
maybeSendHeartbeat()
Private API - Checks lastActivityTime and heartbeat, sending a heartbeat frame if conditions are right. |
Address[] |
open(ConnectionParameters params,
boolean insist)
Called by the connection's constructor. |
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 |
setChannelMax(int value)
Protected API - set the max number of channels available |
void |
setFrameMax(int value)
Protected API - set the max frame size. |
void |
setHeartbeat(int heartbeat)
Protected API - set the heartbeat timeout. |
void |
shutdown(java.lang.Object reason,
boolean initiatedByApplication,
java.lang.Throwable cause)
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. |
java.lang.String |
toString()
|
void |
writeFrame(Frame f)
Public API - sends a frame directly to the broker. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int HANDSHAKE_TIMEOUT
public static final int CONNECTION_CLOSING_TIMEOUT
public final ConnectionParameters _params
public final AMQChannel _channel0
public final ChannelManager _channelManager
public final FrameHandler _frameHandler
public volatile boolean _running
public volatile ShutdownSignalException _shutdownCause
public int _frameMax
public final ExceptionHandler _exceptionHandler
public volatile long _lastActivityTime
public int _missedHeartbeats
public int _heartbeat
public Address[] _knownHosts
| Constructor Detail |
|---|
public AMQConnection(ConnectionParameters params,
boolean insist,
FrameHandler frameHandler)
throws RedirectException,
java.io.IOException
params - the initialization parameters for a connectioninsist - true if broker redirects are disallowedframeHandler - interface to an object that will handle the frame I/O for this connection
RedirectException - if the server is redirecting us to a different host/port
java.io.IOException - if an error is encountered
public AMQConnection(ConnectionParameters params,
boolean insist,
FrameHandler frameHandler,
ExceptionHandler exceptionHandler)
throws RedirectException,
java.io.IOException
params - the initialization parameters for a connectioninsist - true if broker redirects are disallowedframeHandler - 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 connection
RedirectException - if the server is redirecting us to a different host/port
java.io.IOException - if an error is encountered| Method Detail |
|---|
public final void disconnectChannel(int channelNumber)
channelNumber - the number of the channel to disconnectpublic boolean isOpen()
public void ensureIsOpen()
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionpublic java.lang.String getHost()
Connection
getHost in interface Connectionpublic int getPort()
Connection
getPort in interface Connectionpublic ConnectionParameters getParameters()
Connection
getParameters in interface Connectionpublic Address[] getKnownHosts()
Connection
getKnownHosts in interface ConnectionAMQP.Connection.OpenOk open-ok methodpublic void checkPreconditions()
public int getChannelMax()
ConnectionConnection.getParameters().ConnectionParameters.getRequestedChannelMax().
getChannelMax in interface ConnectionConnection.getChannelMax()public void setChannelMax(int value)
public int getFrameMax()
ConnectionConnection.getParameters().ConnectionParameters.getRequestedFrameMax().
getFrameMax in interface ConnectionConnection.getFrameMax()public void setFrameMax(int value)
public int getHeartbeat()
ConnectionConnection.getParameters().ConnectionParameters.getRequestedHeartbeat().
getHeartbeat in interface ConnectionConnection.getHeartbeat()public void setHeartbeat(int heartbeat)
public ExceptionHandler getExceptionHandler()
public Channel createChannel(int channelNumber)
throws java.io.IOException
createChannel in interface ConnectionchannelNumber - the channel number to allocate
java.io.IOException - if an I/O problem is encountered
public Channel createChannel()
throws java.io.IOException
createChannel in interface Connectionjava.io.IOException - if an I/O problem is encountered
public Frame readFrame()
throws java.io.IOException
java.io.IOException
public void writeFrame(Frame f)
throws java.io.IOException
java.io.IOExceptionpublic java.util.Map<java.lang.String,java.lang.Object> buildClientPropertiesTable()
public Address[] open(ConnectionParameters params,
boolean insist)
throws RedirectException,
java.io.IOException
params - the construction parameters for a Connection
RedirectException - if the server asks us to redirect to
a different host/port.
java.io.IOException - if any other I/O error occurs
public void maybeSendHeartbeat()
throws java.io.IOException
java.io.IOException
public void handleSocketTimeout()
throws MissedHeartbeatException
MissedHeartbeatException - if too many silent timeouts have gone by
public boolean processControlCommand(Command c)
throws java.io.IOException
java.io.IOExceptionpublic void handleConnectionClose(Command closeCommand)
public void shutdown(java.lang.Object reason,
boolean initiatedByApplication,
java.lang.Throwable cause)
public void close(int closeCode,
java.lang.String closeMessage)
throws java.io.IOException
close in interface ConnectioncloseCode - code indicating the reason for closing the connection - see AMQP spec for a list of codescloseMessage - optional message describing the reason for closing the connection
java.io.IOException - if an I/O problem is encountered
public void close(int closeCode,
java.lang.String closeMessage,
boolean initiatedByApplication,
java.lang.Throwable cause)
throws java.io.IOException
java.io.IOExceptionpublic 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 | ||||||||