1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.service;
21
22 import org.waarp.common.future.WaarpFuture;
23 import org.waarp.common.logging.WaarpLogger;
24 import org.waarp.common.logging.WaarpLoggerFactory;
25 import org.waarp.common.service.EngineAbstract;
26 import org.waarp.common.utility.SystemPropertyUtil;
27 import org.waarp.openr66.protocol.configuration.Configuration;
28 import org.waarp.openr66.protocol.configuration.R66SystemProperties;
29 import org.waarp.openr66.protocol.utils.ChannelUtils;
30 import org.waarp.openr66.server.R66Server;
31
32
33
34
35 public class R66Engine extends EngineAbstract {
36
37
38
39 private static final WaarpLogger logger =
40 WaarpLoggerFactory.getLogger(R66Engine.class);
41
42 static final WaarpFuture closeFuture = new WaarpFuture(true);
43
44 @Override
45 public void run() {
46 final String config =
47 SystemPropertyUtil.get(R66SystemProperties.OPENR66_CONFIGFILE);
48 if (config == null) {
49 logger.error("Cannot find " + R66SystemProperties.OPENR66_CONFIGFILE +
50 " parameter");
51 closeFuture.cancel();
52 shutdown();
53 return;
54 }
55 Configuration.configuration.getShutdownConfiguration().serviceFuture =
56 closeFuture;
57 try {
58 if (!R66Server.initialize(config)) {
59 throw new Exception("Initialization in error");
60 }
61 } catch (final Throwable e) {
62 logger.error("Cannot start R66", e);
63 closeFuture.cancel();
64 shutdown();
65 return;
66 }
67 logger.warn("Service started with " + config);
68 }
69
70 @Override
71 public final void shutdown() {
72 logger.warn("Shutdown");
73 ChannelUtils.startShutdown();
74 closeFuture.setSuccess();
75 logger.info("Service stopped");
76 }
77
78 @Override
79 public final boolean isShutdown() {
80 return closeFuture.isDone();
81 }
82
83 @Override
84 public final boolean waitShutdown() {
85 closeFuture.awaitOrInterruptible();
86 logger.info("Shutdown on going: {}", closeFuture.isSuccess());
87 return closeFuture.isSuccess();
88 }
89 }