Пример #1
0
  public void init(String host, int port) throws Exception {
    logger.info("Starting Server bound to '" + host + ":" + port + "'");

    String memory = Configurations.get("refine.memory");
    if (memory != null) {
      logger.info(
          "refine.memory size: " + memory + " JVM Max heap: " + Runtime.getRuntime().maxMemory());
    }

    int maxThreads = Configurations.getInteger("refine.queue.size", 30);
    int maxQueue = Configurations.getInteger("refine.queue.max_size", 300);
    long keepAliveTime = Configurations.getInteger("refine.queue.idle_time", 60);

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue);

    threadPool =
        new ThreadPoolExecutor(maxThreads, maxQueue, keepAliveTime, TimeUnit.SECONDS, queue);

    this.setThreadPool(new ThreadPoolExecutorAdapter(threadPool));

    Connector connector = new SocketConnector();
    connector.setPort(port);
    connector.setHost(host);
    connector.setMaxIdleTime(Configurations.getInteger("refine.connection.max_idle_time", 60000));
    connector.setStatsOn(false);
    this.addConnector(connector);

    File webapp = new File(Configurations.get("refine.webapp", "main/webapp"));

    if (!isWebapp(webapp)) {
      webapp = new File("main/webapp");
      if (!isWebapp(webapp)) {
        webapp = new File("webapp");
        if (!isWebapp(webapp)) {
          logger.warn(
              "Warning: Failed to find web application at '" + webapp.getAbsolutePath() + "'");
          System.exit(-1);
        }
      }
    }

    final String contextPath = Configurations.get("refine.context_path", "/");

    logger.info(
        "Initializing context: '" + contextPath + "' from '" + webapp.getAbsolutePath() + "'");
    WebAppContext context = new WebAppContext(webapp.getAbsolutePath(), contextPath);
    context.setMaxFormContentSize(1048576);

    this.setHandler(context);
    this.setStopAtShutdown(true);
    this.setSendServerVersion(true);

    // Enable context autoreloading
    if (Configurations.getBoolean("refine.autoreload", false)) {
      scanForUpdates(webapp, context);
    }

    // start the server
    try {
      this.start();
    } catch (BindException e) {
      logger.error(
          "Failed to start server - is there another copy running already on this port/address?");
      throw e;
    }

    configure(context);
  }