@Override
  public void start() {
    try {
      log.info("ThriftServer starting....");
      TServerSocket socket = new TServerSocket(Const.THRIFT_PORT);

      NewsServiceHandler newsServiceHandler =
          (NewsServiceHandler) SpringContextUtil.getBean("newsServiceHandler");
      final kevin.news.thrift.NewsService.Processor processor =
          new kevin.news.thrift.NewsService.Processor(newsServiceHandler);

      TThreadPoolServer.Args args = new TThreadPoolServer.Args(socket);
      args.protocolFactory(new TBinaryProtocol.Factory(true, true));
      //            args.transportFactory(new TFramedTransport.Factory());
      args.processor(processor);
      args.minWorkerThreads = Const.work_thread_num;
      args.maxWorkerThreads = Const.work_thread_num;

      log.info("ThriftServer starting, listening on " + Const.THRIFT_PORT);
      TThreadPoolServer server = new TThreadPoolServer(args);

      server.serve();

    } catch (Exception e) {
      log.error("thrift server 启动出错", e);
    }
  }
Exemplo n.º 2
0
  /**
   * Runs the block worker. The thread calling this will be blocked until the thrift server shuts
   * down.
   */
  public void process() {
    getExecutorService()
        .submit(
            new HeartbeatThread(
                HeartbeatContext.WORKER_BLOCK_SYNC,
                mBlockMasterSync,
                WorkerContext.getConf().getInt(Constants.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS)));

    // Start the pinlist syncer to perform the periodical fetching
    getExecutorService()
        .submit(
            new HeartbeatThread(
                HeartbeatContext.WORKER_PIN_LIST_SYNC,
                mPinListSync,
                WorkerContext.getConf().getInt(Constants.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS)));

    // Start the session cleanup checker to perform the periodical checking
    getExecutorService().submit(mSessionCleanerThread);

    // Start the space reserver
    if (mSpaceReserver != null) {
      getExecutorService().submit(mSpaceReserver);
    }

    mThriftServer.serve();
  }
Exemplo n.º 3
0
  //    @Test
  public void testThreadServerStart() {
    try {
      TServerTransport serverTransport = serverTransport = new TServerSocket(port);

      TThreadPoolServer.Args processor =
          new TThreadPoolServer.Args(serverTransport)
              .inputTransportFactory(new TFramedTransport.Factory())
              .outputTransportFactory(new TFramedTransport.Factory())
              .protocolFactory(new TCompactProtocol.Factory())
              .processor(new PingPongService.Processor<>(pingPongService));
      //            processor.maxWorkerThreads = 20;
      TThreadPoolServer server = new TThreadPoolServer(processor);

      log.info("Starting the server...");
      server.serve();
    } catch (TTransportException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  @Test
  public void echoStart() {
    try {
      TServerTransport serverTransport = new TServerSocket(port);

      TThreadPoolServer.Args processor =
          new TThreadPoolServer.Args(serverTransport)
              .inputTransportFactory(new TFramedTransport.Factory())
              .outputTransportFactory(new TFramedTransport.Factory())
              .protocolFactory(new TCompactProtocol.Factory())
              .processor(new TestThriftService.Processor<>(new TestThriftServiceHandler()));
      //            processor.maxWorkerThreads = 20;
      TThreadPoolServer server = new TThreadPoolServer(processor);

      System.out.println("Starting the server...");
      server.serve();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 5
0
  /**
   * Starts the Tachyon worker server.
   *
   * @throws Exception if the workers fail to start
   */
  public void start() throws Exception {
    // NOTE: the order to start different services is sensitive. If you change it, do it cautiously.

    // Start serving metrics system, this will not block
    mWorkerMetricsSystem.start();

    // Start serving the web server, this will not block
    // Requirement: metrics system started so we could add the metrics servlet to the web server
    // Consequence: when starting webserver, the webport will be updated.
    mWebServer.addHandler(mWorkerMetricsSystem.getServletHandler());
    mWebServer.startWebServer();

    // Set updated net address for this worker in context
    // Requirement: RPC, web, and dataserver ports are updated
    // Consequence: create a NetAddress object and set it into WorkerContext
    mNetAddress =
        new NetAddress(
            NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, mTachyonConf),
            mTachyonConf.getInt(Constants.WORKER_RPC_PORT),
            getDataLocalPort(),
            mTachyonConf.getInt(Constants.WORKER_WEB_PORT));
    WorkerContext.setWorkerNetAddress(mNetAddress);

    // Start each worker
    // Requirement: NetAddress set in WorkerContext, so block worker can initialize BlockMasterSync
    // Consequence: worker id is granted
    startWorkers();
    LOG.info("Started worker with id {}", WorkerIdRegistry.getWorkerId());

    mIsServingRPC = true;

    // Start serving RPC, this will block
    LOG.info("Tachyon Worker version {} started @ {}", Version.VERSION, mWorkerAddress);
    mThriftServer.serve();
    LOG.info("Tachyon Worker version {} ended @ {}", Version.VERSION, mWorkerAddress);
  }
 public void run() {
   server.serve();
 }
Exemplo n.º 7
0
 /** hook for JSVC */
 public void start() {
   logger.info("Cassandra starting up...");
   serverEngine.serve();
 }