|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.qpid.client.protocol.AMQProtocolHandler
public class AMQProtocolHandler
AMQProtocolHandler is the client side protocol handler for AMQP, it handles all protocol events received from the network by MINA. The primary purpose of AMQProtocolHandler is to translate the generic event model of MINA into the specific event model of AMQP, by revealing the type of the received events (from decoded data), and passing the event on to more specific handlers for the type. In this sense, it channels the richer event model of AMQP, expressed in terms of methods and so on, through the cruder, general purpose event model of MINA, expressed in terms of "message received" and so on.
There is a 1:1 mapping between an AMQProtocolHandler and anAMQConnection
. The connection class is
exposed to the end user of the AMQP client API, and also implements the JMS Connection API, so provides the public
API calls through which an individual connection can be manipulated. This protocol handler talks to the network
through MINA, in a behind the scenes role; it is not an exposed part of the client API.
There is a 1:many mapping between an AMQProtocolHandler and a set of AMQSession
s. At the MINA level,
there is one session per connection. At the AMQP level there can be many channels which are also called sessions in
JMS parlance. The AMQSession
s are managed through an AMQProtocolSession
instance. The protocol
session is similar to the MINA per-connection session, except that it can span the lifecycle of multiple MINA sessions
in the event of failover. See below for more information about this.
Mina provides a session container that can be used to store/retrieve arbitrary objects as String named
attributes. A more convenient, type-safe, container for session data is provided in the form of
AMQProtocolSession
.
A common way to use MINA is to have a single instance of the event handler, and for MINA to pass in its session
object with every event, and for per-connection data to be held in the MINA session (perhaps using a type-safe wrapper
as described above). This event handler is different, because dealing with failover complicates things. To the
end client of an AMQConnection, a failed over connection is still handled through the same connection instance, but
behind the scenes a new transport connection, and MINA session will have been created. The MINA session object cannot
be used to track the state of the fail-over process, because it is destroyed and a new one is created, as the old
connection is shutdown and a new one created. For this reason, an AMQProtocolHandler is created per AMQConnection
and the protocol session data is held outside of the MINA IOSession.
This handler is responsibile for setting up the filter chain to filter all events for this handler through.
The filter chain is set up as a stack of event handers that perform the following functions (working upwards from
the network traffic at the bottom), handing off incoming events to an asynchronous thread pool to do the work,
optionally handling secure sockets encoding/decoding, encoding/decoding the AMQP format itself.
Responsibilities | Collaborations |
---|---|
Maintain fail-over state. | |
Constructor Summary | |
---|---|
AMQProtocolHandler(AMQConnection con)
Creates a new protocol handler, associated with the specified client connection instance. |
Method Summary | |
---|---|
void |
blockUntilNotFailingOver()
|
void |
closeConnection(long timeout)
Closes the connection. |
void |
closed()
Called when the network connection is closed. |
void |
closeSession(AMQSession session)
|
void |
createIoTransportSession(BrokerDetails brokerDetail)
Called when we want to create a new IoTransport session |
StateWaiter |
createWaiter(Set<AMQState> states)
|
void |
exception(Throwable cause)
Invoked when any exception is thrown by the NetworkDriver |
void |
failover(String host,
int port)
|
void |
failoverInProgress()
|
org.apache.qpid.framing.AMQShortString |
generateQueueName()
|
AMQConnection |
getConnection()
|
CountDownLatch |
getFailoverLatch()
|
(package private) FailoverState |
getFailoverState()
|
SocketAddress |
getLocalAddress()
|
org.apache.qpid.framing.MethodRegistry |
getMethodRegistry()
|
org.apache.qpid.transport.NetworkDriver |
getNetworkDriver()
|
byte |
getProtocolMajorVersion()
|
byte |
getProtocolMinorVersion()
|
AMQProtocolSession |
getProtocolSession()
|
org.apache.qpid.framing.ProtocolVersion |
getProtocolVersion()
|
long |
getReadBytes()
|
SocketAddress |
getRemoteAddress()
|
AMQStateManager |
getStateManager()
|
org.apache.qpid.framing.ProtocolVersion |
getSuggestedProtocolVersion()
|
long |
getWrittenBytes()
|
(package private) void |
initHeartbeats(int delay)
|
void |
methodBodyReceived(int channelId,
org.apache.qpid.framing.AMQBody bodyFrame)
|
void |
notifyFailoverStarting()
|
void |
propagateExceptionToAllWaiters(Exception e)
There are two cases where we have other threads potentially blocking for events to be handled by this class. |
void |
propagateExceptionToFrameListeners(Exception e)
This caters for the case where we only need to propogate an exception to the the frame listeners to interupt any protocol level waits. |
void |
readerIdle()
|
void |
received(ByteBuffer msg)
|
void |
setFailoverLatch(CountDownLatch failoverLatch)
|
void |
setFailoverState(FailoverState failoverState)
|
void |
setNetworkDriver(org.apache.qpid.transport.NetworkDriver driver)
|
void |
setStateManager(AMQStateManager stateManager)
|
org.apache.qpid.protocol.AMQMethodEvent |
syncWrite(org.apache.qpid.framing.AMQFrame frame,
Class responseClass)
More convenient method to write a frame and wait for it's response. |
org.apache.qpid.protocol.AMQMethodEvent |
syncWrite(org.apache.qpid.framing.AMQFrame frame,
Class responseClass,
long timeout)
More convenient method to write a frame and wait for it's response. |
org.apache.qpid.protocol.AMQMethodEvent |
writeCommandFrameAndWaitForReply(org.apache.qpid.framing.AMQFrame frame,
BlockingMethodFrameListener listener)
Convenience method that writes a frame to the protocol session and waits for a particular response. |
org.apache.qpid.protocol.AMQMethodEvent |
writeCommandFrameAndWaitForReply(org.apache.qpid.framing.AMQFrame frame,
BlockingMethodFrameListener listener,
long timeout)
Convenience method that writes a frame to the protocol session and waits for a particular response. |
void |
writeFrame(org.apache.qpid.framing.AMQDataBlock frame)
Convenience method that writes a frame to the protocol session. |
void |
writeFrame(org.apache.qpid.framing.AMQDataBlock frame,
boolean wait)
|
void |
writerIdle()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AMQProtocolHandler(AMQConnection con)
con
- The client connection that this is the event handler for.Method Detail |
---|
public void createIoTransportSession(BrokerDetails brokerDetail)
brokerDetail
- public void closed()
closed
in interface org.apache.qpid.protocol.ProtocolEngine
closed
in interface org.apache.qpid.transport.Receiver<ByteBuffer>
public void readerIdle()
readerIdle
in interface org.apache.qpid.protocol.ProtocolEngine
public void writerIdle()
writerIdle
in interface org.apache.qpid.protocol.ProtocolEngine
public void exception(Throwable cause)
exception
in interface org.apache.qpid.transport.Receiver<ByteBuffer>
public void propagateExceptionToAllWaiters(Exception e)
e
- the exception to propagatepropagateExceptionToFrameListeners(java.lang.Exception)
public void propagateExceptionToFrameListeners(Exception e)
FailoverHandler
.
Once the FailoverHandler
has re-established the connection then the listeners will be able to re-attempt
their protocol request and so listen again for the correct frame.
e
- the exception to propagatepublic void notifyFailoverStarting()
public void failoverInProgress()
public void received(ByteBuffer msg)
received
in interface org.apache.qpid.transport.Receiver<ByteBuffer>
public void methodBodyReceived(int channelId, org.apache.qpid.framing.AMQBody bodyFrame) throws org.apache.qpid.AMQException
org.apache.qpid.AMQException
public StateWaiter createWaiter(Set<AMQState> states) throws org.apache.qpid.AMQException
org.apache.qpid.AMQException
public void writeFrame(org.apache.qpid.framing.AMQDataBlock frame)
frame
- the frame to writepublic void writeFrame(org.apache.qpid.framing.AMQDataBlock frame, boolean wait)
public org.apache.qpid.protocol.AMQMethodEvent writeCommandFrameAndWaitForReply(org.apache.qpid.framing.AMQFrame frame, BlockingMethodFrameListener listener) throws org.apache.qpid.AMQException, FailoverException
frame
- listener
- the blocking listener. Note the calling thread will block.
org.apache.qpid.AMQException
FailoverException
public org.apache.qpid.protocol.AMQMethodEvent writeCommandFrameAndWaitForReply(org.apache.qpid.framing.AMQFrame frame, BlockingMethodFrameListener listener, long timeout) throws org.apache.qpid.AMQException, FailoverException
frame
- listener
- the blocking listener. Note the calling thread will block.
org.apache.qpid.AMQException
FailoverException
public org.apache.qpid.protocol.AMQMethodEvent syncWrite(org.apache.qpid.framing.AMQFrame frame, Class responseClass) throws org.apache.qpid.AMQException, FailoverException
org.apache.qpid.AMQException
FailoverException
public org.apache.qpid.protocol.AMQMethodEvent syncWrite(org.apache.qpid.framing.AMQFrame frame, Class responseClass, long timeout) throws org.apache.qpid.AMQException, FailoverException
org.apache.qpid.AMQException
FailoverException
public void closeSession(AMQSession session) throws org.apache.qpid.AMQException
org.apache.qpid.AMQException
public void closeConnection(long timeout) throws org.apache.qpid.AMQException
timeout
- The timeout to wait for an acknowledgement to the close request.
org.apache.qpid.AMQException
- If the close fails for any reason.public long getReadBytes()
getReadBytes
in interface org.apache.qpid.protocol.ProtocolEngine
public long getWrittenBytes()
getWrittenBytes
in interface org.apache.qpid.protocol.ProtocolEngine
public void failover(String host, int port)
public void blockUntilNotFailingOver() throws InterruptedException
InterruptedException
public org.apache.qpid.framing.AMQShortString generateQueueName()
public CountDownLatch getFailoverLatch()
public void setFailoverLatch(CountDownLatch failoverLatch)
public AMQConnection getConnection()
public AMQStateManager getStateManager()
public void setStateManager(AMQStateManager stateManager)
public AMQProtocolSession getProtocolSession()
FailoverState getFailoverState()
public void setFailoverState(FailoverState failoverState)
public byte getProtocolMajorVersion()
public byte getProtocolMinorVersion()
public org.apache.qpid.framing.MethodRegistry getMethodRegistry()
public org.apache.qpid.framing.ProtocolVersion getProtocolVersion()
public SocketAddress getRemoteAddress()
getRemoteAddress
in interface org.apache.qpid.protocol.ProtocolEngine
public SocketAddress getLocalAddress()
getLocalAddress
in interface org.apache.qpid.protocol.ProtocolEngine
public void setNetworkDriver(org.apache.qpid.transport.NetworkDriver driver)
setNetworkDriver
in interface org.apache.qpid.protocol.ProtocolEngine
void initHeartbeats(int delay)
delay
- delay in seconds (not ms)public org.apache.qpid.transport.NetworkDriver getNetworkDriver()
public org.apache.qpid.framing.ProtocolVersion getSuggestedProtocolVersion()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |