[jboss-cvs] JBoss Messaging SVN: r1592 - branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 20 06:29:46 EST 2006
Author: juha at jboss.org
Date: 2006-11-20 06:29:44 -0500 (Mon, 20 Nov 2006)
New Revision: 1592
Added:
branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery/MessagingXAResourceRecovery.java
Log:
Original patch (JBMessaging-407). Integration code for standalone JBossTS and JBMessaging implementations. Integration on JBossAS should use the JMSProviderXAResourceRecovery implementation instead.
Added: branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery/MessagingXAResourceRecovery.java
===================================================================
--- branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery/MessagingXAResourceRecovery.java 2006-11-20 11:29:31 UTC (rev 1591)
+++ branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery/MessagingXAResourceRecovery.java 2006-11-20 11:29:44 UTC (rev 1592)
@@ -0,0 +1,134 @@
+package org.jboss.jms.recovery;
+
+import java.sql.SQLException;
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XASession;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.logging.Logger;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
+import com.arjuna.ats.jta.recovery.XAResourceRecovery;
+
+public class MessagingXAResourceRecovery implements XAResourceRecovery {
+
+ private boolean trace = log.isTraceEnabled();
+
+ private static final Logger log = Logger.getLogger(MessagingXAResourceRecovery.class);
+
+ private boolean working = false;
+
+ private XAResource xaRes = null;
+
+ private String xaConnFactory = null;
+
+ public MessagingXAResourceRecovery() {
+ }
+
+ public XAResource getXAResource() throws SQLException {
+ if(trace)
+ log.trace("returning the xaresource "+xaRes);
+ return xaRes;
+ }
+
+ /**
+ * This method returns the Messaging XAResource reference.
+ * You have to pass the jndi name of the XAConnectionFactory
+ * via the JBossTS RecoveryManager's properties
+ * @return
+ */
+ public XAResource initXAResource() {
+ if(trace)
+ log.trace("Initialising xaresource..");
+ try {
+ Context ctx = new InitialContext();
+
+ XAConnectionFactory cf = (XAConnectionFactory) ctx
+ .lookup(xaConnFactory);
+
+ XAConnection xaConn = cf.createXAConnection();
+
+ XASession session = xaConn.createXASession();
+ xaRes = session.getXAResource();
+
+ if(trace)
+ log.trace("Found the xares: "+xaRes);
+
+ } catch (Exception e) {
+ // You may get this exception when the messaging server
+ // is not fully booted up. Nothing to worry, it'll keep
+ // trying until successful.
+ log.warn("XAConnectionFactory is not found. \n" +
+ "The messaging server is not yet initialized.\n" +
+ "we'll try again once server is fully back");
+
+ }
+
+ return xaRes;
+ }
+
+ /**
+ * This method is used to pass any
+ * intialisation parameters to this
+ * class
+ * @param param
+ * @return
+ * @throws SQLException
+ */
+ public boolean initialise(String param) throws SQLException
+ {
+ if(trace)
+ log.trace("Passed in parameter: "+param);
+
+ if(param != null)
+ {
+ // parama is in the form of name=value
+ String value = param.substring(param.indexOf("=")+1);
+
+ if(trace)
+ log.trace("The connection factory is "+value);
+
+ xaConnFactory = value;
+ }
+ else
+ {
+ log.debug("The XA connection factory parameter is null. " +
+ "Using the default 'XAConnectionFactory'");
+
+ xaConnFactory = "XAConnectionFactory";
+ }
+ return true;
+ }
+
+ /**
+ * This method checks whether there's an xa resource available
+ *
+ * @return
+ */
+ public boolean hasMoreResources() {
+
+ if (working)
+ return false;
+
+ if (xaRes == null) {
+ xaRes = initXAResource();
+ }
+
+ // test the resource
+ try {
+
+ xaRes.getTransactionTimeout();
+
+ working = true;
+
+ } catch (Exception ignored) {
+
+ // ignore this exception
+ }
+
+ return working;
+ }
+}
Property changes on: branches/Branch_1_0_XARecovery/src/main/org/jboss/jms/recovery/MessagingXAResourceRecovery.java
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-cvs-commits
mailing list