1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.gateway.ftp.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.ftp.core.config.FtpConfiguration;
28 import org.waarp.ftp.core.utils.FtpChannelUtils;
29 import org.waarp.gateway.ftp.ExecGatewayFtpServer;
30 import org.waarp.gateway.ftp.config.FileBasedConfiguration;
31
32
33
34
35 public class FtpEngine extends EngineAbstract {
36
37
38
39 private static final WaarpLogger logger =
40 WaarpLoggerFactory.getLogger(FtpEngine.class);
41
42 public static final WaarpFuture closeFuture = new WaarpFuture(true);
43
44 public static final String CONFIGFILE = "org.waarp.gateway.ftp.config.file";
45
46 public static final String R66CONFIGFILE = "org.waarp.r66.config.file";
47
48 @Override
49 public final void run() {
50 final String ftpfile = SystemPropertyUtil.get(CONFIGFILE);
51 final String r66file = SystemPropertyUtil.get(R66CONFIGFILE);
52 if (ftpfile == null) {
53 logger.error("Cannot find " + CONFIGFILE + " parameter");
54 shutdown();
55 return;
56 }
57 try {
58 if (!ExecGatewayFtpServer.initialize(ftpfile, r66file)) {
59 logger.error("Cannot start Gateway FTP");
60 shutdown();
61 return;
62 }
63 } catch (final Throwable e) {
64 logger.error("Cannot start Gateway FTP", e);
65 shutdown();
66 return;
67 }
68 logger.warn("Service started with " + ftpfile);
69 }
70
71 private static void exit(final FtpConfiguration configuration) {
72 final FtpChannelUtils util = new FtpChannelUtils(configuration);
73 util.run();
74 }
75
76 @Override
77 public final void shutdown() {
78 exit(FileBasedConfiguration.fileBasedConfiguration);
79 closeFuture.setSuccess();
80 logger.info("Service stopped");
81 }
82
83 @Override
84 public final boolean isShutdown() {
85 return closeFuture.isDone();
86 }
87
88 @Override
89 public final boolean waitShutdown() {
90 closeFuture.awaitOrInterruptible();
91 return closeFuture.isSuccess();
92 }
93 }