|
|
@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ContainerHelper { |
|
|
|
public class ContainerHelper { |
|
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ContainerHelper.class); |
|
|
|
private static Logger LOGGER = LoggerFactory.getLogger(ContainerHelper.class); |
|
|
|
|
|
|
|
|
|
|
|
private static volatile boolean running = true; |
|
|
|
private static volatile boolean running = true; |
|
|
|
|
|
|
|
|
|
|
@ -25,7 +25,7 @@ public class ContainerHelper { |
|
|
|
|
|
|
|
|
|
|
|
// 启动所有容器
|
|
|
|
// 启动所有容器
|
|
|
|
startContainers(); |
|
|
|
startContainers(); |
|
|
|
|
|
|
|
//在JVM销毁前执行的一个线程
|
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -53,20 +53,20 @@ public class ContainerHelper { |
|
|
|
|
|
|
|
|
|
|
|
private static void startContainers() { |
|
|
|
private static void startContainers() { |
|
|
|
for (Container container : cachedContainers) { |
|
|
|
for (Container container : cachedContainers) { |
|
|
|
logger.info("starting container [{}]", container.getClass().getName()); |
|
|
|
LOGGER.info("starting container [{}]", container.getClass().getName()); |
|
|
|
container.start(); |
|
|
|
container.start(); |
|
|
|
logger.info("container [{}] started", container.getClass().getName()); |
|
|
|
LOGGER.info("container [{}] started", container.getClass().getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void stopContainers() { |
|
|
|
private static void stopContainers() { |
|
|
|
for (Container container : cachedContainers) { |
|
|
|
for (Container container : cachedContainers) { |
|
|
|
logger.info("stopping container [{}]", container.getClass().getName()); |
|
|
|
LOGGER.info("stopping container [{}]", container.getClass().getName()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
container.stop(); |
|
|
|
container.stop(); |
|
|
|
logger.info("container [{}] stopped", container.getClass().getName()); |
|
|
|
LOGGER.info("container [{}] stopped", container.getClass().getName()); |
|
|
|
} catch (Exception ex) { |
|
|
|
} catch (Exception ex) { |
|
|
|
logger.warn("container stopped with error", ex); |
|
|
|
LOGGER.warn("container stopped with error", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|