2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.services
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.msg
.MsgConstants
;
25 import org
.argeo
.slc
.msg
.event
.SlcEvent
;
26 import org
.argeo
.slc
.msg
.event
.SlcEventPublisher
;
27 import org
.argeo
.slc
.msg
.process
.SlcExecutionStatusRequest
;
28 import org
.argeo
.slc
.process
.SlcExecution
;
29 import org
.argeo
.slc
.runtime
.SlcAgentDescriptor
;
30 import org
.aspectj
.lang
.JoinPoint
;
31 import org
.aspectj
.lang
.annotation
.After
;
32 import org
.aspectj
.lang
.annotation
.Aspect
;
35 public class EventPublisherAspect
{
36 public final static String EVT_AGENT_REGISTERED
= "agentRegistered";
37 public final static String EVT_AGENT_UNREGISTERED
= "agentUnregistered";
38 public final static String EVT_NEW_SLC_EXECUTION
= "newSlcExecution";
39 public final static String EVT_UPDATE_SLC_EXECUTION_STATUS
= "updateSlcExecutionStatus";
41 private final static Log log
= LogFactory
42 .getLog(EventPublisherAspect
.class);
44 private List
<SlcEventPublisher
> eventPublishers
;
46 @After("execution(void org.argeo.slc.services.AgentService.register(..))")
47 public void registerAgent(JoinPoint jp
) throws Throwable
{
48 SlcAgentDescriptor agentDescriptor
= (SlcAgentDescriptor
) jp
.getArgs()[0];
49 SlcEvent event
= new SlcEvent(EVT_AGENT_REGISTERED
);
50 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_AGENT_ID
,
51 agentDescriptor
.getUuid());
55 @After("execution(void org.argeo.slc.services.AgentService.unregister(..))")
56 public void unregisterAgent(JoinPoint jp
) throws Throwable
{
57 SlcAgentDescriptor agentDescriptor
= (SlcAgentDescriptor
) jp
.getArgs()[0];
58 SlcEvent event
= new SlcEvent(EVT_AGENT_UNREGISTERED
);
59 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_AGENT_ID
,
60 agentDescriptor
.getUuid());
64 @After("execution(void org.argeo.slc.services.SlcExecutionService.newExecution(..))")
65 public void newSlcExecution(JoinPoint jp
) throws Throwable
{
66 SlcExecution slcExecution
= (SlcExecution
) jp
.getArgs()[0];
67 SlcEvent event
= new SlcEvent(EVT_NEW_SLC_EXECUTION
);
68 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_ID
,
69 slcExecution
.getUuid());
73 @After("execution(void org.argeo.slc.services.SlcExecutionService.updateStatus(..))")
74 public void updateSlcExecutionStatus(JoinPoint jp
) throws Throwable
{
75 SlcExecutionStatusRequest msg
= (SlcExecutionStatusRequest
) jp
77 SlcEvent event
= new SlcEvent(EVT_UPDATE_SLC_EXECUTION_STATUS
);
78 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_ID
,
79 msg
.getSlcExecutionUuid());
80 event
.getHeaders().put(MsgConstants
.PROPERTY_SLC_EXECUTION_STATUS
,
85 public void setEventPublishers(List
<SlcEventPublisher
> eventPublishers
) {
86 this.eventPublishers
= eventPublishers
;
89 protected void publishEvent(SlcEvent event
) {
91 for (Iterator
<SlcEventPublisher
> it
= eventPublishers
.iterator(); it
93 SlcEventPublisher eventPublisher
= it
.next();
94 if (log
.isTraceEnabled())
95 log
.debug("Publish event: "
96 + event
.getHeaders().get(SlcEvent
.EVENT_TYPE
) + " to "
98 eventPublisher
.publish(event
);