org.apache.qpid.client.protocol
Class AMQProtocolSession

java.lang.Object
  extended by org.apache.qpid.client.protocol.AMQProtocolSession
All Implemented Interfaces:
org.apache.qpid.framing.ProtocolVersionList

public class AMQProtocolSession
extends java.lang.Object
implements org.apache.qpid.framing.ProtocolVersionList

Wrapper for protocol session that provides type-safe access to session attributes. The underlying protocol session is still available but clients should not use it to obtain session attributes.


Field Summary
protected  java.util.concurrent.ConcurrentMap _channelId2SessionMap
          Maps from the channel id to the AMQSession that it represents.
protected  java.util.concurrent.ConcurrentMap _channelId2UnprocessedMsgMap
          Maps from a channel id to an unprocessed message.
protected  java.util.concurrent.ConcurrentMap _closingChannels
           
protected  org.apache.mina.common.WriteFuture _lastWriteFuture
           
protected static org.apache.log4j.Logger _logger
           
protected  org.apache.mina.common.IoSession _minaProtocolSession
           
protected  AMQProtocolHandler _protocolHandler
          The handler from which this session was created and which is used to handle protocol events.
protected  int _queueId
          Counter to ensure unique queue names
protected  java.lang.Object _queueIdLock
           
protected static java.lang.String AMQ_CONNECTION
           
protected static java.lang.String CONNECTION_TUNE_PARAMETERS
           
protected static int LAST_WRITE_FUTURE_JOIN_TIMEOUT
           
static java.lang.String PROTOCOL_INITIATION_RECEIVED
           
protected static java.lang.String SASL_CLIENT
           
 
Fields inherited from interface org.apache.qpid.framing.ProtocolVersionList
PROTOCOL_MAJOR, PROTOCOL_MINOR, pv
 
Constructor Summary
AMQProtocolSession()
          No-arg constructor for use by test subclass - has to initialise final vars NOT intended for use other then for test
AMQProtocolSession(AMQProtocolHandler protocolHandler, org.apache.mina.common.IoSession protocolSession, AMQConnection connection)
           
 
Method Summary
 void addSessionByChannel(int channelId, AMQSession session)
           
 boolean channelClosed(int channelId, int code, java.lang.String text)
          Called from the ChannelClose handler when a channel close frame is received.
 void closeProtocolSession()
           
 void closeSession(AMQSession session)
          Starts the process of closing a session
 void failover(java.lang.String host, int port)
           
protected  java.lang.String generateQueueName()
           
 AMQConnection getAMQConnection()
           
 java.lang.String getClientID()
           
 ConnectionTuneParameters getConnectionTuneParameters()
           
 org.apache.mina.common.IoSession getIoSession()
           
 java.lang.String getPassword()
           
 javax.security.sasl.SaslClient getSaslClient()
           
 java.lang.String getUsername()
           
 java.lang.String getVirtualHost()
           
 void init()
           
 void messageContentBodyReceived(int channelId, org.apache.qpid.framing.ContentBody contentBody)
           
 void messageContentHeaderReceived(int channelId, org.apache.qpid.framing.ContentHeaderBody contentHeader)
           
 void removeSessionByChannel(int channelId)
           
 void setClientID(java.lang.String clientID)
           
 void setConnectionTuneParameters(ConnectionTuneParameters params)
           
 void setSaslClient(javax.security.sasl.SaslClient client)
          Store the SASL client currently being used for the authentication handshake
 void unprocessedMessageReceived(UnprocessedMessage message)
          Callback invoked from the BasicDeliverMethodHandler when a message has been received.
 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
 

Field Detail

LAST_WRITE_FUTURE_JOIN_TIMEOUT

protected static final int LAST_WRITE_FUTURE_JOIN_TIMEOUT
See Also:
Constant Field Values

_logger

protected static final org.apache.log4j.Logger _logger

PROTOCOL_INITIATION_RECEIVED

public static final java.lang.String PROTOCOL_INITIATION_RECEIVED
See Also:
Constant Field Values

CONNECTION_TUNE_PARAMETERS

protected static final java.lang.String CONNECTION_TUNE_PARAMETERS
See Also:
Constant Field Values

AMQ_CONNECTION

protected static final java.lang.String AMQ_CONNECTION
See Also:
Constant Field Values

SASL_CLIENT

protected static final java.lang.String SASL_CLIENT
See Also:
Constant Field Values

_minaProtocolSession

protected final org.apache.mina.common.IoSession _minaProtocolSession

_lastWriteFuture

protected org.apache.mina.common.WriteFuture _lastWriteFuture

_protocolHandler

protected final AMQProtocolHandler _protocolHandler
The handler from which this session was created and which is used to handle protocol events. We send failover events to the handler.


_channelId2SessionMap

protected java.util.concurrent.ConcurrentMap _channelId2SessionMap
Maps from the channel id to the AMQSession that it represents.


_closingChannels

protected java.util.concurrent.ConcurrentMap _closingChannels

_channelId2UnprocessedMsgMap

protected java.util.concurrent.ConcurrentMap _channelId2UnprocessedMsgMap
Maps from a channel id to an unprocessed message. This is used to tie together the JmsDeliverBody (which arrives first) with the subsequent content header and content bodies.


_queueId

protected int _queueId
Counter to ensure unique queue names


_queueIdLock

protected final java.lang.Object _queueIdLock
Constructor Detail

AMQProtocolSession

public AMQProtocolSession()
No-arg constructor for use by test subclass - has to initialise final vars NOT intended for use other then for test


AMQProtocolSession

public AMQProtocolSession(AMQProtocolHandler protocolHandler,
                          org.apache.mina.common.IoSession protocolSession,
                          AMQConnection connection)
Method Detail

init

public void init()

getClientID

public java.lang.String getClientID()

setClientID

public void setClientID(java.lang.String clientID)
                 throws javax.jms.JMSException
Throws:
javax.jms.JMSException

getVirtualHost

public java.lang.String getVirtualHost()

getUsername

public java.lang.String getUsername()

getPassword

public java.lang.String getPassword()

getIoSession

public org.apache.mina.common.IoSession getIoSession()

getSaslClient

public javax.security.sasl.SaslClient getSaslClient()

setSaslClient

public void setSaslClient(javax.security.sasl.SaslClient client)
Store the SASL client currently being used for the authentication handshake

Parameters:
client - if non-null, stores this in the session. if null clears any existing client being stored

getConnectionTuneParameters

public ConnectionTuneParameters getConnectionTuneParameters()

setConnectionTuneParameters

public void setConnectionTuneParameters(ConnectionTuneParameters params)

unprocessedMessageReceived

public void unprocessedMessageReceived(UnprocessedMessage message)
                                throws org.apache.qpid.AMQException
Callback invoked from the BasicDeliverMethodHandler when a message has been received. This is invoked on the MINA dispatcher thread.

Parameters:
message -
Throws:
org.apache.qpid.AMQException - if this was not expected

messageContentHeaderReceived

public void messageContentHeaderReceived(int channelId,
                                         org.apache.qpid.framing.ContentHeaderBody contentHeader)
                                  throws org.apache.qpid.AMQException
Throws:
org.apache.qpid.AMQException

messageContentBodyReceived

public void messageContentBodyReceived(int channelId,
                                       org.apache.qpid.framing.ContentBody contentBody)
                                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)

addSessionByChannel

public void addSessionByChannel(int channelId,
                                AMQSession session)

removeSessionByChannel

public void removeSessionByChannel(int channelId)

closeSession

public void closeSession(AMQSession session)
Starts the process of closing a session

Parameters:
session - the AMQSession being closed

channelClosed

public boolean channelClosed(int channelId,
                             int code,
                             java.lang.String text)
Called from the ChannelClose handler when a channel close frame is received. This method decides whether this is a response or an initiation. The latter case causes the AMQSession to be closed and an exception to be thrown if appropriate.

Parameters:
channelId - the id of the channel (session)
Returns:
true if the client must respond to the server, i.e. if the server initiated the channel close, false if the channel close is just the server responding to the client's earlier request to close the channel.

getAMQConnection

public AMQConnection getAMQConnection()

closeProtocolSession

public void closeProtocolSession()

failover

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

generateQueueName

protected java.lang.String generateQueueName()