1 package org
.argeo
.slc
.jms
;
3 import java
.net
.InetAddress
;
4 import java
.net
.UnknownHostException
;
7 import javax
.jms
.Destination
;
8 import javax
.jms
.JMSException
;
9 import javax
.jms
.Message
;
10 import javax
.jms
.MessageListener
;
12 import org
.apache
.commons
.logging
.Log
;
13 import org
.apache
.commons
.logging
.LogFactory
;
14 import org
.argeo
.slc
.SlcException
;
15 import org
.argeo
.slc
.process
.SlcExecution
;
16 import org
.argeo
.slc
.runtime
.SlcAgent
;
17 import org
.argeo
.slc
.runtime
.SlcAgentDescriptor
;
18 import org
.springframework
.beans
.factory
.DisposableBean
;
19 import org
.springframework
.beans
.factory
.InitializingBean
;
20 import org
.springframework
.jms
.core
.JmsTemplate
;
22 /** JMS based implementation of SLC Agent. */
23 public class JmsAgent
implements SlcAgent
, InitializingBean
, DisposableBean
{
24 private final static Log log
= LogFactory
.getLog(JmsAgent
.class);
26 private final SlcAgentDescriptor agentDescriptor
;
27 private JmsTemplate jmsTemplate
;
28 private Destination agentRegister
;
29 private Destination agentUnregister
;
31 private String agentDestinationPrefix
= "agent.";
32 private String agentDestinationBase
;
36 agentDescriptor
= new SlcAgentDescriptor();
37 agentDescriptor
.setUuid(UUID
.randomUUID().toString());
38 agentDescriptor
.setHost(InetAddress
.getLocalHost().getHostName());
39 } catch (UnknownHostException e
) {
40 throw new SlcException("Unable to create agent descriptor.", e
);
44 public void afterPropertiesSet() throws Exception
{
45 agentDestinationBase
= agentDestinationPrefix
46 + agentDescriptor
.getUuid() + ".";
47 jmsTemplate
.convertAndSend(agentRegister
, agentDescriptor
);
48 log
.info("Agent #" + agentDescriptor
.getUuid() + " registered to "
52 public void destroy() throws Exception
{
53 jmsTemplate
.convertAndSend(agentUnregister
, agentDescriptor
);
54 log
.info("Agent #" + agentDescriptor
.getUuid() + " unregistered to "
58 public String
actionDestinationName(String action
) {
59 return agentDestinationBase
+ action
;
62 public void newExecution(SlcExecution slcExecution
) {
63 log
.info("Would execute SlcExecution :" + slcExecution
);
66 public void setJmsTemplate(JmsTemplate jmsTemplate
) {
67 this.jmsTemplate
= jmsTemplate
;
70 public void setAgentRegister(Destination agentRegister
) {
71 this.agentRegister
= agentRegister
;
74 public void setAgentUnregister(Destination agentUnregister
) {
75 this.agentUnregister
= agentUnregister
;
78 public void setAgentDestinationPrefix(String agentDestinationPrefix
) {
79 this.agentDestinationPrefix
= agentDestinationPrefix
;