com.rabbitmq.client.impl
Class AMQChannel

java.lang.Object
  extended by com.rabbitmq.client.impl.AMQChannel
Direct Known Subclasses:
ChannelN

public abstract class AMQChannel
extends java.lang.Object

Base class modelling an AMQ channel. Subclasses implement close() and processAsync(), and may choose to override processShutdownSignal().

See Also:
ChannelN, Connection

Nested Class Summary
static class AMQChannel.BlockingRpcContinuation<T>
           
static interface AMQChannel.RpcContinuation
           
static class AMQChannel.SimpleBlockingRpcContinuation
           
 
Field Summary
 AMQChannel.RpcContinuation _activeRpc
          The current outstanding RPC request, if any.
 int _channelNumber
          This channel's channel number.
 AMQCommand.Assembler _commandAssembler
          State machine assembling commands on their way in.
 AMQConnection _connection
          The connection this channel is associated with.
 boolean _isOpen
          Indicates whether this channel is in a state to handle further activity.
 
Constructor Summary
AMQChannel(AMQConnection connection, int channelNumber)
          Construct a channel on the given connection, with the given channel number.
 
Method Summary
 void enqueueRpc(AMQChannel.RpcContinuation k)
           
 void ensureIsOpen()
           
 AMQCommand exnWrappingRpc(Method m)
          Placeholder until we address bug 15786 (implementing a proper exception hierarchy).
 AMQConnection getAMQConnection()
           
 int getChannelNumber()
          Public API - Retrieves this channel's channel number.
 Connection getConnection()
          Public API - Retrieves this channel's underlying connection.
 void handleCompleteInboundCommand(AMQCommand command)
          Private API - handle a command which has been assembled
 void handleFrame(Frame frame)
          Private API - When the Connection receives a Frame for this channel, it passes it to this method.
 boolean isOpen()
           
 AMQChannel.RpcContinuation nextOutstandingRpc()
           
abstract  boolean processAsync(Command command)
          Protected API - called by nextCommand to check possibly handle an incoming Command before it is returned to the caller of nextCommand.
 void processShutdownSignal(ShutdownSignalException signal)
          Protected API - respond, in the driver thread, to a ShutdownSignalException.
 AMQCommand quiescingRpc(Method m, int timeoutMillisec, AMQCommand timeoutReply)
          Just like rpc(Method), but for use during quiescing/close/shutdown.
 AMQCommand rpc(Method m)
          Protected API - sends a Command to the broker and waits for the next inbound Command from the broker: only for use from non-connection-MainLoop threads!
 void rpc(Method m, AMQChannel.RpcContinuation k)
           
 java.lang.String toString()
           
 void transmit(Method m)
           
 void transmitAndEnqueue(Method m, AMQChannel.RpcContinuation k)
           
static java.io.IOException wrap(ShutdownSignalException ex)
          Placeholder until we address bug 15786 (implementing a proper exception hierarchy).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_connection

public final AMQConnection _connection
The connection this channel is associated with.


_channelNumber

public final int _channelNumber
This channel's channel number.


_commandAssembler

public AMQCommand.Assembler _commandAssembler
State machine assembling commands on their way in.


_activeRpc

public AMQChannel.RpcContinuation _activeRpc
The current outstanding RPC request, if any. (Could become a queue in future.)


_isOpen

public volatile boolean _isOpen
Indicates whether this channel is in a state to handle further activity.

Constructor Detail

AMQChannel

public AMQChannel(AMQConnection connection,
                  int channelNumber)
Construct a channel on the given connection, with the given channel number.

Parameters:
connection - the underlying connection for this channel
channelNumber - the allocated reference number for this channel
Method Detail

getChannelNumber

public int getChannelNumber()
Public API - Retrieves this channel's channel number.

Returns:
the channel number

getConnection

public Connection getConnection()
Public API - Retrieves this channel's underlying connection.

Returns:
the connection

handleFrame

public void handleFrame(Frame frame)
                 throws java.io.IOException
Private API - When the Connection receives a Frame for this channel, it passes it to this method.

Parameters:
frame - the incoming frame
Throws:
java.io.IOException - if an error is encountered

wrap

public static java.io.IOException wrap(ShutdownSignalException ex)
Placeholder until we address bug 15786 (implementing a proper exception hierarchy). In the meantime, this at least won't throw away any information from the wrapped exception.

Parameters:
ex - the exception to wrap
Returns:
the wrapped exception

exnWrappingRpc

public AMQCommand exnWrappingRpc(Method m)
                          throws java.io.IOException
Placeholder until we address bug 15786 (implementing a proper exception hierarchy).

Throws:
java.io.IOException

handleCompleteInboundCommand

public void handleCompleteInboundCommand(AMQCommand command)
                                  throws java.io.IOException
Private API - handle a command which has been assembled

Parameters:
command - the incoming command
Throws:
java.io.IOException - if there's any problem
java.io.IOException

enqueueRpc

public void enqueueRpc(AMQChannel.RpcContinuation k)

transmitAndEnqueue

public void transmitAndEnqueue(Method m,
                               AMQChannel.RpcContinuation k)
                        throws java.io.IOException
Throws:
java.io.IOException

nextOutstandingRpc

public AMQChannel.RpcContinuation nextOutstandingRpc()

isOpen

public boolean isOpen()

ensureIsOpen

public void ensureIsOpen()
                  throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

rpc

public AMQCommand rpc(Method m)
               throws java.io.IOException,
                      ShutdownSignalException
Protected API - sends a Command to the broker and waits for the next inbound Command from the broker: only for use from non-connection-MainLoop threads!

Throws:
java.io.IOException
ShutdownSignalException

rpc

public void rpc(Method m,
                AMQChannel.RpcContinuation k)
         throws java.io.IOException
Throws:
java.io.IOException

quiescingRpc

public AMQCommand quiescingRpc(Method m,
                               int timeoutMillisec,
                               AMQCommand timeoutReply)
                        throws java.io.IOException,
                               ShutdownSignalException
Just like rpc(Method), but for use during quiescing/close/shutdown. Not for regular use. Doesn't do the ensureIsOpen() check.

Throws:
java.io.IOException
ShutdownSignalException

processAsync

public abstract boolean processAsync(Command command)
                              throws java.io.IOException
Protected API - called by nextCommand to check possibly handle an incoming Command before it is returned to the caller of nextCommand. If this method returns true, the command is considered handled and is not passed back to nextCommand's caller; if it returns false, nextCommand returns the command as usual. This is used in subclasses to implement handling of Basic.Return and Basic.Deliver messages, as well as Channel.Close and Connection.Close.

Parameters:
command - the command to handle asynchronously
Returns:
true if we handled the command; otherwise the caller should consider it "unhandled"
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

processShutdownSignal

public void processShutdownSignal(ShutdownSignalException signal)
Protected API - respond, in the driver thread, to a ShutdownSignalException.

Parameters:
signal - the signal to handle

transmit

public void transmit(Method m)
              throws java.io.IOException
Throws:
java.io.IOException

getAMQConnection

public AMQConnection getAMQConnection()