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