org.apache.qpid.client.protocol
Class AMQProtocolHandler

java.lang.Object
  extended by org.apache.mina.common.IoHandlerAdapter
      extended by org.apache.qpid.client.protocol.AMQProtocolHandler
All Implemented Interfaces:
org.apache.mina.common.IoHandler

public class AMQProtocolHandler
extends org.apache.mina.common.IoHandlerAdapter


Constructor Summary
AMQProtocolHandler(AMQConnection con)
           
 
Method Summary
 void addFrameListener(AMQMethodListener listener)
           
 void addSessionByChannel(int channelId, AMQSession session)
          Convenience method to register an AMQSession with the protocol handler.
 void attainState(AMQState s)
           
 void blockUntilNotFailingOver()
           
 void closeConnection()
           
 void closeSession(AMQSession session)
           
 void exceptionCaught(org.apache.mina.common.IoSession session, java.lang.Throwable cause)
           
 void failover(java.lang.String host, int port)
           
 java.lang.String generateQueueName()
           
 AMQConnection getConnection()
           
 java.util.concurrent.CountDownLatch getFailoverLatch()
           
 long getReadBytes()
           
 AMQStateManager getStateManager()
           
 long getWrittenBytes()
           
 boolean isUseSSL()
           
 void messageReceived(org.apache.mina.common.IoSession session, java.lang.Object message)
           
 void messageSent(org.apache.mina.common.IoSession session, java.lang.Object message)
           
 void propagateExceptionToWaiters(java.lang.Exception e)
          There are two cases where we have other threads potentially blocking for events to be handled by this class.
 void removeFrameListener(AMQMethodListener listener)
           
 void removeSessionByChannel(int channelId)
          Convenience method to deregister an AMQSession with the protocol handler.
 void sessionClosed(org.apache.mina.common.IoSession session)
          When the broker connection dies we can either get sessionClosed() called or exceptionCaught() followed by sessionClosed() depending on whether we were trying to send data at the time of failure.
 void sessionCreated(org.apache.mina.common.IoSession session)
           
 void sessionIdle(org.apache.mina.common.IoSession session, org.apache.mina.common.IdleStatus status)
           
 void sessionOpened(org.apache.mina.common.IoSession session)
           
 void setFailoverLatch(java.util.concurrent.CountDownLatch failoverLatch)
           
 void setFailoverState(FailoverState failoverState)
           
 void setStateManager(AMQStateManager stateManager)
           
 void setUseSSL(boolean useSSL)
           
 AMQMethodEvent syncWrite(org.apache.qpid.framing.AMQFrame frame, java.lang.Class responseClass)
          More convenient method to write a frame and wait for it's 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AMQProtocolHandler

public AMQProtocolHandler(AMQConnection con)
Method Detail

isUseSSL

public boolean isUseSSL()

setUseSSL

public void setUseSSL(boolean useSSL)

sessionCreated

public void sessionCreated(org.apache.mina.common.IoSession session)
                    throws java.lang.Exception
Specified by:
sessionCreated in interface org.apache.mina.common.IoHandler
Overrides:
sessionCreated in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

sessionOpened

public void sessionOpened(org.apache.mina.common.IoSession session)
                   throws java.lang.Exception
Specified by:
sessionOpened in interface org.apache.mina.common.IoHandler
Overrides:
sessionOpened in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

sessionClosed

public void sessionClosed(org.apache.mina.common.IoSession session)
                   throws java.lang.Exception
When the broker connection dies we can either get sessionClosed() called or exceptionCaught() followed by sessionClosed() depending on whether we were trying to send data at the time of failure.

Specified by:
sessionClosed in interface org.apache.mina.common.IoHandler
Overrides:
sessionClosed in class org.apache.mina.common.IoHandlerAdapter
Parameters:
session -
Throws:
java.lang.Exception

sessionIdle

public void sessionIdle(org.apache.mina.common.IoSession session,
                        org.apache.mina.common.IdleStatus status)
                 throws java.lang.Exception
Specified by:
sessionIdle in interface org.apache.mina.common.IoHandler
Overrides:
sessionIdle in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

exceptionCaught

public void exceptionCaught(org.apache.mina.common.IoSession session,
                            java.lang.Throwable cause)
                     throws java.lang.Exception
Specified by:
exceptionCaught in interface org.apache.mina.common.IoHandler
Overrides:
exceptionCaught in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

propagateExceptionToWaiters

public void propagateExceptionToWaiters(java.lang.Exception e)
There are two cases where we have other threads potentially blocking for events to be handled by this class. These are for the state manager (waiting for a state change) or a frame listener (waiting for a particular type of frame to arrive). When an error occurs we need to notify these waiters so that they can react appropriately.

Parameters:
e - the exception to propagate

messageReceived

public void messageReceived(org.apache.mina.common.IoSession session,
                            java.lang.Object message)
                     throws java.lang.Exception
Specified by:
messageReceived in interface org.apache.mina.common.IoHandler
Overrides:
messageReceived in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

messageSent

public void messageSent(org.apache.mina.common.IoSession session,
                        java.lang.Object message)
                 throws java.lang.Exception
Specified by:
messageSent in interface org.apache.mina.common.IoHandler
Overrides:
messageSent in class org.apache.mina.common.IoHandlerAdapter
Throws:
java.lang.Exception

addFrameListener

public void addFrameListener(AMQMethodListener listener)

removeFrameListener

public void removeFrameListener(AMQMethodListener listener)

attainState

public void attainState(AMQState s)
                 throws org.apache.qpid.AMQException
Throws:
org.apache.qpid.AMQException

writeFrame

public void writeFrame(org.apache.qpid.framing.AMQDataBlock frame)
Convenience method that writes a frame to the protocol session. Equivalent to calling getProtocolSession().write().

Parameters:
frame - the frame to write

writeFrame

public void writeFrame(org.apache.qpid.framing.AMQDataBlock frame,
                       boolean wait)

syncWrite

public AMQMethodEvent syncWrite(org.apache.qpid.framing.AMQFrame frame,
                                java.lang.Class responseClass)
                         throws org.apache.qpid.AMQException
More convenient method to write a frame and wait for it's response.

Throws:
org.apache.qpid.AMQException

addSessionByChannel

public void addSessionByChannel(int channelId,
                                AMQSession session)
Convenience method to register an AMQSession with the protocol handler. Registering a session with the protocol handler will ensure that messages are delivered to the consumer(s) on that session.

Parameters:
channelId - the channel id of the session
session - the session instance.

removeSessionByChannel

public void removeSessionByChannel(int channelId)
Convenience method to deregister an AMQSession with the protocol handler.

Parameters:
channelId - then channel id of the session

closeSession

public void closeSession(AMQSession session)
                  throws org.apache.qpid.AMQException
Throws:
org.apache.qpid.AMQException

closeConnection

public void closeConnection()
                     throws org.apache.qpid.AMQException
Throws:
org.apache.qpid.AMQException

getReadBytes

public long getReadBytes()
Returns:
the number of bytes read from this protocol session

getWrittenBytes

public long getWrittenBytes()
Returns:
the number of bytes written to this protocol session

failover

public void failover(java.lang.String host,
                     int port)

blockUntilNotFailingOver

public void blockUntilNotFailingOver()
                              throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

generateQueueName

public java.lang.String generateQueueName()

getFailoverLatch

public java.util.concurrent.CountDownLatch getFailoverLatch()

setFailoverLatch

public void setFailoverLatch(java.util.concurrent.CountDownLatch failoverLatch)

getConnection

public AMQConnection getConnection()

getStateManager

public AMQStateManager getStateManager()

setStateManager

public void setStateManager(AMQStateManager stateManager)

setFailoverState

public void setFailoverState(FailoverState failoverState)