View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.transaction.support.TransactionSynchronization;
23  
24  
25  /**
26   * Sends message when current transaction commits.  
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public class MessageSendingTransactionSynchronization implements TransactionSynchronization {
32      
33      private static final Logger LOG = Logger.getLogger(MessageSendingTransactionSynchronization.class);
34  
35      //this is to verify this was called without implementing some sort of plugability in this 
36      //layer of the code for the tests.
37      public static boolean CALLED_TRANS_COMMITTED = false;
38      public static boolean CALLED_TRANS_ROLLEDBACKED = false;
39      
40      private PersistedMessageBO message;
41      
42      public MessageSendingTransactionSynchronization(PersistedMessageBO message) {
43  	this.message = message;
44      }
45  
46      public void afterCommit() {
47  
48      }
49  
50      public void afterCompletion(int status) {
51  	if (status == STATUS_COMMITTED) {
52  	    KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message));
53  	    CALLED_TRANS_COMMITTED = true;
54  	} else {
55  	    LOG.info("Message " + message + " not sent because transaction not committed.");
56  	    CALLED_TRANS_ROLLEDBACKED = true;
57  	}
58      }
59  
60      public void beforeCommit(boolean readOnly) {
61      }
62  
63      public void beforeCompletion() {
64      }
65  
66      public void resume() {
67      }
68  
69      public void suspend() {
70      }
71      
72      public void flush() {
73      }
74  
75  }