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