Author: rajith
Date: Tue Jan 29 14:24:40 2008
New Revision: 616542

URL: http://svn.apache.org/viewvc?rev=616542&view=rev
Log:
added support to notify connection.close to the JMSExceptionListener

Modified:
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
    
incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
    
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java?rev=616542&r1=616541&r2=616542&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
 Tue Jan 29 14:24:40 2008
@@ -25,6 +25,8 @@
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
@@ -32,6 +34,12 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession_0_10;
+import org.apache.qpidity.nclient.Client;
+import org.apache.qpidity.transport.Option;
+
 /**
  * Message producer example, sends message to a queue.
  */
@@ -73,13 +81,22 @@
             Context ctx = new InitialContext(properties);
 
             // look up destination
-            Destination destination = (Destination)ctx.lookup("directQueue");
+            //Destination destination = (Destination)ctx.lookup("directQueue");
+            Destination destination = new AMQQueue("amq.fancy","myQeueu");
 
             // Lookup the connection factory
             ConnectionFactory conFac = 
(ConnectionFactory)ctx.lookup("qpidConnectionfactory");
             // create the connection
             Connection connection = conFac.createConnection();
 
+            connection.setExceptionListener(new ExceptionListener()
+            {
+                public void onException(JMSException e)
+                {
+                    e.printStackTrace();
+                }
+            });
+
             // Create a session on the connection
             // This session is a default choice of non-transacted and uses the 
auto acknowledge feature of a session.
             System.out.println(CLASS + ": Creating a non-transacted, 
auto-acknowledged session");
@@ -91,6 +108,17 @@
             // Create a Message producer
             System.out.println(CLASS + ": Creating a Message Producer");
             MessageProducer messageProducer = 
session.createProducer(destination);
+
+            try{
+                org.apache.qpidity.nclient.Connection con = 
Client.createConnection();
+                con.connect("qpid:password=pass;[EMAIL 
PROTECTED]:localhost:5672");
+                org.apache.qpidity.nclient.Session ses = 
con.createSession(1000000);
+                ses.exchangeDelete("amq.direct", Option.NO_OPTION);
+            }
+            catch(Exception e)
+            {
+                e.printStackTrace();
+            }
 
             // Create a Message
             TextMessage message;

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=616542&r1=616541&r2=616542&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
 Tue Jan 29 14:24:40 2008
@@ -11,11 +11,13 @@
 import org.apache.qpid.jms.BrokerDetails;
 import org.apache.qpid.jms.Session;
 import org.apache.qpidity.nclient.Client;
+import org.apache.qpidity.nclient.ClosedListener;
+import org.apache.qpidity.ErrorCode;
 import org.apache.qpidity.QpidException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate
+public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, 
ClosedListener
 {
     /**
      * This class logger.
@@ -137,5 +139,14 @@
             throw new AMQException(AMQConstant.CHANNEL_ERROR, "cannot close 
connection", e);
         }
 
+    }
+
+    public void onClosed(ErrorCode errorCode, String reason)
+    {
+        if (_logger.isDebugEnabled())
+        {
+            _logger.debug("Received a connection close from the broker: Error 
code : " + errorCode.getCode());
+        }
+        _conn._exceptionListener.onException(new 
JMSException(reason,String.valueOf(errorCode.getCode())));
     }
 }

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java?rev=616542&r1=616541&r2=616542&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
 Tue Jan 29 14:24:40 2008
@@ -5,10 +5,10 @@
     //Qpid specific - for the time being
     UNDEFINED(1,"undefined",true),
     MESSAGE_REJECTED(1,"message_rejected",true),
-    
+
     //This might change in the spec, the error class is not applicable
     NO_ERROR(200,"reply-success",true),
-    
+
     //From the spec
     CONTENT_TOO_LARGE(311,"content-too-large",false),
     NO_ROUTE(312,"no-route",false),
@@ -16,10 +16,10 @@
     CONNECTION_FORCED(320,"connection-forced",true),
     INVALID_PATH(402,"invalid-path",true),
     ACCESS_REFUSED(403,"access-refused",false),
-    NOT_FOUND(404,"not-found",false),    
-    RESOURCE_LOCKED(405,"resource-locked",false),    
+    NOT_FOUND(404,"not-found",false),
+    RESOURCE_LOCKED(405,"resource-locked",false),
     PRE_CONDITION_FAILED(406,"precondition-failed",false),
-    
+
     FRAME_ERROR(501,"frame_error",true),
     SYNTAX_ERROR(502,"syntax_error",true),
     COMMAND_INVALID(503,"command_invalid",true),
@@ -28,11 +28,11 @@
     NOT_IMPLEMENTED(540,"not_implemented",true),
     INTERNAL_ERROR(541,"internal_error",true),
     INVALID_ARGUMENT(542,"invalid_argument",true);
-        
+
     private int _code;
     private String _desc;
     private boolean _hardError;
-    
+
     private ErrorCode(int code,String desc,boolean hardError)
     {
         _code = code;
@@ -49,12 +49,12 @@
     {
         return _desc;
     }
-    
+
     private boolean isHardError()
     {
         return _hardError;
     }
-    
+
     public static ErrorCode get(int code)
     {
         switch(code)
@@ -72,17 +72,16 @@
             case 501 : return FRAME_ERROR;
             case 502 : return SYNTAX_ERROR;
             case 503 : return COMMAND_INVALID;
-            case 504 : return SESSION_ERROR;            
+            case 504 : return SESSION_ERROR;
             case 530 : return NOT_ALLOWED;
             case 540 : return NOT_IMPLEMENTED;
             case 541 : return INTERNAL_ERROR;
             case 542 : return INVALID_ARGUMENT;
-            
+
             default : return UNDEFINED;
         }
     }
-    
-}
+ }
 
 /*
 


Reply via email to