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
.core
.runtime
.AbstractAgent
;
16 import org
.argeo
.slc
.process
.SlcExecution
;
17 import org
.argeo
.slc
.runtime
.SlcAgent
;
18 import org
.argeo
.slc
.runtime
.SlcAgentDescriptor
;
19 import org
.springframework
.beans
.factory
.DisposableBean
;
20 import org
.springframework
.beans
.factory
.InitializingBean
;
21 import org
.springframework
.jms
.core
.JmsTemplate
;
23 /** JMS based implementation of SLC Agent. */
24 public class JmsAgent
extends AbstractAgent
implements SlcAgent
, InitializingBean
, DisposableBean
{
25 private final static Log log
= LogFactory
.getLog(JmsAgent
.class);
27 private final SlcAgentDescriptor agentDescriptor
;
28 private JmsTemplate jmsTemplate
;
29 private Destination agentRegister
;
30 private Destination agentUnregister
;
32 private String agentDestinationPrefix
= "agent.";
33 private String agentDestinationBase
;
37 agentDescriptor
= new SlcAgentDescriptor();
38 agentDescriptor
.setUuid(UUID
.randomUUID().toString());
39 agentDescriptor
.setHost(InetAddress
.getLocalHost().getHostName());
40 } catch (UnknownHostException e
) {
41 throw new SlcException("Unable to create agent descriptor.", e
);
45 public void afterPropertiesSet() throws Exception
{
46 agentDestinationBase
= agentDestinationPrefix
47 + agentDescriptor
.getUuid() + ".";
48 jmsTemplate
.convertAndSend(agentRegister
, agentDescriptor
);
49 log
.info("Agent #" + agentDescriptor
.getUuid() + " registered to "
53 public void destroy() throws Exception
{
54 jmsTemplate
.convertAndSend(agentUnregister
, agentDescriptor
);
55 log
.info("Agent #" + agentDescriptor
.getUuid() + " unregistered to "
59 public String
actionDestinationName(String action
) {
60 return agentDestinationBase
+ action
;
63 public void newExecution(SlcExecution slcExecution
) {
64 log
.info("Execute SlcExecution :" + slcExecution
);
65 runSlcExecution(slcExecution
);
68 public void setJmsTemplate(JmsTemplate jmsTemplate
) {
69 this.jmsTemplate
= jmsTemplate
;
72 public void setAgentRegister(Destination agentRegister
) {
73 this.agentRegister
= agentRegister
;
76 public void setAgentUnregister(Destination agentUnregister
) {
77 this.agentUnregister
= agentUnregister
;
80 public void setAgentDestinationPrefix(String agentDestinationPrefix
) {
81 this.agentDestinationPrefix
= agentDestinationPrefix
;