]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgentProxyFactory.java
Event listener use only one JMS Connection
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.activemq / src / main / java / org / argeo / slc / jms / JmsAgentProxyFactory.java
1 package org.argeo.slc.jms;
2
3 import java.util.List;
4 import java.util.UUID;
5
6 import javax.jms.Destination;
7 import javax.jms.JMSException;
8 import javax.jms.Message;
9
10 import org.argeo.slc.msg.ReferenceList;
11 import org.argeo.slc.runtime.SlcAgent;
12 import org.argeo.slc.runtime.SlcAgentFactory;
13 import org.springframework.jms.core.JmsTemplate;
14 import org.springframework.jms.core.MessagePostProcessor;
15
16 public class JmsAgentProxyFactory implements SlcAgentFactory {
17 private Destination requestDestination;
18 private Destination responseDestination;
19 private Destination pingAllDestination;
20 private JmsTemplate jmsTemplate;
21
22 public SlcAgent getAgent(String uuid) {
23 return new JmsAgentProxy(uuid, requestDestination, responseDestination,
24 jmsTemplate);
25 }
26
27 public void pingAll(List<String> activeAgentIds) {
28 ReferenceList referenceList = new ReferenceList(activeAgentIds);
29 jmsTemplate.convertAndSend(pingAllDestination, referenceList,
30 new MessagePostProcessor() {
31
32 public Message postProcessMessage(Message message)
33 throws JMSException {
34 message.setJMSCorrelationID(UUID.randomUUID()
35 .toString());
36 message.setStringProperty(JmsAgent.PROPERTY_QUERY,
37 JmsAgent.QUERY_PING_ALL);
38 return message;
39 }
40 });
41 }
42
43 public void setRequestDestination(Destination requestDestination) {
44 this.requestDestination = requestDestination;
45 }
46
47 public void setResponseDestination(Destination responseDestination) {
48 this.responseDestination = responseDestination;
49 }
50
51 public void setJmsTemplate(JmsTemplate jmsTemplate) {
52 this.jmsTemplate = jmsTemplate;
53 }
54
55 public void setPingAllDestination(Destination pingAllDestination) {
56 this.pingAllDestination = pingAllDestination;
57 }
58
59 }