Coverage Report - org.kuali.rice.ksb.messaging.service.impl.MessageQueueServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageQueueServiceImpl
0%
0/38
0%
0/12
1.462
 
 1  
 /*
 2  
  * Copyright 2006-2011 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  
 
 17  
 package org.kuali.rice.ksb.messaging.service.impl;
 18  
 
 19  
 import org.apache.log4j.Logger;
 20  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 21  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 22  
 import org.kuali.rice.core.api.util.RiceUtilities;
 23  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 24  
 import org.kuali.rice.ksb.api.messaging.AsynchronousCall;
 25  
 import org.kuali.rice.ksb.messaging.PersistedMessageBO;
 26  
 import org.kuali.rice.ksb.messaging.PersistedMessagePayload;
 27  
 import org.kuali.rice.ksb.messaging.dao.MessageQueueDAO;
 28  
 import org.kuali.rice.ksb.messaging.service.MessageQueueService;
 29  
 import org.kuali.rice.ksb.util.KSBConstants;
 30  
 
 31  
 import javax.xml.namespace.QName;
 32  
 import java.sql.Timestamp;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  0
 public class MessageQueueServiceImpl implements MessageQueueService {
 37  
 
 38  
 
 39  0
     private static final Logger LOG = Logger.getLogger(MessageQueueServiceImpl.class);
 40  
     private MessageQueueDAO messageQueueDao;
 41  
 
 42  
     public void delete(PersistedMessageBO routeQueue) {
 43  0
         if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGE_PERSISTENCE))) {
 44  0
             if (LOG.isDebugEnabled()) {
 45  0
                 LOG.debug("Message Persistence is on.  Deleting stored message" + routeQueue);
 46  
             }
 47  0
             this.getMessageQueueDao().remove(routeQueue);
 48  
         }
 49  0
     }
 50  
 
 51  
     public void save(PersistedMessageBO routeQueue) {
 52  0
         if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.MESSAGE_PERSISTENCE))) {
 53  0
             if (LOG.isDebugEnabled()) {
 54  0
                 LOG.debug("Persisting Message " + routeQueue);
 55  
             }
 56  0
             this.getMessageQueueDao().save(routeQueue);
 57  
         }
 58  0
     }
 59  
 
 60  
     public List<PersistedMessageBO> findAll() {
 61  0
         return this.getMessageQueueDao().findAll();
 62  
     }
 63  
 
 64  
     public List<PersistedMessageBO> findAll(int maxRows) {
 65  0
         return this.getMessageQueueDao().findAll(maxRows);
 66  
     }
 67  
 
 68  
     public PersistedMessageBO findByRouteQueueId(Long routeQueueId) {
 69  0
         return getMessageQueueDao().findByRouteQueueId(routeQueueId);
 70  
     }
 71  
 
 72  
     public PersistedMessagePayload findByPersistedMessageByRouteQueueId(Long routeQueueId) {
 73  0
         return messageQueueDao.findByPersistedMessageByRouteQueueId(routeQueueId);
 74  
     }
 75  
 
 76  
     public List<PersistedMessageBO> getNextDocuments(Integer maxDocuments) {
 77  0
         return this.getMessageQueueDao().getNextDocuments(maxDocuments);
 78  
     }
 79  
 
 80  
     public MessageQueueDAO getMessageQueueDao() {
 81  0
         return this.messageQueueDao;
 82  
     }
 83  
 
 84  
     public void setMessageQueueDao(MessageQueueDAO queueDAO) {
 85  0
         this.messageQueueDao = queueDAO;
 86  0
     }
 87  
 
 88  
     public List<PersistedMessageBO> findByServiceName(QName serviceName, String methodName) {
 89  0
         return getMessageQueueDao().findByServiceName(serviceName, methodName);
 90  
     }
 91  
 
 92  
     public List<PersistedMessageBO> findByValues(Map<String, String> criteriaValues, int maxRows) {
 93  0
         return getMessageQueueDao().findByValues(criteriaValues, maxRows);
 94  
     }
 95  
 
 96  
     public Integer getMaxRetryAttempts() {
 97  0
         return new Integer(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY));
 98  
     }
 99  
 
 100  
     public PersistedMessageBO getMessage(ServiceConfiguration serviceConfiguration, AsynchronousCall methodCall) {
 101  0
         PersistedMessageBO message = new PersistedMessageBO();
 102  0
         message.setPayload(new PersistedMessagePayload(methodCall, message));
 103  0
         message.setIpNumber(RiceUtilities.getIpNumber());
 104  0
         message.setServiceName(serviceConfiguration.getServiceName().toString());
 105  0
         message.setQueueDate(new Timestamp(System.currentTimeMillis()));
 106  0
         if (serviceConfiguration.getPriority() == null) {
 107  0
             message.setQueuePriority(KSBConstants.ROUTE_QUEUE_DEFAULT_PRIORITY);
 108  
         } else {
 109  0
             message.setQueuePriority(serviceConfiguration.getPriority());
 110  
         }
 111  0
         message.setQueueStatus(KSBConstants.ROUTE_QUEUE_QUEUED);
 112  0
         message.setRetryCount(0);
 113  0
         if (serviceConfiguration.getMillisToLive() > 0) {
 114  0
             message.setExpirationDate(new Timestamp(System.currentTimeMillis() + serviceConfiguration.getMillisToLive()));
 115  
         }
 116  0
         message.setApplicationId(CoreConfigHelper.getApplicationId());
 117  0
         message.setMethodName(methodCall.getMethodName());
 118  0
         return message;
 119  
     }
 120  
 }