[jboss-svn-commits] JBL Code SVN: r7500 - in labs/jbossesb/trunk/product/core/rosetta/src/org/jboss: internal/soa/esb/couriers soa/esb/couriers

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 9 12:33:06 EST 2006


Author: estebanschifman
Date: 2006-11-09 12:33:02 -0500 (Thu, 09 Nov 2006)
New Revision: 7500

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
Log:
Two way courier concept and implementation

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java	2006-11-09 16:00:48 UTC (rev 7499)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java	2006-11-09 17:33:02 UTC (rev 7500)
@@ -26,6 +26,7 @@
 
 import javax.jms.Connection;
 import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.QueueConnection;
@@ -41,33 +42,38 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
-import org.jboss.soa.esb.couriers.Courier;
 import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.couriers.CourierTimeoutException;
 import org.jboss.soa.esb.helpers.AppServerContext;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.util.Util;
 
-public class JmsCourier implements Courier 
+public class JmsCourier implements PickUpCourier, DeliverCourier 
 {
 	/**
 	 * disable default constructor
 	 */
 	private JmsCourier() { }
+
 	/**
 	 * package protected constructor - Objects of Courier should only be instantiated by the Factory
 	 * @param epr
 	 */
-	public JmsCourier(JMSEpr epr) throws CourierException
+	JmsCourier(JMSEpr epr) throws CourierException { this(epr,false); }
+
+	/**
+	 * package protected constructor - Objects of Courier should only be instantiated by the Factory
+	 * @param epr
+	 */
+	JmsCourier(JMSEpr epr, boolean isReceiver) throws CourierException
 	{
-		_epr	= epr;
+		_isReceiver = isReceiver;
+		_epr		= epr;
 		_sleepForRetries	= 3000;
 
 		try 
 		{
 			_messageProperties = Util.propertiesFromSelector(_epr.getMessageSelector());
-			createMessageProducer(); 
 		}
 		catch (Exception e) { throw new CourierException(e); }
 		
@@ -78,12 +84,22 @@
 		if (null != _messageProducer)
 			try { _messageProducer.close(); }
 			catch (JMSException e) {/*  OK do nothing  */ }
+		_messageProducer = null;
+		
+		if (null != _messageConsumer)
+			try { _messageConsumer.close(); }
+			catch (JMSException e) {/*  OK do nothing  */ }
+		_messageConsumer = null;
+		
 		if (null != _jmsSession)
 			try { _jmsSession.close(); }
 			catch (JMSException e) {/*  OK do nothing  */ }
+		_jmsSession = null;
+		
 		if (null != _jmsConnection)
 			try { _jmsConnection.close(); }
 			catch (JMSException e) {/*  OK do nothing  */ }
+		_jmsConnection = null;
     } //________________________________
 
 	/**
@@ -94,9 +110,16 @@
 	 */
 	public boolean deliver(Message message) throws CourierException 
 	{
+		if (_isReceiver)
+			throw new CourierException("This is a read-only Courier");
+
 		if (null==message)
 			return false;
-		while (null!=_messageProducer)
+		if (null==_messageProducer)
+			try {  createMessageProducer();}
+			catch (Exception e) {throw new CourierException(e); }
+
+			while (null!=_messageProducer)
 		{
 			try 
 			{
@@ -107,12 +130,20 @@
 				sendMessage(msg);
 				return true;
 			}
-			catch (JMSException e)	{ jmsRetry(e); }
+			catch (JMSException e)	{ jmsRetryDeliver(e); }
 			catch (Exception e)		{ throw new CourierException(e);}
 		}
 		return false;
 	} //________________________________
 	
+	public Message pickUp(long millis) throws CourierException 
+	{
+		if (! _isReceiver)
+			throw new CourierException("This is an outgoing-only Courier");
+		// TODO Auto-generated method stub
+		return null;
+	}
+    
 	/**
 	 * send/publish a javax.jms.ObjectMessage (that will contain the serialized ESB Message)
 	 * @param jmsMessage
@@ -125,7 +156,7 @@
     		_messageProducer.send(jmsMessage);
     } //________________________________
     
-    private void jmsRetry(Exception exc)
+    private void jmsRetryDeliver(Exception exc)
     {
     	_logger.error("JMS error.  Attempting JMS reconnect.", exc);
         _jmsConnection	= null;
@@ -147,7 +178,7 @@
                 }
             }
 		}
-    }
+    } //________________________________
     
     protected void createMessageProducer() throws Exception
     {
@@ -192,43 +223,14 @@
                 
     } //________________________________
 
+    protected boolean			_isReceiver;	  
     protected JMSEpr			_epr;
     protected Logger			_logger = Logger.getLogger(JmsCourier.class);
     protected String 			_messageSelector;
     protected Connection 		_jmsConnection;
     protected Session 			_jmsSession;
     protected MessageProducer 	_messageProducer;
+    protected MessageConsumer	_messageConsumer;
     protected long 				_sleepForRetries = 3000;   //  milliseconds
     protected List<KeyValuePair> _messageProperties;
-    
-    
-	public Message deliverAndWaitForPickup(Message message, long waitTime) throws CourierException, CourierTimeoutException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-	public boolean deliverNext(Message message) throws CourierException {
-		// TODO Auto-generated method stub
-		return false;
-	}
-	public Message pickup(long waitTime) throws CourierException, CourierTimeoutException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-	public Message pickupNext(long waitTime) throws CourierException {
-		// TODO Auto-generated method stub
-		return null;
-	}
-	public void stopDurableDelivery()  {
-		// TODO Auto-generated method stub
-		
-	}
-	public void stopDurablePickup()  {
-		// TODO Auto-generated method stub
-		
-	}
-    
-    
-    
-    
-	
 }

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java	2006-11-09 16:00:48 UTC (rev 7499)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java	2006-11-09 17:33:02 UTC (rev 7500)
@@ -22,9 +22,8 @@
 
 package org.jboss.soa.esb.couriers;
 
-import org.jboss.internal.soa.esb.couriers.JmsCourier;
+import org.jboss.internal.soa.esb.couriers.TwoWayCourier;
 import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 
 public class CourierFactory 
 {
@@ -36,12 +35,20 @@
 		return _instance;
 	}
 	
-	public static Courier getCourier(EPR epr) throws CourierException
+	public static Courier getCourier(EPR outgoing) throws CourierException
 	{
-		if (epr instanceof JMSEpr)
-				return new JmsCourier((JMSEpr)epr);
-		throw new CourierException("Unknown EPR type");
+		return getCourier(outgoing,null);
 	}
 	
+	public static Courier getPickupCourier(EPR incoming) throws CourierException
+	{
+		return getCourier(null, incoming);
+	}
+	
+	public static Courier getCourier(EPR outgoing, EPR incoming) throws CourierException
+	{
+		return new TwoWayCourier(outgoing,incoming);
+	}
+	
 	private static final CourierFactory _instance = new CourierFactory();
 }




More information about the jboss-svn-commits mailing list