You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ar...@apache.org on 2007/09/17 14:07:57 UTC

svn commit: r576388 - /incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java

Author: arnaudsimon
Date: Mon Sep 17 05:07:56 2007
New Revision: 576388

URL: http://svn.apache.org/viewvc?rev=576388&view=rev
Log:
0_10 implementation

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java?rev=576388&r1=576387&r2=576388&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java Mon Sep 17 05:07:56 2007
@@ -5,39 +5,101 @@
 import javax.jms.JMSException;
 
 import org.apache.qpid.AMQException;
+import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.client.failover.FailoverException;
 import org.apache.qpid.jms.BrokerDetails;
 import org.apache.qpid.jms.Session;
+import org.apache.qpidity.client.Client;
+import org.apache.qpidity.QpidException;
+import org.apache.qpidity.jms.SessionImpl;
+import org.apache.qpidity.jms.ExceptionHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate
 {
-
+    /**
+     * This class logger.
+     */
     private static final Logger _logger = LoggerFactory.getLogger(AMQConnectionDelegate_0_10.class);
+
+    /**
+     * The AMQ Connection.
+     */
     private AMQConnection _conn;
 
+    /**
+     * The QpidConeection instance that is mapped with thie JMS connection.
+     */
+    org.apache.qpidity.client.Connection _qpidConnection;
+
+    //--- constructor
     public AMQConnectionDelegate_0_10(AMQConnection conn)
     {
         _conn = conn;
     }
 
-    public Session createSession(boolean transacted, int acknowledgeMode, int prefetchHigh, int prefetchLow) throws JMSException
+    /**
+     * create a Session and start it if required.
+     */
+    public Session createSession(boolean transacted, int acknowledgeMode, int prefetchHigh, int prefetchLow)
+            throws JMSException
     {
-        // TODO Auto-generated method stub
-        return null;
+        _conn.checkNotClosed();
+        int channelId = _conn._idFactory.incrementAndGet();
+        AMQSession session =
+                new AMQSession_0_10(_conn, channelId, transacted, acknowledgeMode, prefetchHigh, prefetchLow);
+        try
+        {
+            // create the qpid session with an expiry  <= 0 so that the session does not expire
+            _qpidConnection.createSession(0);
+            _conn.registerSession(channelId, session);
+            if (_conn._started)
+            {
+                session.start();
+            }
+        }
+        catch (Exception e)
+        {
+            throw new JMSAMQException("cannot create session", e);
+        }
+        return session;
     }
 
+    /**
+     * Make a connection with the broker
+     *
+     * @param brokerDetail The detail of the broker to connect to.
+     * @throws IOException
+     * @throws AMQException
+     */
     public void makeBrokerConnection(BrokerDetails brokerDetail) throws IOException, AMQException
     {
-        // TODO Auto-generated method stub
-
+        _qpidConnection = Client.createConnection();
+        try
+        {
+            if (_logger.isDebugEnabled())
+            {
+                _logger.debug("creating connection with broker " + " host: " + brokerDetail
+                        .getHost() + " port: " + brokerDetail.getPort() + " virtualhost: " + _conn
+                        .getVirtualHost() + "user name: " + _conn.getUsername() + "password: " + _conn.getPassword());
+            }
+            _qpidConnection.connect(brokerDetail.getHost(), brokerDetail.getPort(), _conn.getVirtualHost(),
+                                    _conn.getUsername(), _conn.getPassword());
+        }
+        catch (QpidException e)
+        {
+            throw new AMQException(AMQConstant.CHANNEL_ERROR, "cannot connect to broker", e);
+        }
     }
 
+    /**
+     * Not supported at this level.
+     */
     public void resubscribeSessions() throws JMSException, AMQException, FailoverException
     {
-        // TODO Auto-generated method stub
-
+       //NOT implemented as railover is handled at a lower level
+       throw new FailoverException("failing to reconnect during failover, operation not supported.");
     }
 
 }