View Javadoc

1   /**
2    * Copyright 2005-2013 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.kuali.rice.core.api.config.property.ConfigContext;
19  import org.kuali.rice.core.api.util.RiceConstants;
20  import org.kuali.rice.ksb.messaging.MessageServiceInvoker;
21  import org.kuali.rice.ksb.messaging.PersistedMessageBO;
22  import org.kuali.rice.ksb.service.KSBServiceLocator;
23  import org.kuali.rice.ksb.util.KSBConstants;
24  import org.springframework.transaction.support.TransactionSynchronizationManager;
25  
26  
27  /**
28   * Responsible for implementing policy to put message into threadpool for execution appropriately. Could make Spring and
29   * overridable service.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   * 
33   */
34  public class MessageSender {
35  
36      public static void sendMessage(PersistedMessageBO message) throws Exception {
37          if (!Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGING_OFF))) {
38  
39              if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null
40                      || ConfigContext.getCurrentContextConfig().getObject(RiceConstants.TRANSACTION_MANAGER_OBJ) != null) {
41                  if (TransactionSynchronizationManager.isSynchronizationActive()) {
42                      TransactionSynchronizationManager.registerSynchronization(new MessageSendingTransactionSynchronization(
43                              message));
44                  } else {
45                      KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message));
46                  }
47              } else {
48                  KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message));
49              }
50          }
51      }
52  
53  }