1 package org.openecomp.sdc.be.components.impl.lock;
3 import org.aspectj.lang.ProceedingJoinPoint;
4 import org.openecomp.sdc.be.components.impl.ComponentLocker;
5 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
6 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
7 import org.openecomp.sdc.common.log.wrappers.Logger;
9 public class ComponentLockAspect {
11 private static final Logger log = Logger.getLogger(ComponentLockAspect.class);
12 private final ComponentLocker componentLocker;
14 public ComponentLockAspect(ComponentLocker componentLocker) {
15 this.componentLocker = componentLocker;
18 public Object lock(ProceedingJoinPoint proceedingJoinPoint, String componentId, ComponentTypeEnum componentType) throws Throwable {
19 return surroundWithLockUnlock(proceedingJoinPoint, componentId, componentType.getNodeType());
22 private Object surroundWithLockUnlock(ProceedingJoinPoint proceedingJoinPoint, String componentId, NodeTypeEnum componentType) throws Throwable {
23 String methodName = proceedingJoinPoint.getSignature().toShortString();
25 log.trace("#{} - before locking component {} of type {}", methodName, componentId, componentType);
26 componentLocker.lock(componentId, componentType);
27 log.trace("#{} - after locking component {} of type {}", methodName, componentId, componentType);
28 return proceedingJoinPoint.proceed();
31 log.trace("#{} - before unlocking component {} of type {}", methodName, componentId, componentType);
32 componentLocker.unlock(componentId, componentType);
33 log.trace("#{} - after unlocking component {} of type {}", methodName, componentId, componentType);