1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.serviceproxies; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.kuali.rice.ksb.messaging.MessageServiceInvoker; |
20 | |
import org.kuali.rice.ksb.messaging.PersistedMessageBO; |
21 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
22 | |
import org.springframework.core.Ordered; |
23 | |
import org.springframework.transaction.support.TransactionSynchronizationAdapter; |
24 | |
|
25 | |
import java.util.concurrent.atomic.AtomicBoolean; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
public class MessageSendingTransactionSynchronization extends TransactionSynchronizationAdapter { |
34 | |
|
35 | 0 | private static final Logger LOG = Logger.getLogger(MessageSendingTransactionSynchronization.class); |
36 | 0 | public static final AtomicBoolean CALLED_TRANS_COMMITTED = new AtomicBoolean(false); |
37 | 0 | public static final AtomicBoolean CALLED_TRANS_ROLLEDBACKED = new AtomicBoolean(false); |
38 | |
|
39 | |
private final PersistedMessageBO message; |
40 | |
|
41 | 0 | public MessageSendingTransactionSynchronization(PersistedMessageBO message) { |
42 | 0 | this.message = message; |
43 | 0 | } |
44 | |
|
45 | |
@Override |
46 | |
public void afterCompletion(int status) { |
47 | 0 | if (status == STATUS_COMMITTED) { |
48 | 0 | KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message)); |
49 | 0 | CALLED_TRANS_COMMITTED.set(true); |
50 | |
} else { |
51 | 0 | LOG.info("Message " + message + " not sent because transaction not committed."); |
52 | 0 | CALLED_TRANS_ROLLEDBACKED.set(true); |
53 | |
} |
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
public int getOrder() { |
58 | 0 | return Ordered.HIGHEST_PRECEDENCE; |
59 | |
} |
60 | |
} |