예제 #1
0
  private void readConf(Configuration conf) {
    int selectorThreads = conf.getInt(SELECTOR_THREADS_CONF_KEY, getSelectorThreads());
    int workerThreads = conf.getInt(WORKER_THREADS_CONF_KEY, getWorkerThreads());
    int stopTimeoutVal = conf.getInt(STOP_TIMEOUT_CONF_KEY, getStopTimeoutVal());
    int acceptQueueSizePerThread =
        conf.getInt(ACCEPT_QUEUE_SIZE_PER_THREAD_CONF_KEY, getAcceptQueueSizePerThread());
    AcceptPolicy acceptPolicy =
        AcceptPolicy.valueOf(
            conf.get(ACCEPT_POLICY_CONF_KEY, getAcceptPolicy().toString()).toUpperCase());

    super.selectorThreads(selectorThreads)
        .workerThreads(workerThreads)
        .stopTimeoutVal(stopTimeoutVal)
        .acceptQueueSizePerThread(acceptQueueSizePerThread)
        .acceptPolicy(acceptPolicy);

    LOG.info(
        "Read configuration selectorThreads:"
            + selectorThreads
            + " workerThreads:"
            + workerThreads
            + " stopTimeoutVal:"
            + stopTimeoutVal
            + "sec"
            + " acceptQueueSizePerThread:"
            + acceptQueueSizePerThread
            + " acceptPolicy:"
            + acceptPolicy);
  }
예제 #2
0
  public static TServer factory(ProcessorFactory processorFactory) {

    loadProperties();

    try {
      validate();
    } catch (Exception e) {
      e.printStackTrace();
    }

    TProtocolFactory tProtocolFactory = getTProtocolFactory();

    TTransportFactory tTransportFactory = getTTransportFactory();

    TServer serverEngine = null;

    TMultiplexedProcessor tProcessor = processorFactory.getProcessor();

    if (server_type.equals("nonblocking") || server_type.equals("threaded-selector")) {
      // Nonblocking servers
      TNonblockingServerSocket tNonblockingServerSocket = null;
      try {
        tNonblockingServerSocket =
            new TNonblockingServerSocket(
                new TNonblockingServerSocket.NonblockingAbstractServerSocketArgs().port(port));
      } catch (TTransportException e) {
        e.printStackTrace();
      }

      if (server_type.equals("nonblocking")) {
        // Nonblocking Server
        TNonblockingServer.Args tNonblockingServerArgs =
            new TNonblockingServer.Args(tNonblockingServerSocket);
        tNonblockingServerArgs.processor(tProcessor);
        tNonblockingServerArgs.protocolFactory(tProtocolFactory);
        tNonblockingServerArgs.transportFactory(tTransportFactory);

        serverEngine = new TNonblockingServer(tNonblockingServerArgs);
      } else { // server_type.equals("threaded-selector")
        // ThreadedSelector Server
        TThreadedSelectorServer.Args tThreadedSelectorServerArgs =
            new TThreadedSelectorServer.Args(tNonblockingServerSocket);
        tThreadedSelectorServerArgs.processor(tProcessor);
        tThreadedSelectorServerArgs.protocolFactory(tProtocolFactory);
        tThreadedSelectorServerArgs.transportFactory(tTransportFactory);

        serverEngine = new TThreadedSelectorServer(tThreadedSelectorServerArgs);
      }
    } else {
      // Blocking servers

      // SSL socket
      TServerSocket tServerSocket = null;
      if (ssl) {
        try {
          tServerSocket = TSSLTransportFactory.getServerSocket(port, 0);
        } catch (TTransportException e) {
          e.printStackTrace();
        }
      } else {
        try {
          tServerSocket =
              new TServerSocket(new TServerSocket.ServerSocketTransportArgs().port(port));
        } catch (TTransportException e) {
          e.printStackTrace();
        }
      }

      if (server_type.equals("simple")) {
        // Simple Server
        TServer.Args tServerArgs = new TServer.Args(tServerSocket);
        tServerArgs.processor(tProcessor);
        tServerArgs.protocolFactory(tProtocolFactory);
        tServerArgs.transportFactory(tTransportFactory);

        serverEngine = new TSimpleServer(tServerArgs);
      } else { // server_type.equals("threadpool")
        // ThreadPool Server
        TThreadPoolServer.Args tThreadPoolServerArgs = new TThreadPoolServer.Args(tServerSocket);
        tThreadPoolServerArgs.processor(tProcessor);
        tThreadPoolServerArgs.protocolFactory(tProtocolFactory);
        tThreadPoolServerArgs.transportFactory(tTransportFactory);

        serverEngine = new TThreadPoolServer(tThreadPoolServerArgs);
      }
    }
    // Set server event handler
    serverEngine.setServerEventHandler(new TServerEventHandlerImpl());

    return serverEngine;
  }