001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.ksb.messaging.serviceproxies; 017 018import org.kuali.rice.core.api.config.property.ConfigContext; 019import org.kuali.rice.core.api.util.RiceConstants; 020import org.kuali.rice.ksb.messaging.MessageServiceInvoker; 021import org.kuali.rice.ksb.messaging.PersistedMessageBO; 022import org.kuali.rice.ksb.service.KSBServiceLocator; 023import org.kuali.rice.ksb.util.KSBConstants; 024import org.springframework.transaction.support.TransactionSynchronizationManager; 025 026 027/** 028 * Responsible for implementing policy to put message into threadpool for execution appropriately. Could make Spring and 029 * overridable service. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 * 033 */ 034public class MessageSender { 035 036 public static void sendMessage(PersistedMessageBO message) throws Exception { 037 if (!Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGING_OFF))) { 038 039 if (ConfigContext.getCurrentContextConfig().getObject(RiceConstants.SPRING_TRANSACTION_MANAGER) != null 040 || ConfigContext.getCurrentContextConfig().getObject(RiceConstants.TRANSACTION_MANAGER_OBJ) != null) { 041 if (TransactionSynchronizationManager.isSynchronizationActive()) { 042 TransactionSynchronizationManager.registerSynchronization(new MessageSendingTransactionSynchronization( 043 message)); 044 } else { 045 KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message)); 046 } 047 } else { 048 KSBServiceLocator.getThreadPool().execute(new MessageServiceInvoker(message)); 049 } 050 } 051 } 052 053}