small refactoring

Use a private method to deserialize hooks
remove unnecessary if statement

Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/d9a36932
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/d9a36932
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/d9a36932

Branch: refs/heads/master
Commit: d9a369329b741f3f78c9f62e28768faee7063cbd
Parents: ce7c716
Author: michelo <michelo@michelo-desktop>
Authored: Mon Apr 9 21:38:56 2018 +0200
Committer: michelo <michelo@michelo-desktop>
Committed: Mon Apr 9 21:38:56 2018 +0200

----------------------------------------------------------------------
 .../apache/storm/daemon/worker/WorkerState.java | 34 ++++++++++----------
 1 file changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/d9a36932/storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java
----------------------------------------------------------------------
diff --git 
a/storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java 
b/storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java
index b763c8d..e709d04 100644
--- a/storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java
+++ b/storm-client/src/jvm/org/apache/storm/daemon/worker/WorkerState.java
@@ -344,15 +344,7 @@ public class WorkerState {
         int maxTaskId = getMaxTaskId(componentToSortedTasks);
         this.workerTransfer = new WorkerTransfer(this, topologyConf, 
maxTaskId);
         this.bpTracker = new BackPressureTracker(workerId, localTaskIds);
-        // 
-        this.deserializedWorkerHooks = new ArrayList<>();
-        if (topology.is_set_worker_hooks()) {
-            for (ByteBuffer hook : topology.get_worker_hooks()) {
-                byte[] hookBytes = Utils.toByteArray(hook);
-                IWorkerHook hookObject = Utils.javaDeserialize(hookBytes, 
IWorkerHook.class);
-                deserializedWorkerHooks.add(hookObject);
-            }
-        }    
+        this.deserializedWorkerHooks = deserializeWorkerHooks();
     }
 
     public void refreshConnections() {
@@ -610,20 +602,28 @@ public class WorkerState {
         }
     }
 
-    public void runWorkerStartHooks() {
-        WorkerTopologyContext workerContext = getWorkerTopologyContext();
+    private List<IWorkerHook> deserializeWorkerHooks() {
+        List<IWorkerHook> myHookList = new ArrayList<>();
         if (topology.is_set_worker_hooks()) {
-            for (IWorkerHook hook : getDeserializedWorkerHooks()) {
-                hook.start(topologyConf, workerContext);
+            for (ByteBuffer hook : topology.get_worker_hooks()) {
+                byte[] hookBytes = Utils.toByteArray(hook);
+                IWorkerHook hookObject = Utils.javaDeserialize(hookBytes, 
IWorkerHook.class);
+                myHookList.add(hookObject);
             }
         }
+        return myHookList;
+    }
+
+    public void runWorkerStartHooks() {
+        WorkerTopologyContext workerContext = getWorkerTopologyContext();
+        for (IWorkerHook hook : getDeserializedWorkerHooks()) {
+            hook.start(topologyConf, workerContext);
+        }
     }
 
     public void runWorkerShutdownHooks() {
-        if (topology.is_set_worker_hooks()) {
-            for (IWorkerHook hook : getDeserializedWorkerHooks()) {
-                hook.shutdown();
-            }
+        for (IWorkerHook hook : getDeserializedWorkerHooks()) {
+            hook.shutdown();
         }
     }
 

Reply via email to