]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java
45db072b9be17450342dca5cc90c000eccc28939
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.activemq / src / main / java / org / argeo / slc / jms / JmsSlcExecutionNotifier.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.argeo.slc.jms;
18
19 import java.util.List;
20
21 import javax.jms.Destination;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.slc.UnsupportedException;
26 import org.argeo.slc.msg.process.SlcExecutionStatusRequest;
27 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
28 import org.argeo.slc.process.SlcExecution;
29 import org.argeo.slc.process.SlcExecutionNotifier;
30 import org.argeo.slc.process.SlcExecutionStep;
31 import org.springframework.jms.JmsException;
32 import org.springframework.jms.core.JmsTemplate;
33
34 public class JmsSlcExecutionNotifier implements SlcExecutionNotifier {
35 private final static Log log = LogFactory
36 .getLog(JmsSlcExecutionNotifier.class);
37
38 private JmsTemplate jmsTemplate;
39
40 private Destination executionEventDestination;
41
42 // private Destination updateStatusDestination;
43
44 public void updateStatus(SlcExecution slcExecution, String oldStatus,
45 String newStatus) {
46 SlcExecutionStatusRequest req = new SlcExecutionStatusRequest(
47 slcExecution.getUuid(), newStatus);
48 convertAndSend(req);
49 }
50
51 public void addSteps(SlcExecution slcExecution,
52 List<SlcExecutionStep> additionalSteps) {
53 SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(
54 slcExecution.getUuid(), additionalSteps);
55 convertAndSend(req);
56 }
57
58 public void newExecution(SlcExecution slcExecution) {
59 throw new UnsupportedException();
60 }
61
62 public void updateExecution(SlcExecution slcExecution) {
63 throw new UnsupportedException();
64 }
65
66 public void setJmsTemplate(JmsTemplate jmsTemplate) {
67 this.jmsTemplate = jmsTemplate;
68 }
69
70 public void setExecutionEventDestination(
71 Destination executionEventDestination) {
72 this.executionEventDestination = executionEventDestination;
73 }
74
75 protected void convertAndSend(Object req) {
76 try {
77 jmsTemplate.convertAndSend(executionEventDestination, req);
78 } catch (JmsException e) {
79 log.warn("Send request " + req.getClass() + " to server: "
80 + e.getMessage());
81 if (log.isTraceEnabled())
82 log.debug("Original error.", e);
83 }
84 }
85 }