1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
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 | 0 | private Map<String, String> properties = new HashMap<String, String>(); |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
private TransactionManager tm; |
38 | |
|
39 | |
public JBossArjunaTransactionManagerFactory() |
40 | 0 | { |
41 | |
|
42 | |
|
43 | 0 | } |
44 | |
|
45 | |
public synchronized TransactionManager create(MuleConfiguration config) throws Exception |
46 | |
{ |
47 | 0 | if (tm == null) |
48 | |
{ |
49 | |
|
50 | 0 | if (!properties.containsKey(Environment.OBJECTSTORE_DIR)) |
51 | |
{ |
52 | 0 | final String muleInternalDir = config.getWorkingDirectory(); |
53 | 0 | arjPropertyManager.propertyManager.setProperty(Environment.OBJECTSTORE_DIR, muleInternalDir + "/transaction-log"); |
54 | |
} |
55 | |
|
56 | 0 | if (!properties.containsKey(Environment.XA_NODE_IDENTIFIER)) |
57 | |
{ |
58 | |
try |
59 | |
{ |
60 | 0 | InetAddress address = InetAddress.getLocalHost(); |
61 | 0 | final String xaNodeId = MessageFormat.format("Mule[{0}/{1}]", |
62 | |
address.getHostName(), address.getHostAddress()); |
63 | 0 | properties.put(Environment.XA_NODE_IDENTIFIER, xaNodeId); |
64 | |
} |
65 | 0 | catch (UnknownHostException e) |
66 | |
{ |
67 | |
|
68 | 0 | } |
69 | |
} |
70 | |
|
71 | |
|
72 | 0 | for (Map.Entry<String, String> entry : properties.entrySet()) |
73 | |
{ |
74 | 0 | arjPropertyManager.propertyManager.setProperty(entry.getKey(), entry.getValue()); |
75 | |
} |
76 | 0 | tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); |
77 | |
|
78 | |
} |
79 | 0 | return tm; |
80 | |
} |
81 | |
|
82 | |
public Map<String, String> getProperties() |
83 | |
{ |
84 | 0 | return properties; |
85 | |
} |
86 | |
|
87 | |
public void setProperties(Map<String, String> properties) |
88 | |
{ |
89 | 0 | this.properties = properties; |
90 | 0 | } |
91 | |
} |