org.apache.qpid.client.protocol
Class AMQProtocolSession

java.lang.Object
  extended by org.apache.qpid.client.protocol.AMQProtocolSession
All Implemented Interfaces:
org.apache.qpid.protocol.AMQProtocolWriter, org.apache.qpid.protocol.AMQVersionAwareProtocolSession, org.apache.qpid.protocol.ProtocolVersionAware

public class AMQProtocolSession
extends Object
implements org.apache.qpid.protocol.AMQVersionAwareProtocolSession

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  ConcurrentMap<Integer,AMQSession> _channelId2SessionMap
          Maps from the channel id to the AMQSession that it represents.
protected  ConcurrentMap _closingChannels
           
protected  AMQConnection _connection
           
protected static org.slf4j.Logger _logger
           
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  Object _queueIdLock
           
protected static String AMQ_CONNECTION
           
protected static String CONNECTION_TUNE_PARAMETERS
           
protected static int LAST_WRITE_FUTURE_JOIN_TIMEOUT
           
static String PROTOCOL_INITIATION_RECEIVED
           
protected static String SASL_CLIENT
           
 
Constructor Summary
AMQProtocolSession(AMQProtocolHandler protocolHandler, AMQConnection connection)
           
 
Method Summary
 boolean channelClosed(int channelId, org.apache.qpid.protocol.AMQConstant code, 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 confirmConsumerCancelled(int channelId, org.apache.qpid.framing.AMQShortString consumerTag)
           
 void contentBodyReceived(int channelId, org.apache.qpid.framing.ContentBody contentBody)
           
 void contentHeaderReceived(int channelId, org.apache.qpid.framing.ContentHeaderBody contentHeader)
           
 void failover(String host, int port)
           
protected  org.apache.qpid.framing.AMQShortString generateQueueName()
           
 AMQConnection getAMQConnection()
           
 String getClientID()
           
 ConnectionTuneParameters getConnectionTuneParameters()
           
 org.apache.qpid.framing.MethodDispatcher getMethodDispatcher()
           
 org.apache.qpid.framing.MethodRegistry getMethodRegistry()
           
 String getPassword()
           
 byte getProtocolMajorVersion()
           
 byte getProtocolMinorVersion()
           
 org.apache.qpid.framing.ProtocolVersion getProtocolVersion()
           
 SaslClient getSaslClient()
           
protected  AMQSession getSession(int channelId)
           
 AMQStateManager getStateManager()
           
 String getUsername()
           
 String getVirtualHost()
           
 void heartbeatBodyReceived(int channelId, org.apache.qpid.framing.HeartbeatBody body)
           
 void init()
           
 void methodFrameReceived(int channel, org.apache.qpid.framing.AMQMethodBody amqMethodBody)
           
 void notifyError(Exception error)
           
 void setClientID(String clientID)
           
 void setConnectionTuneParameters(ConnectionTuneParameters params)
           
 void setFlowControl(int channelId, boolean active)
           
 void setMethodDispatcher(org.apache.qpid.framing.MethodDispatcher methodDispatcher)
           
 void setProtocolVersion(org.apache.qpid.framing.ProtocolVersion pv)
           
 void setSaslClient(SaslClient client)
          Store the SASL client currently being used for the authentication handshake
 void setSender(org.apache.qpid.transport.Sender<ByteBuffer> sender)
           
 void setTicket(int ticket, int channelId)
           
 String toString()
           
 void unprocessedMessageReceived(int channelId, 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, 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.slf4j.Logger _logger

PROTOCOL_INITIATION_RECEIVED

public static final String PROTOCOL_INITIATION_RECEIVED
See Also:
Constant Field Values

CONNECTION_TUNE_PARAMETERS

protected static final String CONNECTION_TUNE_PARAMETERS
See Also:
Constant Field Values

AMQ_CONNECTION

protected static final String AMQ_CONNECTION
See Also:
Constant Field Values

SASL_CLIENT

protected static final String SASL_CLIENT
See Also:
Constant Field Values

_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 ConcurrentMap<Integer,AMQSession> _channelId2SessionMap
Maps from the channel id to the AMQSession that it represents.


_closingChannels

protected ConcurrentMap _closingChannels

_queueId

protected int _queueId
Counter to ensure unique queue names


_queueIdLock

protected final Object _queueIdLock

_connection

protected final AMQConnection _connection
Constructor Detail

AMQProtocolSession

public AMQProtocolSession(AMQProtocolHandler protocolHandler,
                          AMQConnection connection)
Method Detail

init

public void init()
Specified by:
init in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession

getClientID

public String getClientID()

setClientID

public void setClientID(String clientID)
                 throws JMSException
Throws:
JMSException

getStateManager

public AMQStateManager getStateManager()

getVirtualHost

public String getVirtualHost()

getUsername

public String getUsername()

getPassword

public String getPassword()

getSaslClient

public SaslClient getSaslClient()

setSaslClient

public void setSaslClient(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(int channelId,
                                       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

contentHeaderReceived

public void contentHeaderReceived(int channelId,
                                  org.apache.qpid.framing.ContentHeaderBody contentHeader)
                           throws org.apache.qpid.AMQException
Specified by:
contentHeaderReceived in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession
Throws:
org.apache.qpid.AMQException

contentBodyReceived

public void contentBodyReceived(int channelId,
                                org.apache.qpid.framing.ContentBody contentBody)
                         throws org.apache.qpid.AMQException
Specified by:
contentBodyReceived in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession
Throws:
org.apache.qpid.AMQException

heartbeatBodyReceived

public void heartbeatBodyReceived(int channelId,
                                  org.apache.qpid.framing.HeartbeatBody body)
                           throws org.apache.qpid.AMQException
Specified by:
heartbeatBodyReceived in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession
Throws:
org.apache.qpid.AMQException

getSession

protected AMQSession getSession(int channelId)

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().

Specified by:
writeFrame in interface org.apache.qpid.protocol.AMQProtocolWriter
Parameters:
frame - the frame to write

writeFrame

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

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,
                             org.apache.qpid.protocol.AMQConstant code,
                             String text)
                      throws org.apache.qpid.AMQException
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.
Throws:
org.apache.qpid.AMQException

getAMQConnection

public AMQConnection getAMQConnection()

closeProtocolSession

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

failover

public void failover(String host,
                     int port)

generateQueueName

protected org.apache.qpid.framing.AMQShortString generateQueueName()

confirmConsumerCancelled

public void confirmConsumerCancelled(int channelId,
                                     org.apache.qpid.framing.AMQShortString consumerTag)

setProtocolVersion

public void setProtocolVersion(org.apache.qpid.framing.ProtocolVersion pv)

getProtocolMinorVersion

public byte getProtocolMinorVersion()
Specified by:
getProtocolMinorVersion in interface org.apache.qpid.protocol.ProtocolVersionAware

getProtocolMajorVersion

public byte getProtocolMajorVersion()
Specified by:
getProtocolMajorVersion in interface org.apache.qpid.protocol.ProtocolVersionAware

getProtocolVersion

public org.apache.qpid.framing.ProtocolVersion getProtocolVersion()
Specified by:
getProtocolVersion in interface org.apache.qpid.protocol.ProtocolVersionAware

getMethodRegistry

public org.apache.qpid.framing.MethodRegistry getMethodRegistry()
Specified by:
getMethodRegistry in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession

getMethodDispatcher

public org.apache.qpid.framing.MethodDispatcher getMethodDispatcher()

setTicket

public void setTicket(int ticket,
                      int channelId)

setMethodDispatcher

public void setMethodDispatcher(org.apache.qpid.framing.MethodDispatcher methodDispatcher)

setFlowControl

public void setFlowControl(int channelId,
                           boolean active)

methodFrameReceived

public void methodFrameReceived(int channel,
                                org.apache.qpid.framing.AMQMethodBody amqMethodBody)
                         throws org.apache.qpid.AMQException
Specified by:
methodFrameReceived in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession
Throws:
org.apache.qpid.AMQException

notifyError

public void notifyError(Exception error)

setSender

public void setSender(org.apache.qpid.transport.Sender<ByteBuffer> sender)
Specified by:
setSender in interface org.apache.qpid.protocol.AMQVersionAwareProtocolSession

toString

public String toString()
Overrides:
toString in class Object


Licensed to the Apache Software Foundation