1 package org
.argeo
.slc
.core
.execution
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
5 import org
.argeo
.slc
.execution
.ExecutionContext
;
6 import org
.argeo
.slc
.execution
.ExecutionFlow
;
7 import org
.argeo
.slc
.execution
.ExecutionStack
;
8 import org
.aspectj
.lang
.ProceedingJoinPoint
;
9 import org
.aspectj
.lang
.annotation
.Around
;
10 import org
.aspectj
.lang
.annotation
.Aspect
;
11 import org
.aspectj
.lang
.annotation
.Pointcut
;
14 public class ExecutionAspect
{
15 private final static Log log
= LogFactory
.getLog(ExecutionAspect
.class);
17 private ExecutionStack executionStack
;
18 private ExecutionContext executionContext
;
20 @Around("flowExecution()")
21 public void aroundFlow(ProceedingJoinPoint pjp
) throws Throwable
{
22 // IMPORTANT: Make sure that the execution context is called before the execution stack
23 executionContext
.getUuid();
25 ExecutionFlow executionFlow
= (ExecutionFlow
) pjp
.getTarget();
26 executionStack
.enterFlow(executionFlow
);
27 executionContext
.setVariable(ExecutionContext
.VAR_FLOW_ID
,
28 executionStack
.getCurrentStackLevelUuid());
29 executionContext
.setVariable(ExecutionContext
.VAR_FLOW_NAME
,
30 executionFlow
.getName());
32 if (log
.isDebugEnabled())
33 logStackEvent("=> ", executionFlow
);
34 // Actually execute the flow
36 if (log
.isDebugEnabled())
37 logStackEvent("<= ", executionFlow
);
39 executionStack
.leaveFlow(executionFlow
);
42 @Around("getVariable()")
43 public Object
aroundGetVariable(ProceedingJoinPoint pjp
) throws Throwable
{
44 Object obj
= pjp
.proceed();
45 // if the variable was not found, look in the stack starting at the
48 String key
= pjp
.getArgs()[0].toString();
49 obj
= executionStack
.findLocalVariable(key
);
54 @Pointcut("execution(void org.argeo.slc.execution.ExecutionFlow.run())")
55 public void flowExecution() {
58 @Pointcut("execution(* org.argeo.slc.execution.ExecutionContext.getVariable(..))")
59 public void getVariable() {
62 public void setExecutionStack(ExecutionStack executionStack
) {
63 this.executionStack
= executionStack
;
66 public void setExecutionContext(ExecutionContext executionContext
) {
67 this.executionContext
= executionContext
;
70 protected void logStackEvent(String symbol
, ExecutionFlow executionFlow
) {
71 Integer stackSize
= executionStack
.getStackSize();
72 log
.debug(depthSpaces(stackSize
) + symbol
+ executionFlow
+ " #"
73 + executionStack
.getCurrentStackLevelUuid() + ", depth="
77 private String
depthSpaces(int depth
) {
78 StringBuffer buf
= new StringBuffer(depth
* 2);
79 for (int i
= 0; i
< depth
; i
++)
81 return buf
.toString();