1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import org.kuali.rice.core.api.config.CoreConfigHelper;
19 import org.kuali.rice.core.api.util.RiceUtilities;
20 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
21 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
22 import org.kuali.rice.ksb.api.messaging.AsynchronousCall;
23 import org.kuali.rice.ksb.service.KSBServiceLocator;
24 import org.kuali.rice.ksb.util.KSBConstants;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.Table;
33 import javax.persistence.Transient;
34 import javax.persistence.Version;
35 import java.sql.Timestamp;
36
37
38
39
40
41
42 @Entity
43 @Table(name="KRSB_MSG_QUE_T")
44 @NamedQueries({
45 @NamedQuery(name="PersistedMessageBO.FindAll", query="select pm from PersistedMessageBO pm"),
46 @NamedQuery(name="PersistedMessageBO.FindByServiceName", query="select pm from PersistedMessageBO pm where pm.serviceName = :serviceName and pm.methodName = :methodName"),
47 @NamedQuery(name="PersistedMessageBO.GetNextDocuments", query="select pm from PersistedMessageBO pm where pm.applicationId = :applicationId and pm.queueStatus <> :queueStatus and pm.ipNumber = :ipNumber order by pm.queuePriority asc, pm.routeQueueId asc, pm.queueDate asc")
48 })
49 public class PersistedMessageBO implements PersistedMessage {
50
51 private static final long serialVersionUID = -7047766894738304195L;
52
53 @Id
54 @GeneratedValue(generator = "KRSB_MSG_QUE_S")
55 @PortableSequenceGenerator(name = "KRSB_MSG_QUE_S")
56 @Column(name="MSG_QUE_ID")
57 private Long routeQueueId;
58
59 @Column(name="PRIO")
60 private Integer queuePriority;
61
62 @Column(name="STAT_CD")
63 private String queueStatus;
64
65 @Column(name="DT")
66 private Timestamp queueDate;
67
68 @Column(name="EXP_DT")
69 private Timestamp expirationDate;
70
71 @Column(name="RTRY_CNT")
72 private Integer retryCount;
73
74 @Version
75 @Column(name="VER_NBR")
76 private Integer lockVerNbr;
77
78 @Column(name="IP_NBR")
79 private String ipNumber;
80
81 @Column(name="SVC_NM")
82 private String serviceName;
83
84 @Column(name="APPL_ID")
85 private String applicationId;
86
87 @Column(name="SVC_MTHD_NM")
88 private String methodName;
89
90 @Column(name="APP_VAL_ONE")
91 private String value1;
92
93 @Column(name="APP_VAL_TWO")
94 private String value2;
95
96 @Transient private AsynchronousCall methodCall;
97 @Transient private PersistedMessagePayload payload;
98
99 public PersistedMessageBO() {
100
101 }
102
103 public static PersistedMessageBO buildMessage(ServiceConfiguration serviceConfiguration, AsynchronousCall methodCall) {
104 PersistedMessageBO message = new PersistedMessageBO();
105 message.setPayload(new PersistedMessagePayload(methodCall, message));
106 message.setIpNumber(RiceUtilities.getIpNumber());
107 message.setServiceName(serviceConfiguration.getServiceName().toString());
108 message.setQueueDate(new Timestamp(System.currentTimeMillis()));
109 if (serviceConfiguration.getPriority() == null) {
110 message.setQueuePriority(KSBConstants.ROUTE_QUEUE_DEFAULT_PRIORITY);
111 } else {
112 message.setQueuePriority(serviceConfiguration.getPriority());
113 }
114 message.setQueueStatus(KSBConstants.ROUTE_QUEUE_QUEUED);
115 message.setRetryCount(0);
116 if (serviceConfiguration.getMillisToLive() > 0) {
117 message.setExpirationDate(new Timestamp(System.currentTimeMillis() + serviceConfiguration.getMillisToLive()));
118 }
119 message.setApplicationId(CoreConfigHelper.getApplicationId());
120 message.setMethodName(methodCall.getMethodName());
121 return message;
122 }
123
124 public PersistedMessageBO copy() {
125 PersistedMessageBO message = new PersistedMessageBO();
126 message.routeQueueId = routeQueueId;
127 message.queuePriority = queuePriority;
128 message.queueStatus = queueStatus;
129 message.queueDate = queueDate;
130 message.expirationDate = expirationDate;
131 message.retryCount = retryCount;
132 message.lockVerNbr = lockVerNbr;
133 message.ipNumber = ipNumber;
134 message.serviceName = serviceName;
135 message.applicationId = applicationId;
136 message.methodName = methodName;
137 message.value1 = value1;
138 message.value2 = value2;
139 message.methodCall = methodCall;
140 message.payload = payload;
141 return message;
142 }
143
144 @Override
145 public String getApplicationId() {
146 return this.applicationId;
147 }
148
149 public void setApplicationId(String applicationId) {
150 this.applicationId = applicationId;
151 }
152
153 @Override
154 public String getIpNumber() {
155 return this.ipNumber;
156 }
157
158 public void setIpNumber(String ipNumber) {
159 this.ipNumber = ipNumber;
160 }
161
162 @Override
163 public Timestamp getQueueDate() {
164 return this.queueDate;
165 }
166
167 @Override
168 public Integer getQueuePriority() {
169 return this.queuePriority;
170 }
171
172 @Override
173 public String getQueueStatus() {
174 return this.queueStatus;
175 }
176
177 @Override
178 public Integer getRetryCount() {
179 return this.retryCount;
180 }
181
182
183 public void setQueueDate(Timestamp timestamp) {
184 this.queueDate = timestamp;
185 }
186
187 public void setQueuePriority(Integer integer) {
188 this.queuePriority = integer;
189 }
190
191 public void setQueueStatus(String string) {
192 this.queueStatus = string;
193 }
194
195 public void setRetryCount(Integer integer) {
196 this.retryCount = integer;
197 }
198
199
200 public Integer getLockVerNbr() {
201 return this.lockVerNbr;
202 }
203
204 public void setLockVerNbr(Integer lockVerNbr) {
205 this.lockVerNbr = lockVerNbr;
206 }
207
208 @Override
209 public Long getRouteQueueId() {
210 return this.routeQueueId;
211 }
212
213 public void setRouteQueueId(Long queueSequence) {
214 this.routeQueueId = queueSequence;
215 }
216
217 @Override
218 public String getServiceName() {
219 return this.serviceName;
220 }
221
222 public void setServiceName(String serviceName) {
223 this.serviceName = serviceName;
224 }
225
226 public String toString() {
227 return "[RouteQueue: " + ", routeQueueId=" + this.routeQueueId + ", ipNumber=" + this.ipNumber
228 + "applicationId=" + this.applicationId + ", serviceName=" + this.serviceName + ", methodName=" + methodName
229 + ", queueStatus=" + this.queueStatus + ", queuePriority=" + this.queuePriority
230 + ", queueDate=" + this.queueDate + "]";
231 }
232
233 @Override
234 public AsynchronousCall getMethodCall() {
235 return this.methodCall;
236 }
237
238 public void setMethodCall(AsynchronousCall methodCall) {
239 this.methodCall = methodCall;
240 }
241
242 @Override
243 public String getMethodName() {
244 return this.methodName;
245 }
246
247 public void setMethodName(String methodName) {
248 this.methodName = methodName;
249 }
250
251 @Override
252 public Timestamp getExpirationDate() {
253 return this.expirationDate;
254 }
255
256 public void setExpirationDate(Timestamp expirationDate) {
257 this.expirationDate = expirationDate;
258 }
259
260 @Override
261 public PersistedMessagePayload getPayload() {
262 if (this.payload == null) {
263 if (this.getRouteQueueId() == null) {
264 return null;
265 } this.payload = KSBServiceLocator.getMessageQueueService().findByPersistedMessageByRouteQueueId(this.getRouteQueueId());
266 }
267 return this.payload;
268 }
269
270 public void setPayload(PersistedMessagePayload payload) {
271 this.payload = payload;
272 }
273
274 @Override
275 public String getValue1() {
276 return this.value1;
277 }
278
279 public void setValue1(String value1) {
280 this.value1 = value1;
281 }
282
283 @Override
284 public String getValue2() {
285 return this.value2;
286 }
287
288 public void setValue2(String value2) {
289 this.value2 = value2;
290 }
291
292 }