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