01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License"); you may not use this file except in
05: * compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.opensource.org/licenses/ecl1.php
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
10: * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: */
13: package edu.iu.uis.eden.messaging.serviceproxies;
14:
15: import javax.transaction.Status;
16: import javax.transaction.Synchronization;
17:
18: import org.apache.log4j.Logger;
19: import org.kuali.bus.services.KSBServiceLocator;
20:
21: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
22: import edu.iu.uis.eden.messaging.PersistedMessage;
23:
24: /**
25: * Puts new message invoker in thread pool when JTA transaction completes. This is what allows us to keep our messaging
26: * sync'd up with our current tranaction.
27: *
28: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
29: *
30: */
31: public class AsynchronousMessageCaller implements Synchronization {
32:
33: private static final Logger LOG = Logger
34: .getLogger(AsynchronousMessageCaller.class);
35:
36: //this is to verify this was called without implementing some sort of plugability in this
37: //layer of the code for the tests.
38: public static boolean CALLED_TRANS_COMMITTED = false;
39: public static boolean CALLED_TRANS_ROLLEDBACKED = false;
40:
41: private PersistedMessage message;
42:
43: public AsynchronousMessageCaller(PersistedMessage message) {
44: this .message = message;
45: }
46:
47: public void afterCompletion(int status) {
48: if (status == Status.STATUS_COMMITTED) {
49: KSBServiceLocator.getThreadPool().execute(
50: new MessageServiceInvoker(message));
51: CALLED_TRANS_COMMITTED = true;
52: } else {
53: LOG.info("Message " + message
54: + " not sent because transaction not committed.");
55: CALLED_TRANS_ROLLEDBACKED = true;
56: }
57: }
58:
59: public void beforeCompletion() {
60: }
61: }
|