imbajin commented on code in PR #286:
URL: 
https://github.com/apache/incubator-hugegraph-computer/pull/286#discussion_r1421886867


##########
computer-core/src/main/java/org/apache/hugegraph/computer/core/worker/WorkerService.java:
##########
@@ -91,57 +89,67 @@ public WorkerService() {
     /**
      * Init worker service, create the managers used by worker service.
      */
-    public void init(Config config) {
-        E.checkArgument(!this.inited, "The %s has been initialized", this);
-
-        this.serviceThread = Thread.currentThread();
-        this.registerShutdownHook();
-
-        this.config = config;
-
-        this.workerInfo = new ContainerInfo();
-        LOG.info("{} Start to initialize worker", this);
-
-        this.bsp4Worker = new Bsp4Worker(this.config, this.workerInfo);
+    public synchronized void init(Config config) {
+        try {
+            LOG.info("{} Prepare to init WorkerService", this);
+            // TODO: what will happen if init() called by multiple threads?
+            E.checkArgument(!this.inited, "The %s has been initialized", this);
 
-        /*
-         * Keep the waitMasterInitDone() called before initManagers(),
-         * in order to ensure master init() before worker managers init()
-         */
-        this.masterInfo = this.bsp4Worker.waitMasterInitDone();
+            this.serviceThread = Thread.currentThread();
+            this.registerShutdownHook();
+            this.config = config;
+            this.workerInfo = new ContainerInfo();
 
-        InetSocketAddress address = this.initManagers(this.masterInfo);
-        this.workerInfo.updateAddress(address);
+            LOG.info("{} Start to initialize worker", this);
+            this.bsp4Worker = new Bsp4Worker(this.config, this.workerInfo);
+            /*
+             * Keep the waitMasterInitDone() called before initManagers(),
+             * in order to ensure master init() before worker managers init()
+             */
+            ContainerInfo masterInfo = this.bsp4Worker.waitMasterInitDone();
+            InetSocketAddress address = this.initManagers(masterInfo);
+            this.workerInfo.updateAddress(address);
+            this.loadComputation();
+
+            LOG.info("{} register WorkerService", this);
+            this.bsp4Worker.workerInitDone();
+            this.connectToWorkers();
+
+            this.computeManager = new ComputeManager(this.workerInfo.id(), 
this.context,
+                                                     this.managers);
+
+            this.managers.initedAll(this.config);
+            LOG.info("{} WorkerService initialized", this);
+            this.inited = true;
+        } catch (Exception e) {

Review Comment:
   > don't need to try-catch and just log here
   
   seems without `try-catch` the log won't print if exception throws before it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to