rpuch commented on code in PR #784:
URL: https://github.com/apache/ignite-3/pull/784#discussion_r855042696


##########
modules/runner/src/main/java/org/apache/ignite/internal/app/LifecycleManager.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.app;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.util.ReverseIterator;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.lang.NodeStoppingException;
+
+/**
+ * Class for managing the lifecycle of Ignite components.
+ */
+class LifecycleManager {
+    private static final IgniteLogger LOG = 
IgniteLogger.forClass(LifecycleManager.class);
+
+    /** Ignite node name. */
+    private final String nodeName;
+
+    /** Node status. Needed for handling stop a starting node. */
+    private final AtomicReference<Status> status = new 
AtomicReference<>(Status.STARTING);
+
+    /**
+     * List of started Ignite components.
+     *
+     * <p>Multi-threaded access is guarded by {@code this}.
+     */
+    private final List<IgniteComponent> startedComponents = new ArrayList<>();
+
+    /** Node state. */
+    private enum Status {
+        STARTING,
+        STARTED,
+        STOPPING
+    }
+
+    LifecycleManager(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    /**
+     * Starts a given components unless the node is in {@link Status#STOPPING} 
state, in which case a {@link NodeStoppingException} will be
+     * thrown.
+     *
+     * @param component Ignite component to start.
+     * @throws NodeStoppingException If node stopping intention was detected.
+     */
+    synchronized void startComponent(IgniteComponent component) throws 
NodeStoppingException {
+        if (status.get() == Status.STOPPING) {
+            throw new NodeStoppingException("Node=[" + nodeName + "] was 
stopped.");
+        }
+
+        startedComponents.add(component);
+
+        component.start();
+    }
+
+    /**
+     * Similar to {@link #startComponent} but allows to start multiple 
components at once.
+     *
+     * @param components Ignite components to start.
+     * @throws NodeStoppingException If node stopping intention was detected.
+     */
+    synchronized void startComponents(IgniteComponent... components) throws 
NodeStoppingException {
+        for (IgniteComponent component : components) {
+            startComponent(component);
+        }
+    }
+
+    /**
+     * Callback that should be called after all components, that comprise an 
Ignite node, has been started. After this method completes,

Review Comment:
   has been started -> have been started



-- 
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]

Reply via email to