View Javadoc

1   /*
2    * $Id:JBossArjunaTransactionManagerFactory.java 8215 2007-09-05 16:56:51Z aperepel $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.jboss.transaction;
12  
13  import org.mule.api.config.MuleConfiguration;
14  import org.mule.api.transaction.TransactionManagerFactory;
15  
16  import com.arjuna.ats.arjuna.common.arjPropertyManager;
17  
18  import java.net.InetAddress;
19  import java.net.UnknownHostException;
20  import java.text.MessageFormat;
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.transaction.TransactionManager;
25  
26  public class JBossArjunaTransactionManagerFactory implements TransactionManagerFactory
27  {
28  
29      public static final String PROPERTY_OBJECTSTORE_DIR = "com.arjuna.ats.arjuna.objectstore.objectStoreDir";
30      public static final String PROPERTY_NODE_IDENTIFIER = "com.arjuna.ats.arjuna.nodeIdentifier";
31  
32      private Map<String, String> properties = new HashMap<String, String>();
33  
34      //static
35      //{
36      //arjPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "log4j_releveler");
37      //arjPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "jakarta");
38      //arjPropertyManager.propertyManager.setProperty(LogFactory.DEBUG_LEVEL, String.valueOf(DebugLevel.FULL_DEBUGGING));
39      //commonPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "jakarta");
40      //commonPropertyManager.propertyManager.setProperty(LogFactory.DEBUG_LEVEL, String.valueOf(DebugLevel.FULL_DEBUGGING));
41      //}
42  
43      private TransactionManager tm;
44  
45      public JBossArjunaTransactionManagerFactory()
46      {
47          //arjPropertyManager.propertyManager.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreType", "ShadowNoFileLockStore");
48          //arjPropertyManager.propertyManager.setProperty(Environment.OBJECTSTORE_TYPE, ArjunaNames.Implementation_ObjectStore_JDBCStore().stringForm());
49      }
50  
51      public synchronized TransactionManager create(MuleConfiguration config) throws Exception
52      {
53          if (tm == null)
54          {
55              // let the user override those in the config
56              if (!properties.containsKey(PROPERTY_OBJECTSTORE_DIR))
57              {
58                  final String muleInternalDir = config.getWorkingDirectory();
59                  arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreDir(muleInternalDir + "/transaction-log");
60              }
61  
62              if (!properties.containsKey(PROPERTY_NODE_IDENTIFIER))
63              {
64                  try
65                  {
66                      InetAddress address = InetAddress.getLocalHost();
67                      final String xaNodeId = MessageFormat.format("Mule[{0}/{1}]",
68                                                                   address.getHostName(), address.getHostAddress());
69                      arjPropertyManager.getCoreEnvironmentBean().setNodeIdentifier(xaNodeId);
70                  }
71                  catch (UnknownHostException e)
72                  {
73                      // ignore, let the defaults be generated
74                  }
75              }
76  
77  
78              // TODO JBossTS now uses different configuration approach, broke props into 3 javabeans, update
79              /*for (Map.Entry<String, String> entry : properties.entrySet())
80              {
81                  arjPropertyManager.propertyManager.setProperty(entry.getKey(), entry.getValue());
82              }*/
83              tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
84  
85          }
86          return tm;
87      }
88  
89      public Map<String, String> getProperties()
90      {
91          return properties;
92      }
93  
94      public void setProperties(Map<String, String> properties)
95      {
96          this.properties = properties;
97      }
98  }