org.apache.qpid.client
Class AMQConnection

java.lang.Object
  extended by org.apache.qpid.client.Closeable
      extended by org.apache.qpid.client.AMQConnection
All Implemented Interfaces:
javax.jms.Connection, javax.jms.QueueConnection, javax.jms.TopicConnection, javax.naming.Referenceable

public class AMQConnection
extends Closeable
implements Connection, javax.jms.QueueConnection, javax.jms.TopicConnection, javax.naming.Referenceable


Field Summary
 
Fields inherited from class org.apache.qpid.client.Closeable
_closed
 
Constructor Summary
  AMQConnection(ConnectionURL connectionURL)
           
  AMQConnection(java.lang.String connection)
           
  AMQConnection(java.lang.String host, int port, boolean useSSL, java.lang.String username, java.lang.String password, java.lang.String clientName, java.lang.String virtualHost)
           
  AMQConnection(java.lang.String host, int port, java.lang.String username, java.lang.String password, java.lang.String clientName, java.lang.String virtualHost)
           
protected AMQConnection(java.lang.String username, java.lang.String password, java.lang.String clientName, java.lang.String virtualHost)
           
  AMQConnection(java.lang.String broker, java.lang.String username, java.lang.String password, java.lang.String clientName, java.lang.String virtualHost)
           
 
Method Summary
 boolean attemptReconnection()
           
 boolean attemptReconnection(java.lang.String host, int port, boolean useSSL)
           
 void blockUntilNotFailingOver()
          If failover is taking place this will block until it has completed.
 void bytesReceived(long receivedBytes)
           
 void bytesSent(long writtenBytes)
           
protected  boolean checkException(java.lang.Throwable thrown)
           
 void close()
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Queue queue, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Topic topic, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, java.lang.String subscriptionName, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.QueueSession createQueueSession(boolean transacted, int acknowledgeMode)
          Returns an AMQQueueSessionAdaptor which wraps an AMQSession and throws IllegalStateExceptions where specified in the JMS spec
 javax.jms.Session createSession(boolean transacted, int acknowledgeMode)
           
 Session createSession(boolean transacted, int acknowledgeMode, int prefetch)
           
 Session createSession(boolean transacted, int acknowledgeMode, int prefetchHigh, int prefetchLow)
           
 javax.jms.TopicSession createTopicSession(boolean transacted, int acknowledgeMode)
          Returns an AMQTopicSessionAdapter which wraps an AMQSession and throws IllegalStateExceptions where specified in the JMS spec
 void exceptionReceived(java.lang.Throwable cause)
          Invoked by the AMQProtocolSession when a protocol session exception has occurred.
 boolean failoverAllowed()
           
 void fireFailoverComplete()
          Fires a failover complete event to the registered connection listener (if any).
 boolean firePreFailover(boolean redirect)
          Fire the preFailover event to the registered connection listener (if any)
 boolean firePreResubscribe()
          Fire the preResubscribe event to the registered connection listener (if any).
 BrokerDetails getActiveBrokerDetails()
          Get the details of the currently active broker
 java.lang.String getClientID()
           
 ConnectionListener getConnectionListener()
           
 javax.jms.ExceptionListener getExceptionListener()
           
 java.lang.Object getFailoverMutex()
          In order to protect the consistency of the connection and its child sessions, consumers and producers, the "failover mutex" must be held when doing any operations that could be corrupted during failover.
 FailoverPolicy getFailoverPolicy()
           
 long getMaximumChannelCount()
           
 long getMaximumFrameSize()
           
 javax.jms.ConnectionMetaData getMetaData()
           
 java.lang.String getPassword()
           
 AMQProtocolHandler getProtocolHandler()
           
 javax.naming.Reference getReference()
           
 java.util.Map getSessions()
           
 java.lang.String getUsername()
           
 java.lang.String getVirtualHost()
           
 void resubscribeSessions()
          For all sessions, and for all consumers in those sessions, resubscribe.
 void setClientID(java.lang.String clientID)
           
 void setConnectionListener(ConnectionListener listener)
           
 void setExceptionListener(javax.jms.ExceptionListener listener)
           
 void setFailoverPolicy(FailoverPolicy policy)
           
 void setMaximumChannelCount(long maximumChannelCount)
           
 void setMaximumFrameSize(long frameMax)
           
 void start()
          Start the connection, i.e.
 void stop()
           
 java.lang.String toString()
           
 java.lang.String toURL()
           
 
Methods inherited from class org.apache.qpid.client.Closeable
checkNotClosed, isClosed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AMQConnection

public AMQConnection(java.lang.String broker,
                     java.lang.String username,
                     java.lang.String password,
                     java.lang.String clientName,
                     java.lang.String virtualHost)
              throws org.apache.qpid.AMQException,
                     org.apache.qpid.url.URLSyntaxException
Throws:
org.apache.qpid.AMQException
org.apache.qpid.url.URLSyntaxException

AMQConnection

public AMQConnection(java.lang.String host,
                     int port,
                     java.lang.String username,
                     java.lang.String password,
                     java.lang.String clientName,
                     java.lang.String virtualHost)
              throws org.apache.qpid.AMQException,
                     org.apache.qpid.url.URLSyntaxException
Throws:
org.apache.qpid.AMQException
org.apache.qpid.url.URLSyntaxException

AMQConnection

public AMQConnection(java.lang.String host,
                     int port,
                     boolean useSSL,
                     java.lang.String username,
                     java.lang.String password,
                     java.lang.String clientName,
                     java.lang.String virtualHost)
              throws org.apache.qpid.AMQException,
                     org.apache.qpid.url.URLSyntaxException
Throws:
org.apache.qpid.AMQException
org.apache.qpid.url.URLSyntaxException

AMQConnection

public AMQConnection(java.lang.String connection)
              throws org.apache.qpid.AMQException,
                     org.apache.qpid.url.URLSyntaxException
Throws:
org.apache.qpid.AMQException
org.apache.qpid.url.URLSyntaxException

AMQConnection

public AMQConnection(ConnectionURL connectionURL)
              throws org.apache.qpid.AMQException
Throws:
org.apache.qpid.AMQException

AMQConnection

protected AMQConnection(java.lang.String username,
                        java.lang.String password,
                        java.lang.String clientName,
                        java.lang.String virtualHost)
Method Detail

checkException

protected boolean checkException(java.lang.Throwable thrown)

attemptReconnection

public boolean attemptReconnection(java.lang.String host,
                                   int port,
                                   boolean useSSL)

attemptReconnection

public boolean attemptReconnection()

getActiveBrokerDetails

public BrokerDetails getActiveBrokerDetails()
Get the details of the currently active broker

Returns:
null if no broker is active (i.e. no successful connection has been made, or the BrokerDetail instance otherwise

failoverAllowed

public boolean failoverAllowed()

createSession

public javax.jms.Session createSession(boolean transacted,
                                       int acknowledgeMode)
                                throws javax.jms.JMSException
Specified by:
createSession in interface javax.jms.Connection
Throws:
javax.jms.JMSException

createSession

public Session createSession(boolean transacted,
                             int acknowledgeMode,
                             int prefetch)
                      throws javax.jms.JMSException
Throws:
javax.jms.JMSException

createSession

public Session createSession(boolean transacted,
                             int acknowledgeMode,
                             int prefetchHigh,
                             int prefetchLow)
                      throws javax.jms.JMSException
Throws:
javax.jms.JMSException

setFailoverPolicy

public void setFailoverPolicy(FailoverPolicy policy)

getFailoverPolicy

public FailoverPolicy getFailoverPolicy()

createQueueSession

public javax.jms.QueueSession createQueueSession(boolean transacted,
                                                 int acknowledgeMode)
                                          throws javax.jms.JMSException
Returns an AMQQueueSessionAdaptor which wraps an AMQSession and throws IllegalStateExceptions where specified in the JMS spec

Specified by:
createQueueSession in interface javax.jms.QueueConnection
Parameters:
transacted -
acknowledgeMode -
Returns:
QueueSession
Throws:
javax.jms.JMSException

createTopicSession

public javax.jms.TopicSession createTopicSession(boolean transacted,
                                                 int acknowledgeMode)
                                          throws javax.jms.JMSException
Returns an AMQTopicSessionAdapter which wraps an AMQSession and throws IllegalStateExceptions where specified in the JMS spec

Specified by:
createTopicSession in interface javax.jms.TopicConnection
Parameters:
transacted -
acknowledgeMode -
Returns:
TopicSession
Throws:
javax.jms.JMSException

getClientID

public java.lang.String getClientID()
                             throws javax.jms.JMSException
Specified by:
getClientID in interface javax.jms.Connection
Throws:
javax.jms.JMSException

setClientID

public void setClientID(java.lang.String clientID)
                 throws javax.jms.JMSException
Specified by:
setClientID in interface javax.jms.Connection
Throws:
javax.jms.JMSException

getMetaData

public javax.jms.ConnectionMetaData getMetaData()
                                         throws javax.jms.JMSException
Specified by:
getMetaData in interface javax.jms.Connection
Throws:
javax.jms.JMSException

getExceptionListener

public javax.jms.ExceptionListener getExceptionListener()
                                                 throws javax.jms.JMSException
Specified by:
getExceptionListener in interface javax.jms.Connection
Throws:
javax.jms.JMSException

setExceptionListener

public void setExceptionListener(javax.jms.ExceptionListener listener)
                          throws javax.jms.JMSException
Specified by:
setExceptionListener in interface javax.jms.Connection
Throws:
javax.jms.JMSException

start

public void start()
           throws javax.jms.JMSException
Start the connection, i.e. start flowing messages. Note that this method must be called only from a single thread and is not thread safe (which is legal according to the JMS specification).

Specified by:
start in interface javax.jms.Connection
Throws:
javax.jms.JMSException

stop

public void stop()
          throws javax.jms.JMSException
Specified by:
stop in interface javax.jms.Connection
Throws:
javax.jms.JMSException

close

public void close()
           throws javax.jms.JMSException
Specified by:
close in interface javax.jms.Connection
Specified by:
close in class Closeable
Throws:
javax.jms.JMSException

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             java.lang.String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Specified by:
createConnectionConsumer in interface javax.jms.Connection
Throws:
javax.jms.JMSException

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Queue queue,
                                                             java.lang.String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Specified by:
createConnectionConsumer in interface javax.jms.QueueConnection
Throws:
javax.jms.JMSException

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Topic topic,
                                                             java.lang.String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Specified by:
createConnectionConsumer in interface javax.jms.TopicConnection
Throws:
javax.jms.JMSException

createDurableConnectionConsumer

public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic,
                                                                    java.lang.String subscriptionName,
                                                                    java.lang.String messageSelector,
                                                                    javax.jms.ServerSessionPool sessionPool,
                                                                    int maxMessages)
                                                             throws javax.jms.JMSException
Specified by:
createDurableConnectionConsumer in interface javax.jms.Connection
Specified by:
createDurableConnectionConsumer in interface javax.jms.TopicConnection
Throws:
javax.jms.JMSException

getMaximumChannelCount

public long getMaximumChannelCount()
                            throws javax.jms.JMSException
Throws:
javax.jms.JMSException

setConnectionListener

public void setConnectionListener(ConnectionListener listener)

getConnectionListener

public ConnectionListener getConnectionListener()

setMaximumChannelCount

public void setMaximumChannelCount(long maximumChannelCount)

setMaximumFrameSize

public void setMaximumFrameSize(long frameMax)

getMaximumFrameSize

public long getMaximumFrameSize()

getSessions

public java.util.Map getSessions()

getUsername

public java.lang.String getUsername()

getPassword

public java.lang.String getPassword()

getVirtualHost

public java.lang.String getVirtualHost()

getProtocolHandler

public AMQProtocolHandler getProtocolHandler()

bytesSent

public void bytesSent(long writtenBytes)

bytesReceived

public void bytesReceived(long receivedBytes)

firePreFailover

public boolean firePreFailover(boolean redirect)
Fire the preFailover event to the registered connection listener (if any)

Parameters:
redirect - true if this is the result of a redirect request rather than a connection error
Returns:
true if no listener or listener does not veto change

firePreResubscribe

public boolean firePreResubscribe()
                           throws javax.jms.JMSException
Fire the preResubscribe event to the registered connection listener (if any). If the listener vetoes resubscription then all the sessions are closed.

Returns:
true if no listener or listener does not veto resubscription.
Throws:
javax.jms.JMSException

fireFailoverComplete

public void fireFailoverComplete()
Fires a failover complete event to the registered connection listener (if any).


getFailoverMutex

public final java.lang.Object getFailoverMutex()
In order to protect the consistency of the connection and its child sessions, consumers and producers, the "failover mutex" must be held when doing any operations that could be corrupted during failover.

Returns:
a mutex. Guaranteed never to change for the lifetime of this connection even if failover occurs.

blockUntilNotFailingOver

public void blockUntilNotFailingOver()
                              throws java.lang.InterruptedException
If failover is taking place this will block until it has completed. If failover is not taking place it will return immediately.

Throws:
java.lang.InterruptedException

exceptionReceived

public void exceptionReceived(java.lang.Throwable cause)
Invoked by the AMQProtocolSession when a protocol session exception has occurred. This method sends the exception to a JMS exception listener, if configured, and propagates the exception to sessions, which in turn will propagate to consumers. This allows synchronous consumers to have exceptions thrown to them.

Parameters:
cause - the exception

resubscribeSessions

public void resubscribeSessions()
                         throws javax.jms.JMSException,
                                org.apache.qpid.AMQException
For all sessions, and for all consumers in those sessions, resubscribe. This is called during failover handling. The caller must hold the failover mutex before calling this method.

Throws:
javax.jms.JMSException
org.apache.qpid.AMQException

toString

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

toURL

public java.lang.String toURL()

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Specified by:
getReference in interface javax.naming.Referenceable
Throws:
javax.naming.NamingException