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.Environment;
17  import com.arjuna.ats.arjuna.common.arjPropertyManager;
18  
19  import java.net.InetAddress;
20  import java.net.UnknownHostException;
21  import java.text.MessageFormat;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import javax.transaction.TransactionManager;
26  
27  public class JBossArjunaTransactionManagerFactory implements TransactionManagerFactory
28  {
29  
30      private Map<String, String> properties = new HashMap<String, String>();
31  
32      //static
33      //{
34      //arjPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "log4j_releveler");
35      //arjPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "jakarta");
36      //arjPropertyManager.propertyManager.setProperty(LogFactory.DEBUG_LEVEL, String.valueOf(DebugLevel.FULL_DEBUGGING));
37      //commonPropertyManager.propertyManager.setProperty(LogFactory.LOGGER_PROPERTY, "jakarta");
38      //commonPropertyManager.propertyManager.setProperty(LogFactory.DEBUG_LEVEL, String.valueOf(DebugLevel.FULL_DEBUGGING));
39      //}
40  
41      private TransactionManager tm;
42  
43      public JBossArjunaTransactionManagerFactory()
44      {
45          //arjPropertyManager.propertyManager.setProperty("com.arjuna.ats.arjuna.objectstore.objectStoreType", "ShadowNoFileLockStore");
46          //arjPropertyManager.propertyManager.setProperty(Environment.OBJECTSTORE_TYPE, ArjunaNames.Implementation_ObjectStore_JDBCStore().stringForm());
47      }
48  
49      public synchronized TransactionManager create(MuleConfiguration config) throws Exception
50      {
51          if (tm == null)
52          {
53              // let the user override those in the config
54              if (!properties.containsKey(Environment.OBJECTSTORE_DIR))
55              {
56                  final String muleInternalDir = config.getWorkingDirectory();
57                  arjPropertyManager.propertyManager.setProperty(Environment.OBJECTSTORE_DIR, muleInternalDir + "/transaction-log");
58              }
59  
60              if (!properties.containsKey(Environment.XA_NODE_IDENTIFIER))
61              {
62                  try
63                  {
64                      InetAddress address = InetAddress.getLocalHost();
65                      final String xaNodeId = MessageFormat.format("Mule[{0}/{1}]",
66                                                                   address.getHostName(), address.getHostAddress());
67                      properties.put(Environment.XA_NODE_IDENTIFIER, xaNodeId);
68                  }
69                  catch (UnknownHostException e)
70                  {
71                      // ignore, let the defaults be generated
72                  }
73              }
74  
75  
76              for (Map.Entry<String, String> entry : properties.entrySet())
77              {
78                  arjPropertyManager.propertyManager.setProperty(entry.getKey(), entry.getValue());
79              }
80              tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
81  
82          }
83          return tm;
84      }
85  
86      public Map<String, String> getProperties()
87      {
88          return properties;
89      }
90  
91      public void setProperties(Map<String, String> properties)
92      {
93          this.properties = properties;
94      }
95  }