/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed 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 io.gravitee.common.node;

import io.gravitee.common.component.Lifecycle;
import io.gravitee.common.component.LifecycleComponent;
import io.gravitee.common.service.AbstractService;
import io.gravitee.common.util.ListReverser;
import io.gravitee.common.util.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.List;

/**
 * @author David BRASSELY (david.brassely at graviteesource.com)
 * @author GraviteeSource Team
 */
public abstract class AbstractNode extends AbstractService<Node> implements Node, ApplicationContextAware {

    protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    protected ApplicationContext applicationContext;

    @Override
    protected void doStart() throws Exception {
        LOGGER.info("{} is now starting...", name());
        long startTime = System.currentTimeMillis(); // Get the start Time

        List<Class<? extends LifecycleComponent>> components = getLifecycleComponents();
        for(Class<? extends LifecycleComponent> componentClass: components) {
            LOGGER.info("\tStarting component: {}", componentClass.getSimpleName());

            try {
                LifecycleComponent lifecyclecomponent = applicationContext.getBean(componentClass);
                lifecyclecomponent.start();
            } catch (Exception e) {
                LOGGER.error("An error occurs while starting component {}", componentClass.getSimpleName(), e);
                throw e;
            }
        }

        long endTime = System.currentTimeMillis(); // Get the end Time

        LOGGER.info("{} [id: {} - version: {}] started in {} ms.", name(), id(), Version.RUNTIME_VERSION, (endTime - startTime));
    }

    @Override
    protected void doStop() throws Exception {
        LOGGER.info("{} is stopping", name());

        ListReverser<Class<? extends LifecycleComponent>> components =
                new ListReverser<>(getLifecycleComponents());
        for(Class<? extends LifecycleComponent> componentClass: components) {
            try {
                LifecycleComponent lifecyclecomponent = applicationContext.getBean(componentClass);
                if (lifecyclecomponent.lifecycleState() == Lifecycle.State.STARTED) {
                    LOGGER.info("\tStopping component: {}", componentClass.getSimpleName());
                    lifecyclecomponent.stop();
                }
            } catch (Exception e) {
                LOGGER.error("An error occurs while stopping component {}", componentClass.getSimpleName(), e);
            }
        }

        LOGGER.info("{} stopped", name());
    }

    public abstract String name();

    protected abstract List<Class<? extends LifecycleComponent>> getLifecycleComponents();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}

@@ -1115,24 +1115,71 @@
 textAware;%0A%0A
+import java.lang.management.ManagementFactory;%0A
 import java.
@@ -2409,24 +2409,198 @@
 e end Time%0A%0A
+        String processId = ManagementFactory.getRuntimeMXBean().getName();%0A        if (processId.contains(%22@%22)) %7B%0A            processId = processId.split(%22@%22)%5B0%5D;%0A        %7D%0A%0A
         LOGG
@@ -2615,25 +2615,22 @@
 %22%7B%7D 
-%5B
 id
-: %7B%7D -
+%5B%7B%7D%5D
  version
 : %7B%7D
@@ -2625,18 +2625,52 @@
  version
-: 
+%5B%7B%7D%5D pid%5B%7B%7D%5D build%5B%7B%7D#%7B%7D%5D jvm%5B%7B%7D/%7B%7D/
 %7B%7D%5D star
@@ -2698,16 +2698,32 @@
 ), id(),
+%0A               
  Version
@@ -2738,17 +2738,317 @@
 _VERSION
-,
+.MAJOR_VERSION, processId, Version.RUNTIME_VERSION.BUILD_NUMBER,%0A                Version.RUNTIME_VERSION.REVISION, ManagementFactory.getRuntimeMXBean().getVmVendor(),%0A                ManagementFactory.getRuntimeMXBean().getVmName(), ManagementFactory.getRuntimeMXBean().getVmVersion(),%0A               
  (endTim

Add more system and version information when node is starting