01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.callforwarding;
18:
19: import java.sql.Timestamp;
20:
21: import javax.transaction.Status;
22:
23: import org.apache.log4j.Logger;
24: import org.kuali.bus.services.KSBServiceLocator;
25: import org.kuali.rice.RiceConstants;
26: import org.kuali.rice.core.Core;
27: import org.kuali.rice.util.RiceUtilities;
28:
29: import edu.iu.uis.eden.messaging.AsynchronousCall;
30: import edu.iu.uis.eden.messaging.MessageServiceInvoker;
31: import edu.iu.uis.eden.messaging.PersistedMassagePayload;
32: import edu.iu.uis.eden.messaging.PersistedMessage;
33: import edu.iu.uis.eden.messaging.serviceproxies.AsynchronousMessageCaller;
34:
35: /**
36: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
37: */
38: public class ForwardedCallHandlerImpl implements ForwardedCallHandler {
39:
40: private static final Logger LOG = Logger
41: .getLogger(ForwardedCallHandlerImpl.class);
42:
43: public void handleCall(PersistedMessage message) throws Exception {
44: LOG.debug("Recieved forwared message from service "
45: + message.getMethodCall().getServiceInfo().getQname());
46: PersistedMessage copy = new PersistedMessage();
47: copy.setExpirationDate(message.getExpirationDate());
48: copy.setIpNumber(RiceUtilities.getIpNumber());
49: copy.setMessageEntity(message.getMessageEntity());
50: copy.setMethodCall(message.getMethodCall());
51: copy.setMethodName(message.getMethodName());
52: copy.setQueueDate(new Timestamp(System.currentTimeMillis()));
53: copy.setQueuePriority(message.getQueuePriority());
54: copy.setQueueStatus(RiceConstants.ROUTE_QUEUE_QUEUED);
55: copy.setRetryCount(message.getRetryCount());
56: AsynchronousCall methodCall = message.getPayload()
57: .getMethodCall();
58: methodCall.setIgnoreStoreAndForward(true);
59: copy.setPayload(new PersistedMassagePayload(methodCall, copy));
60: copy.setServiceName(message.getServiceName());
61: saveMessage(copy);
62: executeMessage(copy);
63:
64: }
65:
66: // TODO copied from AsynchronousServiceCallProxy
67: protected void saveMessage(PersistedMessage message) {
68: if (new Boolean(Core.getCurrentContextConfig().getProperty(
69: RiceConstants.MESSAGE_PERSISTENCE))) {
70: if (LOG.isDebugEnabled()) {
71: LOG.debug("Persisting Message " + message);
72: }
73: message.setQueueStatus(RiceConstants.ROUTE_QUEUE_ROUTING);
74: KSBServiceLocator.getRouteQueueService().save(message);
75: }
76: }
77:
78: // TODO copied from AsynchronousServiceCallProxy
79: protected void executeMessage(PersistedMessage message)
80: throws Exception {
81: if (!new Boolean(Core.getCurrentContextConfig().getProperty(
82: RiceConstants.MESSAGING_OFF))) {
83: if (KSBServiceLocator.getJtaTransactionManager()
84: .getStatus() == Status.STATUS_ACTIVE) {
85: KSBServiceLocator.getJtaTransactionManager()
86: .getTransaction().registerSynchronization(
87: new AsynchronousMessageCaller(message));
88: } else {
89: KSBServiceLocator.getThreadPool().execute(
90: new MessageServiceInvoker(message));
91: }
92: }
93: }
94: }
|