Ravi Nori has uploaded a new change for review.

Change subject: wip: remove the use of @LockIdNameAttribute
......................................................................

wip: remove the use of @LockIdNameAttribute

Annotations should use behavior modification of
reference objects, not as controller of logic
paths witin inheritance.

@LockIdNameAttribute annotation is used to
indicate incomplete logic requirement.

Change-Id: Ie57e4f7c00ebcd6a4e9e0e61b7d26f50f2d00858
Bug-Url: https://bugzilla.redhat.com/995836
Signed-off-by: Ravi Nori <rn...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsSpmIdCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/LockProperties.java
4 files changed, 62 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/44/25944/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
index 6674a75..3a2af29 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
@@ -26,10 +26,10 @@
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
-@LockIdNameAttribute
 @NonTransactiveCommandAttribute
 public class ActivateVdsCommand<T extends VdsActionParameters> extends 
VdsCommand<T> {
 
+    private final LockProperties lockProperties = new LockProperties();
     private boolean haMaintenanceFailed;
 
     public ActivateVdsCommand(T parameters) {
@@ -48,6 +48,11 @@
     }
 
     @Override
+    protected LockProperties getLockProperties() {
+        return lockProperties;
+    }
+
+    @Override
     protected void executeCommand() {
 
         final VDS vds = getVds();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsSpmIdCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsSpmIdCommand.java
index 4dd432c..57b300c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsSpmIdCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsSpmIdCommand.java
@@ -19,8 +19,9 @@
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 
 @InternalCommandAttribute
-@LockIdNameAttribute(isWait = true)
 public class AddVdsSpmIdCommand<T extends VdsActionParameters> extends 
VdsCommand<T> {
+
+    private final LockProperties lockProperties = new 
LockProperties().setWait(true);
 
     /**
      * Constructor for command creation when compensation is applied on startup
@@ -36,6 +37,11 @@
     }
 
     @Override
+    protected LockProperties getLockProperties() {
+        return lockProperties;
+    }
+
+    @Override
     protected boolean canDoAction() {
         return true;
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index e5777e8..1b0d509 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -507,8 +507,8 @@
      */
     private void initiateLockEndAction() {
         if (commandLock == null) {
-            LockIdNameAttribute annotation = 
getClass().getAnnotation(LockIdNameAttribute.class);
-            if (annotation != null && !annotation.isReleaseAtEndOfExecute()) {
+            LockProperties lockProperties = getLockProperties();
+            if (lockProperties != null && 
!lockProperties.isReleaseAtEndOfExecute()) {
                 commandLock = buildLock();
             }
 
@@ -1745,12 +1745,16 @@
         commandLock = lock;
     }
 
+    protected LockProperties getLockProperties() {
+         return 
LockProperties.build(getClass().getAnnotation(LockIdNameAttribute.class));
+    }
+
     protected boolean acquireLock() {
-        LockIdNameAttribute annotation = 
getClass().getAnnotation(LockIdNameAttribute.class);
+        LockProperties lockProperties = getLockProperties();
         boolean returnValue = true;
-        if (annotation != null) {
-            releaseLocksAtEndOfExecute = annotation.isReleaseAtEndOfExecute();
-            if (!annotation.isWait()) {
+        if (lockProperties != null) {
+            releaseLocksAtEndOfExecute = 
lockProperties.isReleaseAtEndOfExecute();
+            if (!lockProperties.isWait()) {
                 returnValue = acquireLockInternal();
             } else {
                 acquireLockAndWait();
@@ -1764,10 +1768,10 @@
      * @return
      */
     public final boolean acquireLockAsyncTask() {
-        LockIdNameAttribute annotation = 
getClass().getAnnotation(LockIdNameAttribute.class);
+        LockProperties lockProperties = getLockProperties();
         boolean returnValue = true;
-        if (annotation != null) {
-            releaseLocksAtEndOfExecute = annotation.isReleaseAtEndOfExecute();
+        if (lockProperties != null) {
+            releaseLocksAtEndOfExecute = 
lockProperties.isReleaseAtEndOfExecute();
             if (!releaseLocksAtEndOfExecute) {
                 returnValue = acquireLockInternal();
             }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/LockProperties.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/LockProperties.java
new file mode 100644
index 0000000..2d154d2
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/LockProperties.java
@@ -0,0 +1,36 @@
+package org.ovirt.engine.core.bll;
+
+public class LockProperties {
+
+    private boolean wait = false;
+    private boolean releaseAtEndOfExecute = true;
+
+    public LockProperties() {}
+
+    public boolean isWait() {
+        return wait;
+    }
+
+    public LockProperties setWait(boolean wait) {
+        this.wait = wait;
+        return this;
+    }
+
+    public boolean isReleaseAtEndOfExecute() {
+        return releaseAtEndOfExecute;
+    }
+
+    public LockProperties setReleaseAtEndOfExecute(boolean 
releaseAtEndOfExecute) {
+        this.releaseAtEndOfExecute = releaseAtEndOfExecute;
+        return this;
+    }
+
+    public static LockProperties build(LockIdNameAttribute annotation) {
+        if (annotation == null) {
+           return null;
+        }
+        return new LockProperties().
+                setWait(annotation.isWait()).
+                setReleaseAtEndOfExecute(annotation.isReleaseAtEndOfExecute());
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/25944
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie57e4f7c00ebcd6a4e9e0e61b7d26f50f2d00858
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <rn...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to