1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.jms; |
12 | |
|
13 | |
import org.mule.config.i18n.CoreMessages; |
14 | |
import org.mule.providers.jms.i18n.JmsMessages; |
15 | |
import org.mule.transaction.AbstractSingleResourceTransaction; |
16 | |
import org.mule.transaction.IllegalTransactionStateException; |
17 | |
import org.mule.umo.TransactionException; |
18 | |
|
19 | |
import javax.jms.Connection; |
20 | |
import javax.jms.JMSException; |
21 | |
import javax.jms.Message; |
22 | |
import javax.jms.Session; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | 8 | public class JmsClientAcknowledgeTransaction extends AbstractSingleResourceTransaction |
31 | |
{ |
32 | |
private volatile Message message; |
33 | |
|
34 | |
public void setMessage(Message message) |
35 | |
{ |
36 | 8 | this.message = message; |
37 | 8 | } |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
protected void doBegin() throws TransactionException |
45 | |
{ |
46 | |
|
47 | 8 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
protected void doCommit() throws TransactionException |
55 | |
{ |
56 | |
try |
57 | |
{ |
58 | 8 | if (message == null) |
59 | |
{ |
60 | 0 | throw new IllegalTransactionStateException( |
61 | |
JmsMessages.noMessageBoundForAck()); |
62 | |
} |
63 | 8 | message.acknowledge(); |
64 | |
} |
65 | 0 | catch (JMSException e) |
66 | |
{ |
67 | 0 | throw new IllegalTransactionStateException(CoreMessages.transactionCommitFailed(), e); |
68 | 8 | } |
69 | 8 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
protected void doRollback() throws TransactionException |
77 | |
{ |
78 | |
|
79 | 0 | if (message != null) |
80 | |
{ |
81 | 0 | throw new UnsupportedOperationException("Jms Client Acknowledge doesn't support rollback"); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void bindResource(Object key, Object resource) throws TransactionException |
92 | |
{ |
93 | 8 | if (key instanceof Message) |
94 | |
{ |
95 | 0 | this.message = (Message)key; |
96 | 0 | return; |
97 | |
} |
98 | 8 | if (!(key instanceof Connection) || !(resource instanceof Session)) |
99 | |
{ |
100 | 0 | throw new IllegalTransactionStateException( |
101 | |
CoreMessages.transactionCanOnlyBindToResources("javax.jms.Connection/javax.jms.Session")); |
102 | |
} |
103 | |
|
104 | 8 | Session session = (Session)resource; |
105 | |
try |
106 | |
{ |
107 | 8 | if (session.getTransacted()) |
108 | |
{ |
109 | 0 | throw new IllegalTransactionStateException(JmsMessages.sessionShouldNotBeTransacted()); |
110 | |
} |
111 | |
} |
112 | 0 | catch (JMSException e) |
113 | |
{ |
114 | 0 | throw new IllegalTransactionStateException(CoreMessages.transactionCannotReadState(), e); |
115 | 8 | } |
116 | |
|
117 | 8 | super.bindResource(key, resource); |
118 | 8 | } |
119 | |
} |