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