]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgentProxyFactory.java
Start working on serialized JMS
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.activemq / src / main / java / org / argeo / slc / jms / JmsAgentProxyFactory.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 import java.util.UUID;
21
22 import javax.jms.Destination;
23 import javax.jms.JMSException;
24 import javax.jms.Message;
25
26 import org.argeo.slc.msg.ReferenceList;
27 import org.argeo.slc.runtime.SlcAgent;
28 import org.argeo.slc.runtime.SlcAgentFactory;
29 import org.springframework.jms.core.JmsTemplate;
30 import org.springframework.jms.core.MessagePostProcessor;
31
32 public class JmsAgentProxyFactory implements SlcAgentFactory {
33 private Destination requestDestination;
34 private Destination responseDestination;
35 private Destination pingAllDestination;
36 private JmsTemplate jmsTemplate;
37
38 public SlcAgent getAgent(String uuid) {
39 return new JmsAgentProxy(uuid, requestDestination, responseDestination,
40 jmsTemplate);
41 }
42
43 public void pingAll(List<String> activeAgentIds) {
44 ReferenceList referenceList = new ReferenceList(activeAgentIds);
45 jmsTemplate.convertAndSend(pingAllDestination, referenceList,
46 new MessagePostProcessor() {
47
48 public Message postProcessMessage(Message message)
49 throws JMSException {
50 message.setJMSCorrelationID(UUID.randomUUID()
51 .toString());
52 message.setStringProperty(JmsAgent.PROPERTY_QUERY,
53 JmsAgent.QUERY_PING_ALL);
54 return message;
55 }
56 });
57 }
58
59 public void setRequestDestination(Destination requestDestination) {
60 this.requestDestination = requestDestination;
61 }
62
63 public void setResponseDestination(Destination responseDestination) {
64 this.responseDestination = responseDestination;
65 }
66
67 public void setJmsTemplate(JmsTemplate jmsTemplate) {
68 this.jmsTemplate = jmsTemplate;
69 }
70
71 public void setPingAllDestination(Destination pingAllDestination) {
72 this.pingAllDestination = pingAllDestination;
73 }
74
75 }