001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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 edu.iu.uis.eden.messaging;
017:
018: import java.sql.Timestamp;
019: import java.util.ArrayList;
020: import java.util.Date;
021: import java.util.List;
022: import java.util.Map;
023:
024: import javax.xml.namespace.QName;
025:
026: import org.kuali.rice.RiceConstants;
027: import org.kuali.rice.core.Core;
028: import org.kuali.rice.util.RiceUtilities;
029:
030: import edu.iu.uis.eden.messaging.dao.MessageQueueDAO;
031:
032: public class MessageQueueServiceImpl implements MessageQueueService {
033:
034: private MessageQueueDAO messageQueueDAO;
035:
036: public void delete(PersistedMessage routeQueue) {
037: this .getMessageQueueDAO().remove(routeQueue);
038: }
039:
040: public void save(PersistedMessage routeQueue) {
041: this .getMessageQueueDAO().save(routeQueue);
042: }
043:
044: public List<PersistedMessage> findAll() {
045: return this .getMessageQueueDAO().findAll();
046: }
047:
048: public List<PersistedMessage> findAll(int maxRows) {
049: return this .getMessageQueueDAO().findAll(maxRows);
050: }
051:
052: public PersistedMessage findByRouteQueueId(Long routeQueueId) {
053: return getMessageQueueDAO().findByRouteQueueId(routeQueueId);
054: }
055:
056: public PersistedMassagePayload findByPersistedMessageByRouteQueueId(
057: Long routeQueueId) {
058: return messageQueueDAO
059: .findByPersistedMessageByRouteQueueId(routeQueueId);
060: }
061:
062: public List<PersistedMessage> getNextDocuments(Integer maxDocuments) {
063: return this .getMessageQueueDAO().getNextDocuments(maxDocuments);
064: }
065:
066: public MessageQueueDAO getMessageQueueDAO() {
067: return this .messageQueueDAO;
068: }
069:
070: public void setMessageQueueDAO(MessageQueueDAO queueDAO) {
071: this .messageQueueDAO = queueDAO;
072: }
073:
074: public List<PersistedMessage> findByServiceName(QName serviceName,
075: String methodName) {
076: return getMessageQueueDAO().findByServiceName(serviceName,
077: methodName);
078: }
079:
080: public List<PersistedMessage> findByValues(
081: Map<String, String> criteriaValues, int maxRows) {
082: return getMessageQueueDAO().findByValues(criteriaValues,
083: maxRows);
084: }
085:
086: public Integer getMaxRetryAttempts() {
087: return new Integer(Core.getCurrentContextConfig().getProperty(
088: RiceConstants.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY));
089: }
090:
091: public PersistedMessage getMessage(ServiceInfo serviceInfo,
092: AsynchronousCall methodCall) {
093: PersistedMessage message = new PersistedMessage();
094: message.setPayload(new PersistedMassagePayload(methodCall,
095: message));
096: message.setIpNumber(RiceUtilities.getIpNumber());
097: message.setServiceName(serviceInfo.getQname().toString());
098: // if (deliveryDate == null) {
099: message.setQueueDate(new Timestamp(System.currentTimeMillis()));
100: // } else {
101: // message.setQueueDate(new Timestamp(deliveryDate.getTime()));
102: // }
103: // we need this set to persist the message but it's likely many services
104: // won't set this
105: // for now just use a reasonable default value
106: if (serviceInfo.getServiceDefinition().getPriority() == null) {
107: message
108: .setQueuePriority(RiceConstants.ROUTE_QUEUE_DEFAULT_PRIORITY);
109: } else {
110: message.setQueuePriority(serviceInfo.getServiceDefinition()
111: .getPriority());
112: }
113: message.setQueueStatus(RiceConstants.ROUTE_QUEUE_QUEUED);
114: message.setRetryCount(0);
115: if (serviceInfo.getServiceDefinition().getMillisToLive() > 0) {
116: message.setExpirationDate(new Timestamp(System
117: .currentTimeMillis()
118: + serviceInfo.getServiceDefinition()
119: .getMillisToLive()));
120: }
121: message.setMessageEntity(Core.getCurrentContextConfig()
122: .getMessageEntity());
123: message.setMethodName(methodCall.getMethodName());
124: return message;
125: }
126: }
|