1 package dst.ass2.aop.management;
3 import dst.ass2.aop.IPluginExecutable;
4 import org.aspectj.lang.ProceedingJoinPoint;
5 import org.aspectj.lang.annotation.Around;
6 import org.aspectj.lang.annotation.Aspect;
7 import org.aspectj.lang.reflect.MethodSignature;
9 import java.util.Timer;
10 import java.util.TimerTask;
13 public class ManagementAspect {
14 @Around("execution(* dst.ass2.aop.IPluginExecutable.execute(..)) && @annotation(Timeout)")
15 public Object around(ProceedingJoinPoint point) {
16 // setup interruptionTimer.
17 Timeout timeoutAnn = ((MethodSignature) point.getSignature()).getMethod().getAnnotation(Timeout.class);
18 System.out.println("ManagementAspect - sched");
20 Timer interruptionTimer = new Timer(true);
21 interruptionTimer.schedule(new TimerTask() {
24 System.out.println("ManagementAspect - interrupt");
25 ((IPluginExecutable) point.getTarget()).interrupted();
27 }, timeoutAnn.value());
29 //execute actual function
32 result = point.proceed();
33 } catch (Throwable throwable) {
34 throwable.printStackTrace();
37 // once the function completed, cancel interruptionTimer and return results.
38 interruptionTimer.cancel();