[jboss-svn-commits] JBL Code SVN: r20294 - in labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx: jts and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 4 08:03:32 EDT 2008


Author: jhalliday
Date: 2008-06-04 08:03:32 -0400 (Wed, 04 Jun 2008)
New Revision: 20294

Modified:
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerService.java
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerServiceMBean.java
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerService.java
   labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerServiceMBean.java
Log:
Convert TransactionManagerService from JMX to MC POJO style for better integration with AS 5.0.  JBTM-123


Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerService.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerService.java	2008-06-04 11:51:50 UTC (rev 20293)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerService.java	2008-06-04 12:03:32 UTC (rev 20294)
@@ -30,14 +30,13 @@
  */
 package com.arjuna.ats.jbossatx.jta;
 
-import org.jboss.mx.util.ObjectNameFactory;
-import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.system.server.Server;
 import org.jboss.system.server.ServerConfig;
 import org.jboss.tm.JBossXATerminator;
 import org.jboss.tm.LastResource;
 import org.jboss.tm.XAExceptionFormatter;
 
+import org.jboss.logging.Logger;
+
 import com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator;
 import com.arjuna.ats.internal.jbossatx.agent.LocalJBossAgentImpl;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple;
@@ -55,17 +54,12 @@
 import com.arjuna.common.util.propertyservice.PropertyManager;
 import com.arjuna.common.util.logging.LogFactory;
 
-import javax.management.InstanceNotFoundException;
-import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
+import javax.management.*;
 import javax.naming.Reference;
 import javax.naming.InitialContext;
 import javax.transaction.TransactionManager;
 import javax.transaction.UserTransaction;
 import java.net.Socket;
-import java.net.InetAddress;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
@@ -76,8 +70,27 @@
  * @author Richard A. Begg (richard.begg at arjuna.com)
  * @version $Id: TransactionManagerService.java,v 1.5 2005/06/24 15:24:15 kconner Exp $
  */
-public class TransactionManagerService extends ServiceMBeanSupport implements TransactionManagerServiceMBean, NotificationListener
+public class TransactionManagerService implements TransactionManagerServiceMBean
 {
+    /*
+    deploy/transaction-beans.xml:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+    <bean name="TransactionManager" class="com.arjuna.ats.jbossatx.jta.TransactionManagerService">
+        <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss:service=TransactionManager", exposedInterface=com.arjuna.ats.jbossatx.jta.TransactionManagerServiceMBean.class, registerDirectly=true)</annotation>
+
+        <property name="transactionTimeout">300</property>
+        <property name="objectStoreDir">${jboss.server.data.dir}/tx-object-store</property>
+        <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+    </bean>
+
+    </deployment>
+     */
+
+
+
     static {
 		/*
 		 * Override the defualt logging config, force use of the plugin that rewrites log levels to reflect app server level semantics.
@@ -89,8 +102,10 @@
 		//System.setProperty(LogFactory.LOGGER_PROPERTY, "log4j_releveler") ;
 	}
 
-	public final static String PROPAGATE_FULL_CONTEXT_PROPERTY = "com.arjuna.ats.jbossatx.jta.propagatefullcontext";
+    private final Logger log = org.jboss.logging.Logger.getLogger(TransactionManagerService.class);
 
+    public final static String PROPAGATE_FULL_CONTEXT_PROPERTY = "com.arjuna.ats.jbossatx.jta.propagatefullcontext";
+
     private final static String SERVICE_NAME = "TransactionManagerService";
     private final static String PROPAGATION_CONTEXT_IMPORTER_JNDI_REFERENCE = "java:/TransactionPropagationContextImporter";
     private final static String PROPAGATION_CONTEXT_EXPORTER_JNDI_REFERENCE = "java:/TransactionPropagationContextExporter";
@@ -99,9 +114,12 @@
 	private RecoveryManager _recoveryManager;
     private boolean _runRM = true;
     private int timeout ;
-    private boolean started ;
-    private byte[] startedLock = new byte[0] ;
 
+    private boolean configured;
+    private byte[] configuredLock = new byte[0] ;
+
+    private MBeanServer mbeanServer;
+
     /**
      * Use the short class name as the default for the service name.
      */
@@ -110,32 +128,27 @@
         return SERVICE_NAME;
     }
 
-    /**
-     * Sub-classes should override this method to provide
-     * custum 'start' logic.
-     *
-     * <p>This method is empty, and is provided for convenience
-     *    when concrete service classes do not need to perform
-     *    anything specific for this state change.
-     */
-    protected void startService() throws Exception
+    public TransactionManagerService() {}
+
+
+    public void create() throws Exception
     {
-	synchronized(startedLock)
-	{
-	    started = true ;
-	}
+        synchronized(configuredLock)
+        {
+            configured = true ;
+        }
 
-        this.getLog().info("JBossTS Transaction Service (JTA version) - JBoss Inc.");
+        log.info("JBossTS Transaction Service (JTA version) - JBoss Inc.");
 
-        this.getLog().info("Setting up property manager MBean and JMX layer");
+        log.info("Setting up property manager MBean and JMX layer");
 
         /** Set the tsmx agent implementation to the local JBOSS agent impl **/
-        LocalJBossAgentImpl.setLocalAgent(this.getServer());
+        LocalJBossAgentImpl.setLocalAgent( getMbeanServer() );
         System.setProperty(com.arjuna.ats.tsmx.TransactionServiceMX.AGENT_IMPLEMENTATION_PROPERTY,
                 com.arjuna.ats.internal.jbossatx.agent.LocalJBossAgentImpl.class.getName());
         System.setProperty(Environment.LAST_RESOURCE_OPTIMISATION_INTERFACE, LastResource.class.getName()) ;
         System.setProperty(com.arjuna.ats.arjuna.common.Environment.SERVER_BIND_ADDRESS, System.getProperty(ServerConfig.SERVER_BIND_ADDRESS));
-        
+
         if (timeout != 0)
         {
             TxControl.setDefaultTimeout(timeout);
@@ -156,7 +169,7 @@
         }
         catch (Exception e)
         {
-            this.getLog().fatal("Failed to create and register Propagation Context Manager", e);
+            log.fatal("Failed to create and register Propagation Context Manager", e);
         }
 
         /** Start the recovery manager **/
@@ -164,24 +177,22 @@
         {
             if (_runRM)
             {
-                registerNotification() ;
+                log.info("Initializing recovery manager");
 
-                this.getLog().info("Starting recovery manager");
-
                 RecoveryManager.delayRecoveryManagerThread() ;
                 _recoveryManager = RecoveryManager.manager() ;
 
-                this.getLog().info("Recovery manager started");
+                log.info("Recovery manager configured");
             }
             else
             {
                 if (isRecoveryManagerRunning())
                 {
-                    this.getLog().info("Using external recovery manager");
+                    log.info("Using external recovery manager");
                 }
                 else
                 {
-                    this.getLog().fatal("Recovery manager not found - please refer to the JBossTS documentation for details");
+                    log.fatal("Recovery manager not found - please refer to the JBossTS documentation for details");
 
                     throw new Exception("Recovery manager not found - please refer to the JBossTS documentation for details");
                 }
@@ -189,12 +200,12 @@
         }
         catch (Exception e)
         {
-            this.getLog().fatal("Failed to start recovery manager", e);
+            log.fatal("Failed to initialize recovery manager", e);
             throw e;
         }
 
         /** Bind the transaction manager and tsr JNDI references **/
-        this.getLog().info("Binding TransactionManager JNDI Reference");
+        log.info("Binding TransactionManager JNDI Reference");
 
         jtaPropertyManager.propertyManager.setProperty(Environment.JTA_TM_IMPLEMENTATION, TransactionManagerDelegate.class.getName());
         jtaPropertyManager.propertyManager.setProperty(Environment.JTA_UT_IMPLEMENTATION, UserTransactionImple.class.getName());
@@ -208,13 +219,12 @@
 		JNDIManager.bindJTATransactionSynchronizationRegistryImplementation();
 	}
 
-    /**
-     * Handle JMX notification.
-     * @param notification The JMX notification event.
-     * @param param The notification parameter.
-     */
-    public void handleNotification(final Notification notification, final Object param)
+    public void start()
     {
+        log.info("Starting transaction recovery manager");
+
+        // TODO: any point in breaking out the recovery mgr into its own bean w/ own lifecycle?
+        // may impact recovery config e.g. beans injection instead of XAResourceRecoveryRegistry lookup?
         _recoveryManager.startRecoveryManagerThread() ;
     }
 
@@ -245,7 +255,7 @@
             }
             catch (Exception ex)
             {
-                getLog().error("Failed to connect to recovery manager", ex);
+                log.error("Failed to connect to recovery manager", ex);
                 active = false;
             }
             finally
@@ -265,19 +275,12 @@
         return active;
     }
 
-    /**
-     * Sub-classes should override this method to provide
-     * custum 'destroy' logic.
-     *
-     * <p>This method is empty, and is provided for convenience
-     *    when concrete service classes do not need to perform
-     *    anything specific for this state change.
-     */
-    protected void destroyService() throws Exception
+
+    public void stop() throws Exception
     {
         if (_runRM)
         {
-            this.getLog().info("Stopping recovery manager");
+            log.info("Stopping transaction recovery manager");
 
             _recoveryManager.stop();
         }
@@ -293,13 +296,13 @@
      */
     public void setTransactionTimeout(int timeout) throws IllegalStateException
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
-            if (started)
+            if (configured)
             {
         	if (this.timeout != timeout)
         	{
-        	    throw new IllegalStateException("Cannot set transaction timeout once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set transaction timeout once MBean has configured") ;
         	}
             }
             else
@@ -317,9 +320,9 @@
      */
     public int getTransactionTimeout()
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
-	    return (started ? timeout : TxControl.getDefaultTimeout()) ;
+	    return (configured ? timeout : TxControl.getDefaultTimeout()) ;
 	}
     }
 
@@ -399,7 +402,7 @@
      */
     public void registerXAExceptionFormatter(Class c, XAExceptionFormatter f)
     {
-        this.getLog().warn("XAExceptionFormatters are not supported by the JBossTS Transaction Service - this warning can safely be ignored");
+        log.warn("XAExceptionFormatters are not supported by the JBossTS Transaction Service - this warning can safely be ignored");
     }
 
     /**
@@ -449,13 +452,13 @@
     public void setRunInVMRecoveryManager(boolean runRM)
         throws IllegalStateException
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
-            if (started)
+            if (configured)
             {
         	if (this._runRM != runRM)
         	{
-        	    throw new IllegalStateException("Cannot set run in VM recovery manager once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set run in VM recovery manager once MBean has configured") ;
         	}
             }
             else
@@ -474,7 +477,7 @@
      */
     public boolean getRunInVMRecoveryManager()
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
 	    return _runRM ;
 	}
@@ -489,15 +492,15 @@
     public void setObjectStoreDir(final String objectStoreDir)
     	throws IllegalStateException
     {
-        synchronized(startedLock)
+        synchronized(configuredLock)
         {
-            if (started)
+            if (configured)
             {
         	final String currentDir = getObjectStoreDir() ;
         	final boolean equal = (currentDir == null ? objectStoreDir == null : currentDir.equals(objectStoreDir)) ;
         	if (!equal)
         	{
-        	    throw new IllegalStateException("Cannot set object store dir once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set object store dir once MBean has configured") ;
         	}
             }
             else
@@ -516,17 +519,31 @@
 	return System.getProperty(com.arjuna.ats.arjuna.common.Environment.OBJECTSTORE_DIR) ;
     }
 
-    private void registerNotification()
-        throws InstanceNotFoundException
-    {
-        final NotificationFilterSupport notificationFilter = new NotificationFilterSupport() ;
-        notificationFilter.enableType(Server.START_NOTIFICATION_TYPE) ;
 
-        final ObjectName serverName = ObjectNameFactory.create("jboss.system:type=Server") ;
 
-        getServer().addNotificationListener(serverName, this, notificationFilter, null) ;
+    public MBeanServer getMbeanServer()
+    {
+        return mbeanServer;
     }
 
+    public void setMbeanServer(MBeanServer mbeanServer)
+    {
+        synchronized(configuredLock)
+        {
+            if (configured)
+            {
+                if (this.mbeanServer != mbeanServer)
+                {
+                    throw new IllegalStateException("Cannot set MBeanServer once MBean has configured") ;
+                }
+            }
+            else
+            {
+                this.mbeanServer = mbeanServer;
+            }
+        }
+    }
+
     private void bindRef(String jndiName, String className)
             throws Exception
     {

Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerServiceMBean.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerServiceMBean.java	2008-06-04 11:51:50 UTC (rev 20293)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jta/TransactionManagerServiceMBean.java	2008-06-04 12:03:32 UTC (rev 20294)
@@ -1,20 +1,20 @@
 /*
  * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
- * as indicated by the @author tags. 
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
  * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
+ * full listing of individual contributors.
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
  * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
- * 
+ *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
@@ -43,14 +43,14 @@
  * @author Richard A. Begg (richard.begg at arjuna.com)
  * @version $Id: TransactionManagerServiceMBean.java,v 1.3 2005/06/17 10:53:51 kconner Exp $
  */
-public interface TransactionManagerServiceMBean extends org.jboss.system.ServiceMBean
+public interface TransactionManagerServiceMBean
 {
     /**
      * Set the default transaction timeout used by this transaction manager.
      *
      * @param timeout The default timeout in seconds for all transactions created
      * using this transaction manager.
-     * 
+     *
      * @throws IllegalStateException if the MBean has already started.
      */
     public void setTransactionTimeout(int timeout) throws IllegalStateException ;
@@ -96,10 +96,10 @@
      * @return A reference to the JTA transaction manager.
      */
     public TransactionManager getTransactionManager();
-    
+
     /**
      * Get the XA Terminator
-     * 
+     *
      * @return the XA Terminator
      */
     public JBossXATerminator getXATerminator() ;
@@ -146,7 +146,7 @@
      * JBoss.  If this is false the Recovery Manager is already expected to
      * be running when JBoss starts.
      * @param runRM
-     * 
+     *
      * @throws IllegalStateException If the MBean has already started.
      */
     public void setRunInVMRecoveryManager(boolean runRM) throws IllegalStateException ;
@@ -155,7 +155,7 @@
      * Get whether the recovery manager should be ran in the same VM as
      * JBoss.  If this is false the Recovery Manager is already expected to
      * be running when JBoss starts.
-     * 
+     *
      * @return true if the recover manager is running in the same VM, false otherwise.
      */
     public boolean getRunInVMRecoveryManager() ;
@@ -163,12 +163,12 @@
     /**
      * Set the object store directory.
      * @param objectStoreDir The object store directory.
-     * 
+     *
      * @throws IllegalStateException if the MBean has already started.
      */
     public void setObjectStoreDir(final String objectStoreDir) throws IllegalStateException ;
-    
-    
+
+
     /**
      * Get the object store directory.
      * @return objectStoreDir The object store directory.

Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerService.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerService.java	2008-06-04 11:51:50 UTC (rev 20293)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerService.java	2008-06-04 12:03:32 UTC (rev 20294)
@@ -30,14 +30,12 @@
  */
 package com.arjuna.ats.jbossatx.jts;
 
-import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.system.server.Server;
 import org.jboss.system.server.ServerConfig;
 import org.jboss.iiop.CorbaORBService;
-import org.jboss.mx.util.ObjectNameFactory;
 import org.jboss.tm.JBossXATerminator;
 import org.jboss.tm.LastResource;
 import org.jboss.tm.XAExceptionFormatter;
+import org.jboss.logging.Logger;
 import com.arjuna.ats.internal.jbossatx.jts.PropagationContextWrapper;
 import com.arjuna.ats.internal.jbossatx.jts.jca.XATerminator;
 import com.arjuna.ats.internal.jbossatx.agent.LocalJBossAgentImpl;
@@ -59,11 +57,7 @@
 import com.arjuna.common.util.propertyservice.PropertyManager;
 import com.arjuna.common.util.logging.LogFactory;
 
-import javax.management.InstanceNotFoundException;
-import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
+import javax.management.*;
 import javax.naming.Reference;
 import javax.naming.InitialContext;
 import javax.transaction.TransactionManager;
@@ -81,9 +75,33 @@
  * @author Richard A. Begg (richard.begg at arjuna.com)
  * @version $Id: TransactionManagerService.java,v 1.17 2005/06/24 15:24:14 kconner Exp $
  */
-public class TransactionManagerService extends ServiceMBeanSupport implements TransactionManagerServiceMBean, NotificationListener
+public class TransactionManagerService implements TransactionManagerServiceMBean
 {
-	static {
+    /*
+    deploy/transaction-beans.xml:
+
+    <?xml version="1.0" encoding="UTF-8"?>
+    <deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+    <bean name="TransactionManager" class="com.arjuna.ats.jbossatx.jts.TransactionManagerService">
+        <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss:service=TransactionManager", exposedInterface=
+com.arjuna.ats.jbossatx.jts.TransactionManagerServiceMBean.class, registerDirectly=true)</annotation>
+
+        <property name="transactionTimeout">300</property>
+        <property name="objectStoreDir">${jboss.server.data.dir}/tx-object-store</property>
+        <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+
+        <start>
+               <parameter><inject bean="jboss:service=CorbaORB" property="ORB"/></parameter>
+        </start>
+
+    </bean>
+
+
+    </deployment>
+     */
+
+    static {
 		/*
 		 * Override the defualt logging config, force use of the plugin that rewrites log levels to reflect app server level semantics.
 		 * This must be done before the loading of anything that uses the logging, otherwise it's too late to take effect.
@@ -94,6 +112,8 @@
 		//System.setProperty(LogFactory.LOGGER_PROPERTY, "log4j_releveler") ;
 	}
 
+    private final Logger log = org.jboss.logging.Logger.getLogger(TransactionManagerService.class);
+
     private final static String SERVICE_NAME = "TransactionManagerService";
     private final static String PROPAGATION_CONTEXT_IMPORTER_JNDI_REFERENCE = "java:/TransactionPropagationContextImporter";
     private final static String PROPAGATION_CONTEXT_EXPORTER_JNDI_REFERENCE = "java:/TransactionPropagationContextExporter";
@@ -102,8 +122,11 @@
     private RecoveryManager _recoveryManager;
     private boolean _runRM = true;
     private boolean alwaysPropagateContext = true ;
-    private boolean started ;
-    private byte[] startedLock = new byte[0] ;
+
+    private boolean configured;
+    private byte[] configuredLock = new byte[0] ;
+
+    private MBeanServer mbeanServer;
     /**
      * Use the short class name as the default for the service name.
      */
@@ -112,29 +135,24 @@
         return SERVICE_NAME;
     }
 
-    /**
-     * Sub-classes should override this method to provide
-     * custum 'start' logic.
-     *
-     * <p>This method is empty, and is provided for convenience
-     *    when concrete service classes do not need to perform
-     *    anything specific for this state change.
-     */
-    protected void startService() throws Exception
+    public TransactionManagerService() {}
+
+
+    public void create() throws Exception
     {
-	synchronized(startedLock)
-	{
-	    started = true ;
-	}
+        synchronized(configuredLock)
+        {
+            configured = true ;
+        }
 
-        ORB orb = null;
 
-        this.getLog().info("JBossTS Transaction Service - JBoss Inc.");
 
-        this.getLog().info("Setting up property manager MBean and JMX layer");
+        log.info("JBossTS Transaction Service (JTS version) - JBoss Inc.");
 
+        log.info("Setting up property manager MBean and JMX layer");
+
         /** Set the tsmx agent implementation to the local JBOSS agent impl **/
-        LocalJBossAgentImpl.setLocalAgent(this.getServer());
+        LocalJBossAgentImpl.setLocalAgent( getMbeanServer() );
         System.setProperty(com.arjuna.ats.tsmx.TransactionServiceMX.AGENT_IMPLEMENTATION_PROPERTY,
                 com.arjuna.ats.internal.jbossatx.agent.LocalJBossAgentImpl.class.getName());
         System.setProperty(Environment.LAST_RESOURCE_OPTIMISATION_INTERFACE, LastResource.class.getName()) ;
@@ -156,50 +174,65 @@
             /** Bind the propagation context manager **/
             bindRef(PROPAGATION_CONTEXT_IMPORTER_JNDI_REFERENCE, com.arjuna.ats.internal.jbossatx.jts.PropagationContextManager.class.getName());
             bindRef(PROPAGATION_CONTEXT_EXPORTER_JNDI_REFERENCE, com.arjuna.ats.internal.jbossatx.jts.PropagationContextManager.class.getName());
+        }
+        catch (Exception e)
+        {
+            log.fatal("Failed to create and register ORB/OA", e);
+        }
 
+        /** Bind the transaction manager and tsr JNDI reference **/
+        log.info("Binding TransactionManager JNDI Reference");
+
+        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_TM_IMPLEMENTATION, TransactionManagerDelegate.class.getName());
+        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_UT_IMPLEMENTATION, UserTransactionImple.class.getName());
+
+        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_TSR_IMPLEMENTATION, TransactionSynchronizationRegistryImple.class.getName());
+        // When running inside the app server, we bind TSR in the JNDI java:/ space, not its required location.
+        // It's the job of individual components (EJB3, web, etc) to copy the ref to the java:/comp space)
+        jtaPropertyManager.propertyManager.setProperty(Environment.TSR_JNDI_CONTEXT, "java:/TransactionSynchronizationRegistry");
+
+        JNDIManager.bindJTATransactionManagerImplementation();
+		JNDIManager.bindJTATransactionSynchronizationRegistryImplementation();
+    }
+
+    public void start(org.omg.CORBA.ORB theCorbaORB) throws Exception
+    {
+        log.info("Starting transaction recovery manager");
+
+        try
+        {
             /** Create an ORB portability wrapper around the CORBA ORB services orb **/
-            orb = ORB.getInstance("jboss-atx");
+            ORB orb = ORB.getInstance("jboss-atx");
 
-            /** Retrieve ORB service's ORB and root POA **/
-            InitialContext ctx = new InitialContext();
-            org.omg.CORBA.ORB orbImpl = (org.omg.CORBA.ORB) ctx.lookup("java:/" + CorbaORBService.ORB_NAME);
-            org.omg.PortableServer.POA rootPOA = (org.omg.PortableServer.POA) ctx.lookup("java:/" + CorbaORBService.POA_NAME);
+            org.omg.PortableServer.POA rootPOA = org.omg.PortableServer.POAHelper.narrow(theCorbaORB.resolve_initial_references("RootPOA"));
 
-            orb.setOrb(orbImpl);
+            orb.setOrb(theCorbaORB);
             OA oa = OA.getRootOA(orb);
             oa.setPOA(rootPOA);
 
             RecoveryORBManager.setORB(orb);
             RecoveryORBManager.setPOA(oa);
-        }
-        catch (Exception e)
-        {
-            this.getLog().fatal("Failed to create and register ORB/OA", e);
-        }
 
-        /** Start the recovery manager **/
-        try
-        {
+            // Start the recovery manager
             if (_runRM)
             {
-                registerNotification() ;
+                log.info("Initializing recovery manager");
 
-                this.getLog().info("Starting recovery manager");
-
                 RecoveryManager.delayRecoveryManagerThread() ;
-                _recoveryManager = RecoveryManager.manager() ;
+                _recoveryManager = RecoveryManager.manager() ; // RecoveryORBManager must be set up before this
+                _recoveryManager.startRecoveryManagerThread() ;
 
-                this.getLog().info("Recovery manager started");
+                log.info("Recovery manager configured and started");
             }
             else
             {
                 if (isRecoveryManagerRunning())
                 {
-                    this.getLog().info("Using external recovery manager");
+                    log.info("Using external recovery manager");
                 }
                 else
                 {
-                    this.getLog().fatal("Recovery manager not found - please refer to the JBossTS documentation for details");
+                    log.fatal("Recovery manager not found - please refer to the JBossTS documentation for details");
 
                     throw new Exception("Recovery manager not found - please refer to the JBossTS documentation for details");
                 }
@@ -207,35 +240,13 @@
         }
         catch (Exception e)
         {
-            this.getLog().fatal("Failed to start recovery manager", e);
+            log.fatal("Failed to initialize recovery manager", e);
             throw e;
         }
+    }
 
-        /** Bind the transaction manager and tsr JNDI reference **/
-        this.getLog().info("Binding TransactionManager JNDI Reference");
 
-        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_TM_IMPLEMENTATION, TransactionManagerDelegate.class.getName());
-        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_UT_IMPLEMENTATION, UserTransactionImple.class.getName());
 
-        jtaPropertyManager.propertyManager.setProperty(Environment.JTA_TSR_IMPLEMENTATION, TransactionSynchronizationRegistryImple.class.getName());
-        // When running inside the app server, we bind TSR in the JNDI java:/ space, not its required location.
-        // It's the job of individual components (EJB3, web, etc) to copy the ref to the java:/comp space)
-        jtaPropertyManager.propertyManager.setProperty(Environment.TSR_JNDI_CONTEXT, "java:/TransactionSynchronizationRegistry");
-
-        JNDIManager.bindJTATransactionManagerImplementation();
-		JNDIManager.bindJTATransactionSynchronizationRegistryImplementation();
-    }
-
-    /**
-     * Handle JMX notification.
-     * @param notification The JMX notification event.
-     * @param param The notification parameter.
-     */
-    public void handleNotification(final Notification notification, final Object param)
-    {
-        _recoveryManager.startRecoveryManagerThread() ;
-    }
-
     private boolean isRecoveryManagerRunning() throws Exception
     {
         boolean active = false;
@@ -268,11 +279,11 @@
                     InetAddress host = RecoveryManager.getRecoveryManagerHost(getRunInVMRecoveryManager());
                     int port = RecoveryManager.getRecoveryManagerPort();
 
-                    getLog().error("Failed to connect to recovery manager on " + host.getHostAddress() + ':' + port);
+                    log.error("Failed to connect to recovery manager on " + host.getHostAddress() + ':' + port);
                 }
                 catch (UnknownHostException e)
                 {
-                    getLog().error("Failed to connect to recovery manager", ex);
+                    log.error("Failed to connect to recovery manager", ex);
                 }
 
                 active = false;
@@ -294,19 +305,11 @@
         return active;
     }
 
-    /**
-     * Sub-classes should override this method to provide
-     * custum 'destroy' logic.
-     *
-     * <p>This method is empty, and is provided for convenience
-     *    when concrete service classes do not need to perform
-     *    anything specific for this state change.
-     */
-    protected void destroyService() throws Exception
+    public void stop() throws Exception
     {
         if (_runRM)
         {
-            this.getLog().info("Stopping recovery manager");
+            log.info("Stopping transaction recovery manager");
 
             _recoveryManager.stop();
         }
@@ -322,14 +325,14 @@
      */
     public void setTransactionTimeout(int timeout) throws IllegalStateException
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
-            if (started)
+            if (configured)
             {
         	final int currentTimeout = getTransactionTimeout() ;
         	if (currentTimeout != timeout)
         	{
-        	    throw new IllegalStateException("Cannot set transaction timeout once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set transaction timeout once MBean has configured") ;
         	}
             }
             else
@@ -437,7 +440,7 @@
      */
     public void registerXAExceptionFormatter(Class c, XAExceptionFormatter f)
     {
-        this.getLog().warn("XAExceptionFormatters are not supported by the JBossTS Transaction Service - this warning can safely be ignored");
+        log.warn("XAExceptionFormatters are not supported by the JBossTS Transaction Service - this warning can safely be ignored");
     }
 
     /**
@@ -487,13 +490,13 @@
     public void setRunInVMRecoveryManager(boolean runRM)
         throws IllegalStateException
     {
-        synchronized(startedLock)
+        synchronized(configuredLock)
         {
-            if (started)
+            if (configured)
             {
         	if (this._runRM != runRM)
         	{
-        	    throw new IllegalStateException("Cannot set run in VM recovery manager once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set run in VM recovery manager once MBean has configured") ;
         	}
             }
             else
@@ -512,7 +515,7 @@
      */
     public boolean getRunInVMRecoveryManager()
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
 	    return _runRM ;
 	}
@@ -527,15 +530,15 @@
     public void setObjectStoreDir(final String objectStoreDir)
     	throws IllegalStateException
     {
-        synchronized(startedLock)
+        synchronized(configuredLock)
         {
-            if (started)
+            if (configured)
             {
         	final String currentDir = getObjectStoreDir() ;
         	final boolean equal = (currentDir == null ? objectStoreDir == null : currentDir.equals(objectStoreDir)) ;
         	if (!equal)
         	{
-        	    throw new IllegalStateException("Cannot set object store dir once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set object store dir once MBean has configured") ;
         	}
             }
             else
@@ -554,15 +557,28 @@
 	return System.getProperty(com.arjuna.ats.arjuna.common.Environment.OBJECTSTORE_DIR) ;
     }
 
-    private void registerNotification()
-        throws InstanceNotFoundException
+
+    public MBeanServer getMbeanServer()
     {
-        final NotificationFilterSupport notificationFilter = new NotificationFilterSupport() ;
-        notificationFilter.enableType(Server.START_NOTIFICATION_TYPE) ;
+        return mbeanServer;
+    }
 
-        final ObjectName serverName = ObjectNameFactory.create("jboss.system:type=Server") ;
-
-        getServer().addNotificationListener(serverName, this, notificationFilter, null) ;
+    public void setMbeanServer(MBeanServer mbeanServer)
+    {
+        synchronized(configuredLock)
+        {
+            if (configured)
+            {
+                if (this.mbeanServer != mbeanServer)
+                {
+                    throw new IllegalStateException("Cannot set MBeanServer once MBean has configured") ;
+                }
+            }
+            else
+            {
+                this.mbeanServer = mbeanServer;
+            }
+        }
     }
 
     private void bindRef(String jndiName, String className)
@@ -581,13 +597,13 @@
     public void setAlwaysPropagateContext(final boolean alwaysPropagateContext)
     	throws IllegalStateException
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
-            if (started)
+            if (configured)
             {
         	if (this.alwaysPropagateContext != alwaysPropagateContext)
         	{
-        	    throw new IllegalStateException("Cannot set always propagate context once MBean has started") ;
+        	    throw new IllegalStateException("Cannot set always propagate context once MBean has configured") ;
         	}
             }
             else
@@ -603,7 +619,7 @@
      */
     public boolean getAlwaysPropagateContext()
     {
-	synchronized(startedLock)
+	synchronized(configuredLock)
 	{
 	    return alwaysPropagateContext ;
 	}

Modified: labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerServiceMBean.java
===================================================================
--- labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerServiceMBean.java	2008-06-04 11:51:50 UTC (rev 20293)
+++ labs/jbosstm/trunk/atsintegration/classes/com/arjuna/ats/jbossatx/jts/TransactionManagerServiceMBean.java	2008-06-04 12:03:32 UTC (rev 20294)
@@ -1,20 +1,20 @@
 /*
  * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors 
- * as indicated by the @author tags. 
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
  * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
+ * full listing of individual contributors.
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
  * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
- * 
+ *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
@@ -42,14 +42,14 @@
  * @author Richard A. Begg (richard.begg at arjuna.com)
  * @version $Id: TransactionManagerServiceMBean.java,v 1.5 2005/06/17 10:53:51 kconner Exp $
  */
-public interface TransactionManagerServiceMBean extends org.jboss.system.ServiceMBean
+public interface TransactionManagerServiceMBean
 {
     /**
      * Set the default transaction timeout used by this transaction manager.
      *
      * @param timeout The default timeout in seconds for all transactions created
      * using this transaction manager.
-     * 
+     *
      * @throws IllegalStateException if the mbean has already started.
      */
     public void setTransactionTimeout(int timeout) throws IllegalStateException ;
@@ -95,10 +95,10 @@
      * @return A reference to the JTA transaction manager.
      */
     public TransactionManager getTransactionManager();
-    
+
     /**
      * Get the XA Terminator
-     * 
+     *
      * @return the XA Terminator
      */
     public JBossXATerminator getXATerminator() ;
@@ -145,28 +145,28 @@
      * JBoss.  If this is false the Recovery Manager is already expected to
      * be running when JBoss starts.
      * @param runRM
-     * 
+     *
      * @throws IllegalStateException If the MBean has already started.
      */
     public void setRunInVMRecoveryManager(boolean runRM) throws IllegalStateException ;
-    
+
     /**
      * Get whether the recovery manager should be ran in the same VM as
      * JBoss.  If this is false the Recovery Manager is already expected to
      * be running when JBoss starts.
-     * 
+     *
      * @return true if the recover manager is running in the same VM, false otherwise.
      */
     public boolean getRunInVMRecoveryManager() ;
-    
+
     /**
      * Set the object store directory.
      * @param objectStoreDir The object store directory.
-     * 
+     *
      * @throws IllegalStateException if the MBean has already started
      */
     public void setObjectStoreDir(final String objectStoreDir) throws IllegalStateException ;
-    
+
     /**
      * Get the object store directory.
      * @return objectStoreDir The object store directory.
@@ -176,7 +176,7 @@
     /**
      * Set the flag indicating whether the propagation context should always be propagated.
      * @param alwaysPropagateContext true if the context should always be propagated, false if only propagated to OTS transactional objects.
-     * 
+     *
      * @throws IllegalStateException If the MBean has already started.
      */
     public void setAlwaysPropagateContext(final boolean alwaysPropagateContext) throws IllegalStateException ;




More information about the jboss-svn-commits mailing list