1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.ksb.messaging.service.impl; |
17 | |
|
18 | |
import java.sql.Timestamp; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import javax.xml.namespace.QName; |
23 | |
|
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.core.config.ConfigContext; |
26 | |
import org.kuali.rice.core.util.RiceUtilities; |
27 | |
import org.kuali.rice.ksb.messaging.AsynchronousCall; |
28 | |
import org.kuali.rice.ksb.messaging.PersistedMessagePayload; |
29 | |
import org.kuali.rice.ksb.messaging.PersistedMessage; |
30 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
31 | |
import org.kuali.rice.ksb.messaging.dao.MessageQueueDAO; |
32 | |
import org.kuali.rice.ksb.messaging.service.MessageQueueService; |
33 | |
import org.kuali.rice.ksb.util.KSBConstants; |
34 | |
|
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(PersistedMessage routeQueue) { |
43 | 0 | if (new Boolean(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.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(PersistedMessage routeQueue) { |
52 | 0 | if (new Boolean(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.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<PersistedMessage> findAll() { |
61 | 0 | return this.getMessageQueueDAO().findAll(); |
62 | |
} |
63 | |
|
64 | |
public List<PersistedMessage> findAll(int maxRows) { |
65 | 0 | return this.getMessageQueueDAO().findAll(maxRows); |
66 | |
} |
67 | |
|
68 | |
public PersistedMessage 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<PersistedMessage> 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<PersistedMessage> findByServiceName(QName serviceName, String methodName) { |
89 | 0 | return getMessageQueueDAO().findByServiceName(serviceName, methodName); |
90 | |
} |
91 | |
|
92 | |
public List<PersistedMessage> 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.ROUTE_QUEUE_MAX_RETRY_ATTEMPTS_KEY)); |
98 | |
} |
99 | |
|
100 | |
public PersistedMessage getMessage(ServiceInfo serviceInfo, AsynchronousCall methodCall) { |
101 | 0 | PersistedMessage message = new PersistedMessage(); |
102 | 0 | message.setPayload(new PersistedMessagePayload(methodCall, message)); |
103 | 0 | message.setIpNumber(RiceUtilities.getIpNumber()); |
104 | 0 | message.setServiceName(serviceInfo.getQname().toString()); |
105 | 0 | message.setQueueDate(new Timestamp(System.currentTimeMillis())); |
106 | 0 | if (serviceInfo.getServiceDefinition().getPriority() == null) { |
107 | 0 | message.setQueuePriority(KSBConstants.ROUTE_QUEUE_DEFAULT_PRIORITY); |
108 | |
} else { |
109 | 0 | message.setQueuePriority(serviceInfo.getServiceDefinition().getPriority()); |
110 | |
} |
111 | 0 | message.setQueueStatus(KSBConstants.ROUTE_QUEUE_QUEUED); |
112 | 0 | message.setRetryCount(0); |
113 | 0 | if (serviceInfo.getServiceDefinition().getMillisToLive() > 0) { |
114 | 0 | message.setExpirationDate(new Timestamp(System.currentTimeMillis() + serviceInfo.getServiceDefinition().getMillisToLive())); |
115 | |
} |
116 | 0 | message.setServiceNamespace(ConfigContext.getCurrentContextConfig().getServiceNamespace()); |
117 | 0 | message.setMethodName(methodCall.getMethodName()); |
118 | 0 | return message; |
119 | |
} |
120 | |
} |