]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java
Implement kill and process progress
[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.execution.ExecutionProcess;
27 import org.argeo.slc.execution.ExecutionStep;
28 import org.argeo.slc.msg.process.SlcExecutionStatusRequest;
29 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
30 import org.argeo.slc.process.SlcExecution;
31 import org.argeo.slc.process.SlcExecutionNotifier;
32 import org.argeo.slc.process.SlcExecutionStep;
33 import org.springframework.jms.JmsException;
34 import org.springframework.jms.core.JmsTemplate;
35
36 @SuppressWarnings("deprecation")
37 public class JmsSlcExecutionNotifier implements SlcExecutionNotifier {
38 private final static Log log = LogFactory
39 .getLog(JmsSlcExecutionNotifier.class);
40
41 private JmsTemplate jmsTemplate;
42
43 private Destination executionEventDestination;
44
45 // private Destination updateStatusDestination;
46
47 public void updateStatus(ExecutionProcess slcExecution, String oldStatus,
48 String newStatus) {
49 SlcExecutionStatusRequest req = new SlcExecutionStatusRequest(
50 slcExecution.getUuid(), newStatus);
51 convertAndSend(req);
52 }
53
54 public void addSteps(ExecutionProcess slcExecution,
55 List<ExecutionStep> additionalSteps) {
56 SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(
57 slcExecution.getUuid(), additionalSteps);
58 convertAndSend(req);
59 }
60
61 public void newExecution(SlcExecution slcExecution) {
62 throw new UnsupportedException();
63 }
64
65 public void updateExecution(SlcExecution slcExecution) {
66 throw new UnsupportedException();
67 }
68
69 public void setJmsTemplate(JmsTemplate jmsTemplate) {
70 this.jmsTemplate = jmsTemplate;
71 }
72
73 public void setExecutionEventDestination(
74 Destination executionEventDestination) {
75 this.executionEventDestination = executionEventDestination;
76 }
77
78 protected void convertAndSend(Object req) {
79 try {
80 jmsTemplate.convertAndSend(executionEventDestination, req);
81 } catch (JmsException e) {
82 log.warn("Send request " + req.getClass() + " to server: "
83 + e.getMessage());
84 if (log.isTraceEnabled())
85 log.debug("Original error.", e);
86 }
87 }
88 }