2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.services
;
18 import java
.util
.Iterator
;
19 import java
.util
.List
;
21 import org
.apache
.commons
.logging
.Log
;
22 import org
.apache
.commons
.logging
.LogFactory
;
23 import org
.argeo
.slc
.msg
.MsgConstants
;
24 import org
.argeo
.slc
.msg
.event
.SlcEvent
;
25 import org
.argeo
.slc
.msg
.event
.SlcEventPublisher
;
26 import org
.argeo
.slc
.msg
.process
.SlcExecutionStatusRequest
;
27 import org
.argeo
.slc
.process
.SlcExecution
;
28 import org
.argeo
.slc
.runtime
.SlcAgentDescriptor
;
29 import org
.aspectj
.lang
.JoinPoint
;
30 import org
.aspectj
.lang
.annotation
.After
;
31 import org
.aspectj
.lang
.annotation
.Aspect
;
34 public class EventPublisherAspect
{
35 public final static String EVT_AGENT_REGISTERED
= "agentRegistered";
36 public final static String EVT_AGENT_UNREGISTERED
= "agentUnregistered";
37 public final static String EVT_NEW_SLC_EXECUTION
= "newSlcExecution";
38 public final static String EVT_UPDATE_SLC_EXECUTION_STATUS
= "updateSlcExecutionStatus";
40 private final static Log log
= LogFactory
41 .getLog(EventPublisherAspect
.class);
43 private List
<SlcEventPublisher
> eventPublishers
;
45 @After("execution(void org.argeo.slc.services.AgentService.register(..))")
46 public void registerAgent(JoinPoint jp
) throws Throwable
{
47 SlcAgentDescriptor agentDescriptor
= (SlcAgentDescriptor
) jp
.getArgs()[0];
48 SlcEvent event
= new SlcEvent(EVT_AGENT_REGISTERED
);
49 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_AGENT_ID
,
50 agentDescriptor
.getUuid());
54 @After("execution(void org.argeo.slc.services.AgentService.unregister(..))")
55 public void unregisterAgent(JoinPoint jp
) throws Throwable
{
56 SlcAgentDescriptor agentDescriptor
= (SlcAgentDescriptor
) jp
.getArgs()[0];
57 SlcEvent event
= new SlcEvent(EVT_AGENT_UNREGISTERED
);
58 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_AGENT_ID
,
59 agentDescriptor
.getUuid());
63 @After("execution(void org.argeo.slc.services.SlcExecutionService.newExecution(..))")
64 public void newSlcExecution(JoinPoint jp
) throws Throwable
{
65 SlcExecution slcExecution
= (SlcExecution
) jp
.getArgs()[0];
66 SlcEvent event
= new SlcEvent(EVT_NEW_SLC_EXECUTION
);
67 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_ID
,
68 slcExecution
.getUuid());
72 @After("execution(void org.argeo.slc.services.SlcExecutionService.updateStatus(..))")
73 public void updateSlcExecutionStatus(JoinPoint jp
) throws Throwable
{
74 SlcExecutionStatusRequest msg
= (SlcExecutionStatusRequest
) jp
76 SlcEvent event
= new SlcEvent(EVT_UPDATE_SLC_EXECUTION_STATUS
);
77 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_ID
,
78 msg
.getSlcExecutionUuid());
79 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_STATUS
,
84 public void setEventPublishers(List
<SlcEventPublisher
> eventPublishers
) {
85 this.eventPublishers
= eventPublishers
;
88 protected void publishEvent(SlcEvent event
) {
90 for (Iterator
<SlcEventPublisher
> it
= eventPublishers
.iterator(); it
92 SlcEventPublisher eventPublisher
= it
.next();
93 if (log
.isTraceEnabled())
94 log
.debug("Publish event: "
95 + event
.getHeaders().get(SlcEvent
.EVENT_TYPE
) + " to "
97 eventPublisher
.publish(event
);