Arik Hadas has uploaded a new change for review.

Change subject: core: make postConstruct final
......................................................................

core: make postConstruct final

Consider the following case:
Class A {
  @PostConstruct
  protected void foo() {}
}
Class B extends A {
  @Override
  @PostConstruct
  protected void foo() {}
}

JBOSS 7.1.1: when instantiate class B, B#foo will be called twice. This
seems to be a bug in JBOSS.
JBOSS EAP 6.3: when instantiate class B, B#foo will be called only once.

Because of Ibf9cdd60, we have @PostConstruct on postConstruct methods in
commands as well as in the CommandBase, so we have the structure above,
thus in JBOSS 7.1.1 the postConstruct methods are called multiple times.

This patch introduces a different approach where the postConstruct
method that is annotated with @PostConstruct is declared as final in
CommandBase, and calls CommandBase#init which is the method that should
be overridden by commands and does not need to be annotated with
@PostConstruct.

Change-Id: I8340d8348b298fec0c73bf93b7411a149e9fe8c0
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CloneVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmFromConfigurationCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/UpgradeHostCommand.java
9 files changed, 21 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/41212/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
index cd2ffcb..aebead7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
@@ -11,8 +11,6 @@
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
-import javax.annotation.PostConstruct;
-
 import org.apache.commons.codec.CharEncoding;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.StringUtils;
@@ -146,8 +144,7 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
+    protected void init() {
         T parameters = getParameters();
         if (parameters.getVmStaticData() != null) {
             Guid templateIdToUse = 
getParameters().getVmStaticData().getVmtGuid();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CloneVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CloneVmCommand.java
index ec6de22..823a932 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CloneVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CloneVmCommand.java
@@ -5,7 +5,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.annotation.PostConstruct;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
@@ -53,9 +52,8 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
-        super.postConstruct();
+    protected void init() {
+        super.init();
         oldVmId = getParameters().getVmId();
         setVmName(getParameters().getNewName());
 
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 aefda6a..bafe1c8 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
@@ -201,14 +201,19 @@
     }
 
     /**
-     * Implement this method whenever you need extra initialization of the 
command after the
-     * constructor. All DB calls or other interaction with the command 
dependencies for initialization
-     * should be done here. It is ensured that all injected dependencies were 
injected at the time calling.
-     *
      * @see PostConstruct
      */
     @PostConstruct
-    protected void postConstruct() {
+    protected final void postConstruct() {
+        init();
+    }
+
+    /**
+     * Implement this method whenever you need extra initialization of the 
command after the
+     * constructor. All DB calls or other interaction with the command 
dependencies for initialization
+     * should be done here. It is ensured that all injected dependencies were 
injected at the time calling.
+     */
+    protected void init() {
     }
 
     protected List<SPMAsyncTaskHandler> initTaskHandlers() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
index 2db8c91..8ca276c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java
@@ -6,7 +6,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.PostConstruct;
 
 import org.apache.commons.collections.MapUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -89,8 +88,7 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
+    protected void init() {
         // skipped if participating in compensation flow
         if (getParameters() == null) {
             return;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 43ae6bd..3e72801 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -11,8 +11,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import javax.annotation.PostConstruct;
-
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -117,9 +115,8 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
-        super.postConstruct();
+    protected void init() {
+        super.init();
         T parameters = getParameters();
         setVmId(parameters.getContainerId());
         setVm(parameters.getVm());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java
index cf00705..bf865ff 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java
@@ -6,7 +6,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.annotation.PostConstruct;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -92,8 +91,7 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
+    protected void init() {
         T parameters = getParameters();
         // before the execute phase, 
parameters.getVmId().equals(parameters.getVm().getId() == true
         // afterwards if will be false if parameters.isImportAsNewEntity() == 
true, and there is no
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmFromConfigurationCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmFromConfigurationCommand.java
index 9de7734..764db0b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmFromConfigurationCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmFromConfigurationCommand.java
@@ -6,7 +6,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import javax.annotation.PostConstruct;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -68,8 +67,7 @@
     }
 
     @Override
-    @PostConstruct
-    protected void postConstruct() {
+    protected void init() {
         VM vmFromConfiguration = getParameters().getVm();
         if (vmFromConfiguration != null) {
             
vmFromConfiguration.getStaticData().setVdsGroupId(getParameters().getVdsGroupId());
@@ -83,7 +81,7 @@
 
         setVdsGroupId(getParameters().getVdsGroupId());
         getParameters().setStoragePoolId(getVdsGroup().getStoragePoolId());
-        super.postConstruct();
+        super.init();
     }
 
     private void initUnregisteredVM() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index d54729d..caa4132 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -143,9 +143,7 @@
     }
 
     @Override
-    protected void postConstruct() {
-        super.postConstruct();
-
+    protected void init() {
         if (getVm() != null) {
             needsHostDevices = 
hostDeviceManager.checkVmNeedsDirectPassthrough(getVm());
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/UpgradeHostCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/UpgradeHostCommand.java
index ce96f6b..76fbeee 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/UpgradeHostCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/UpgradeHostCommand.java
@@ -4,8 +4,6 @@
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
-import javax.annotation.PostConstruct;
-
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
 import org.ovirt.engine.core.bll.VdsCommand;
 import org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil;
@@ -26,9 +24,8 @@
         super(parameters);
     }
 
-    @PostConstruct
     @Override
-    protected void postConstruct() {
+    protected void init() {
         if (getParameters().getInitialStatus() == null) {
             if (getVds() != null) {
                 getParameters().setInitialStatus(getVds().getStatus());


-- 
To view, visit https://gerrit.ovirt.org/41212
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to