Package org.apache.thrift.server

Examples of org.apache.thrift.server.TServer


          .transportFactory(transFactory)
          .protocolFactory(new TBinaryProtocol.Factory())
          .minWorkerThreads(minWorkerThreads)
          .maxWorkerThreads(maxWorkerThreads);

      TServer tServer = new TThreadPoolServer(args);
      HMSHandler.LOG.info("Started the new metaserver on port [" + port
          + "]...");
      HMSHandler.LOG.info("Options.minWorkerThreads = "
          + minWorkerThreads);
      HMSHandler.LOG.info("Options.maxWorkerThreads = "
          + maxWorkerThreads);
      HMSHandler.LOG.info("TCP keepalive = " + tcpKeepAlive);

      if (startLock != null) {
        signalOtherThreadsToStart(tServer, startLock, startCondition, startedServing);
      }
      tServer.serve();
    } catch (Throwable x) {
      x.printStackTrace();
      HMSHandler.LOG.error(StringUtils.stringifyException(x));
      throw x;
    }
View Full Code Here


   * Start up the Thrift2 server.
   *
   * @param args
   */
  public static void main(String[] args) throws Exception {
    TServer server = null;
    Options options = getOptions();
    try {
      Configuration conf = HBaseConfiguration.create();
      CommandLine cmd = parseArguments(conf, options, args);

      /**
       * This is to please both bin/hbase and bin/hbase-daemon. hbase-daemon provides "start" and "stop" arguments hbase
       * should print the help if no argument is provided
       */
      List<?> argList = cmd.getArgList();
      if (cmd.hasOption("help") || !argList.contains("start") || argList.contains("stop")) {
        printUsage();
        System.exit(1);
      }

      // Get port to bind to
      int listenPort = 0;
      try {
        listenPort = Integer.parseInt(cmd.getOptionValue("port", DEFAULT_LISTEN_PORT));
      } catch (NumberFormatException e) {
        throw new RuntimeException("Could not parse the value provided for the port option", e);
      }

      boolean nonblocking = cmd.hasOption("nonblocking");
      boolean hsha = cmd.hasOption("hsha");

      ThriftMetrics metrics = new ThriftMetrics(
          listenPort, conf, THBaseService.Iface.class);

      String implType = "threadpool";
      if (nonblocking) {
        implType = "nonblocking";
      } else if (hsha) {
        implType = "hsha";
      }

      conf.set("hbase.regionserver.thrift.server.type", implType);
      conf.setInt("hbase.regionserver.thrift.port", listenPort);
      registerFilters(conf);

      // Construct correct ProtocolFactory
      boolean compact = cmd.hasOption("compact") ||
        conf.getBoolean("hbase.regionserver.thrift.compact", false);
      TProtocolFactory protocolFactory = getTProtocolFactory(compact);
      THBaseService.Iface handler =
          ThriftHBaseServiceHandler.newInstance(conf, metrics);
      THBaseService.Processor processor = new THBaseService.Processor(handler);
      conf.setBoolean("hbase.regionserver.thrift.compact", compact);

      boolean framed = cmd.hasOption("framed") ||
        conf.getBoolean("hbase.regionserver.thrift.framed", false) || nonblocking || hsha;
      TTransportFactory transportFactory = getTTransportFactory(framed);
      conf.setBoolean("hbase.regionserver.thrift.framed", framed);

      // TODO: Remove once HBASE-2155 is resolved
      if (cmd.hasOption("bind") && (nonblocking || hsha)) {
        log.error("The Nonblocking and HsHaServer servers don't support IP address binding at the moment." +
            " See https://issues.apache.org/jira/browse/HBASE-2155 for details.");
        printUsage();
        System.exit(1);
      }

      // check for user-defined info server port setting, if so override the conf
      try {
        if (cmd.hasOption("infoport")) {
          String val = cmd.getOptionValue("infoport");
          conf.setInt("hbase.thrift.info.port", Integer.valueOf(val));
          log.debug("Web UI port set to " + val);
        }
      } catch (NumberFormatException e) {
        log.error("Could not parse the value provided for the infoport option", e);
        printUsage();
        System.exit(1);
      }

      // Put up info server.
      int port = conf.getInt("hbase.thrift.info.port", 9095);
      if (port >= 0) {
        conf.setLong("startcode", System.currentTimeMillis());
        String a = conf.get("hbase.thrift.info.bindAddress", "0.0.0.0");
        InfoServer infoServer = new InfoServer("thrift", a, port, false, conf);
        infoServer.setAttribute("hbase.conf", conf);
        infoServer.start();
      }

      InetSocketAddress inetSocketAddress = bindToPort(cmd.getOptionValue("bind"), listenPort);

      if (nonblocking) {
        server = getTNonBlockingServer(protocolFactory, processor, transportFactory, inetSocketAddress);
      } else if (hsha) {
        server = getTHsHaServer(protocolFactory, processor, transportFactory, inetSocketAddress, metrics);
      } else {
        server = getTThreadPoolServer(protocolFactory, processor, transportFactory, inetSocketAddress);
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      printUsage();
      System.exit(1);
    }
    server.serve();
  }
View Full Code Here


      FawnKVCltHandler handler = new FawnKVCltHandler(this);
      FawnKVApp.Processor processor = new FawnKVApp.Processor(handler);
      TServerTransport serverTransport = new TServerSocket(myPort);
      TServer server = new TSimpleServer(processor, serverTransport);

      ServerThread st = new ServerThread(server);
      st.start();

      Thread.sleep(1000);
View Full Code Here

    TrecSearch.Processor<TrecSearch.Iface> searchProcessor =
        new TrecSearch.Processor<TrecSearch.Iface>(new TrecSearchHandler(index, credentials));
   
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverSocket);
    serverArgs.maxWorkerThreads(maxThreads);
    TServer thriftServer = new TThreadPoolServer(serverArgs.processor(searchProcessor)
        .protocolFactory(new TBinaryProtocol.Factory()));

    thriftServer.serve();
  }
View Full Code Here

        if (port > 65535)
          port = 1024 + port % (65535 - 1024);
        TServerTransport serverTransport;
        try {
          serverTransport = TServerUtils.openPort(port);
          TServer server = TServerUtils.startTServer(processor, serverTransport, serverName, threadName, -1);
          return new ServerPort(server, port);
        } catch (IOException ex) {
          if (portHint == 0) {
            throw new RuntimeException(ex);
          }
View Full Code Here

  public static TServer startTServer(TProcessor processor, TServerTransport serverTransport, String serverName, String threadName, int numThreads) {
    TThreadPoolServer.Options options = new TThreadPoolServer.Options();
    if (numThreads > 0)
      options.maxWorkerThreads = numThreads;
    processor = new TServerUtils.TimedProcessor(processor, serverName, threadName);
    final TServer tserver = new TThreadPoolServer(new ClientInfoProcessorFactory(processor), serverTransport, ThriftUtil.transportFactory(),
        ThriftUtil.transportFactory(), ThriftUtil.inputProtocolFactory(), ThriftUtil.outputProtocolFactory(), options);
    Runnable serveTask = new Runnable() {
      public void run() {
        try {
          tserver.serve();
        } catch (Error e) {
          Halt.halt("Unexpected error in TThreadPoolServer " + e + ", halting.");
        }
      }
    };
View Full Code Here

    int port = Integer.parseInt(args[3]);
   
    TServerTransport serverTransport = TServerUtils.openPort(port);
    ThriftClientHandler tch = new ThriftClientHandler();
    TabletClientService.Processor processor = new TabletClientService.Processor(tch);
    @SuppressWarnings("unused")
    TServer server = TServerUtils.startTServer(processor, serverTransport, "NullTServer", "null tserver", -1);
   
    InetSocketAddress addr = new InetSocketAddress(InetAddress.getLocalHost(), port);
   
    // modify !METADATA
View Full Code Here

          .transportFactory(transFactory)
          .protocolFactory(new TBinaryProtocol.Factory())
          .minWorkerThreads(minWorkerThreads)
          .maxWorkerThreads(maxWorkerThreads);

      TServer tServer = new TThreadPoolServer(args);
      HMSHandler.LOG.info("Started the new metaserver on port [" + port
          + "]...");
      HMSHandler.LOG.info("Options.minWorkerThreads = "
          + minWorkerThreads);
      HMSHandler.LOG.info("Options.maxWorkerThreads = "
          + maxWorkerThreads);
      HMSHandler.LOG.info("TCP keepalive = " + tcpKeepAlive);
      tServer.serve();
    } catch (Throwable x) {
      x.printStackTrace();
      HMSHandler.LOG.error(StringUtils.stringifyException(x));
      throw x;
    }
View Full Code Here

    Tracer.getInstance().addReceiver(tracer);
   
    ServerSocket socket = new ServerSocket(0);
    TServerSocket transport = new TServerSocket(socket);
    transport.listen();
    final TServer tserver = new TThreadPoolServer(new TestService.Processor(TraceWrap.service(new Service())), transport);
    Thread t = new Thread() {
      public void run() {
        tserver.serve();
      }
    };
    t.start();
    TTransport clientTransport = new TSocket(new Socket("localhost", socket.getLocalPort()));
    TestService.Iface client = new TestService.Client(new TBinaryProtocol(clientTransport), new TBinaryProtocol(clientTransport));
    client = TraceWrap.client(client);
    assertFalse(client.checkTrace(null, "test"));
   
    Span start = Trace.on("start");
    assertTrue(client.checkTrace(null, "my test"));
    start.stop();
   
    assertNotNull(tracer.traces.get(start.traceId()));
    String traces[] = {"my test", "checkTrace", "client:checkTrace", "start"};
    assertTrue(tracer.traces.get(start.traceId()).size() == traces.length);
    for (int i = 0; i < traces.length; i++)
      assertEquals(traces[i], tracer.traces.get(start.traceId()).get(i).description);
   
    tserver.stop();
    t.join(100);
  }
View Full Code Here

     
      Options opt = new Options();
      opt.maxWorkerThreads = threadCount;
     
      //Server
      TServer server = new THsHaServer(processor,serverSocket);
     
      //Serve
      server.serve();
     
    }catch(Exception e){
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.thrift.server.TServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.