View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.openr66.proxy;
21  
22  import org.waarp.common.logging.SysErrLogger;
23  import org.waarp.common.logging.WaarpLogger;
24  import org.waarp.common.logging.WaarpLoggerFactory;
25  import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
26  import org.waarp.common.utility.WaarpShutdownHook;
27  import org.waarp.common.utility.WaarpSystemUtil;
28  import org.waarp.openr66.proxy.configuration.ConfigurationProxyR66;
29  import org.waarp.openr66.proxy.configuration.FileBasedConfiguration;
30  
31  import static org.waarp.openr66.protocol.configuration.Configuration.*;
32  
33  /**
34   *
35   */
36  public class R66Proxy {
37    private static WaarpLogger logger;
38  
39    private R66Proxy() {
40    }
41  
42    /**
43     * @param args
44     */
45    public static void main(final String[] args) {
46      WaarpLoggerFactory.setDefaultFactoryIfNotSame(
47          new WaarpSlf4JLoggerFactory(null));
48      logger = WaarpLoggerFactory.getLogger(R66Proxy.class);
49      if (args.length < 1) {
50        logger.error("Needs the configuration file as first argument");
51        return;
52      }
53      configuration = new ConfigurationProxyR66();
54      if (initialize(args[0])) {
55        logger.warn("Proxy OpenR66 starts for " + configuration.getHostId());
56        SysErrLogger.FAKE_LOGGER.syserr(
57            "Proxy OpenR66 starts for " + configuration.getHostId());
58      } else {
59        logger.error(
60            "Cannot start Proxy OpenR66 for " + configuration.getHostId());
61        SysErrLogger.FAKE_LOGGER.syserr(
62            "Cannot start Proxy OpenR66 for " + configuration.getHostId());
63        WaarpSystemUtil.systemExit(1);
64      }
65    }
66  
67    public static boolean initialize(final String config) {
68      if (logger == null) {
69        logger = WaarpLoggerFactory.getLogger(R66Proxy.class);
70      }
71      if (!FileBasedConfiguration.setConfigurationProxyFromXml(configuration,
72                                                               config)) {
73        logger.error("Needs a correct configuration file as first argument");
74        return false;
75      }
76      try {
77        configuration.serverStartup();
78      } catch (final Throwable e) {
79        logger.error("Startup of Proxy is in error", e);
80        WaarpShutdownHook.terminate(false);
81        return false;
82      }
83      return true;
84    }
85  
86  }