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 */ 016 package org.kuali.rice.ksb.messaging.service.impl; 017 018 import org.apache.log4j.Logger; 019 import org.kuali.rice.core.api.config.CoreConfigHelper; 020 import org.kuali.rice.core.api.config.property.ConfigContext; 021 import org.kuali.rice.core.api.util.RiceUtilities; 022 import org.kuali.rice.ksb.api.bus.ServiceConfiguration; 023 import org.kuali.rice.ksb.api.messaging.AsynchronousCall; 024 import org.kuali.rice.ksb.messaging.PersistedMessageBO; 025 import org.kuali.rice.ksb.messaging.PersistedMessagePayload; 026 import org.kuali.rice.ksb.messaging.dao.MessageQueueDAO; 027 import org.kuali.rice.ksb.messaging.service.MessageQueueService; 028 import org.kuali.rice.ksb.util.KSBConstants; 029 030 import javax.xml.namespace.QName; 031 import java.sql.Timestamp; 032 import java.util.List; 033 import java.util.Map; 034 035 public class MessageQueueServiceImpl implements MessageQueueService { 036 037 038 private static final Logger LOG = Logger.getLogger(MessageQueueServiceImpl.class); 039 private MessageQueueDAO messageQueueDao; 040 041 public void delete(PersistedMessageBO routeQueue) { 042 if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGE_PERSISTENCE))) { 043 if (LOG.isDebugEnabled()) { 044 LOG.debug("Message Persistence is on. Deleting stored message" + routeQueue); 045 } 046 this.getMessageQueueDao().remove(routeQueue); 047 } 048 } 049 050 public void save(PersistedMessageBO routeQueue) { 051 if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGE_PERSISTENCE))) { 052 if (LOG.isDebugEnabled()) { 053 LOG.debug("Persisting Message " + routeQueue); 054 } 055 this.getMessageQueueDao().save(routeQueue); 056 } 057 } 058 059 public List<PersistedMessageBO> findAll() { 060 return this.getMessageQueueDao().findAll(); 061 } 062 063 public List<PersistedMessageBO> findAll(int maxRows) { 064 return this.getMessageQueueDao().findAll(maxRows); 065 } 066 067 public PersistedMessageBO findByRouteQueueId(Long routeQueueId) { 068 return getMessageQueueDao().findByRouteQueueId(routeQueueId); 069 } 070 071 public PersistedMessagePayload findByPersistedMessageByRouteQueueId(Long routeQueueId) { 072 return messageQueueDao.findByPersistedMessageByRouteQueueId(routeQueueId); 073 } 074 075 public List<PersistedMessageBO> getNextDocuments(Integer maxDocuments) { 076 return this.getMessageQueueDao().getNextDocuments(maxDocuments); 077 } 078 079 public MessageQueueDAO getMessageQueueDao() { 080 return this.messageQueueDao; 081 } 082 083 public void setMessageQueueDao(MessageQueueDAO queueDAO) { 084 this.messageQueueDao = queueDAO; 085 } 086 087 public List<PersistedMessageBO> findByServiceName(QName serviceName, String methodName) { 088 return getMessageQueueDao().findByServiceName(serviceName, methodName); 089 } 090 091 public List<PersistedMessageBO> findByValues(Map<String, String> criteriaValues, int maxRows) { 092 return getMessageQueueDao().findByValues(criteriaValues, maxRows); 093 } 094 095 public Integer getMaxRetryAttempts() { 096 return new Integer(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY)); 097 } 098 099 }