org.apache.thrift.server.THsHaServer Java Examples

The following examples show how to use org.apache.thrift.server.THsHaServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsyncServer.java    From ThriftBook with Apache License 2.0 7 votes vote down vote up
public static void main(String[] args)
        throws TTransportException, IOException, InterruptedException {

    FloorBroker floor = new FloorBroker();
    (new Thread(floor)).start();

    TProcessor proc = new TradeReporting.TradeHistory.AsyncProcessor(
        new AsyncTradeHistoryHandler(floor.getQ()));
    TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
    TServer server = 
        new THsHaServer(new THsHaServer.Args(trans_svr)
            .processor(proc)
            .protocolFactory(new TBinaryProtocol.Factory())
            .minWorkerThreads(4)
            .maxWorkerThreads(4));
    System.out.println("[Server] listening of port 9090");
    server.serve();
}
 
Example #2
Source File: ThriftServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected TServer getTHsHaServer(TNonblockingServerTransport serverTransport,
    TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory,
    InetSocketAddress inetSocketAddress) {
  LOG.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
  THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
  int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY,
      TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS);
  CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics);
  int workerThread = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY,
      serverArgs.getMaxWorkerThreads());
  ExecutorService executorService = createExecutor(
      callQueue, workerThread, workerThread);
  serverArgs.executorService(executorService).processor(processor)
      .transportFactory(transportFactory).protocolFactory(protocolFactory);
  return new THsHaServer(serverArgs);
}
 
Example #3
Source File: AsyncEchoTestServer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static AsyncEchoTestServer<THsHaServer> halfSyncHalfAsyncServer(final TestEnvironment environment)
        throws TTransportException {
    THsHaServer server = new THsHaServer(new THsHaServer.Args(new TNonblockingServerSocket(
            environment.getPort())).processor(getAsyncProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new AsyncEchoTestServer<THsHaServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
 
Example #4
Source File: SyncEchoTestServer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static SyncEchoTestServer<THsHaServer> halfSyncHalfAsyncServer(final TestEnvironment environment)
        throws TTransportException {
    THsHaServer server = new THsHaServer(new THsHaServer.Args(new TNonblockingServerSocket(
            environment.getPort())).processor(getProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<THsHaServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
 
Example #5
Source File: ScribeSource.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
public void run() {
  try {
    Scribe.Processor processor = new Scribe.Processor(new Receiver());
    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    THsHaServer.Args args = new THsHaServer.Args(transport);
    
    args.workerThreads(workers);
    args.processor(processor);
    args.transportFactory(new TFramedTransport.Factory());
    args.protocolFactory(new TBinaryProtocol.Factory(false, false));

    server = new THsHaServer(args);

    LOG.info("Starting Scribe Source on port " + port);

    server.serve();
  } catch (Exception e) {
    LOG.warn("Scribe failed", e);
  }
}
 
Example #6
Source File: SuroServer4Test.java    From suro with Apache License 2.0 6 votes vote down vote up
public  void start() throws Exception {
    transport = new TNonblockingServerSocket(port);
    processor =  new SuroServer.Processor(this);

    THsHaServer.Args serverArgs = new THsHaServer.Args(transport);
    serverArgs.processor(processor);
    serverArgs.workerThreads(2);

    server = new THsHaServer(serverArgs);
    System.out.println("Server started on port:" + port);

    Thread t = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };
    t.start();

    Field serverSocketField = TNonblockingServerSocket.class.getDeclaredField("serverSocket_");
    serverSocketField.setAccessible(true);
    ServerSocket serverSocket = (ServerSocket) serverSocketField.get(transport);
    port = serverSocket.getLocalPort();
}
 
Example #7
Source File: Drpc.java    From jstorm with Apache License 2.0 6 votes vote down vote up
private THsHaServer initHandlerServer(Map conf, final Drpc service) throws Exception {
    int port = JStormUtils.parseInt(conf.get(Config.DRPC_PORT));
    int workerThreadNum = JStormUtils.parseInt(conf.get(Config.DRPC_WORKER_THREADS));
    int queueSize = JStormUtils.parseInt(conf.get(Config.DRPC_QUEUE_SIZE));

    LOG.info("Begin to init DRPC handler server at port: " + port);

    TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
    THsHaServer.Args targs = new THsHaServer.Args(socket);
    targs.workerThreads(64);
    targs.protocolFactory(new TBinaryProtocol.Factory());
    targs.processor(new DistributedRPC.Processor<DistributedRPC.Iface>(service));

    ThreadPoolExecutor executor = new ThreadPoolExecutor(
            workerThreadNum, workerThreadNum, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize));
    targs.executorService(executor);

    THsHaServer handlerServer = new THsHaServer(targs);
    LOG.info("Successfully inited DRPC handler server at port: " + port);

    return handlerServer;
}
 
Example #8
Source File: Drpc.java    From jstorm with Apache License 2.0 6 votes vote down vote up
private THsHaServer initInvokeServer(Map conf, final Drpc service) throws Exception {
    int port = JStormUtils.parseInt(conf.get(Config.DRPC_INVOCATIONS_PORT));

    LOG.info("Begin to init DRPC invoke server at port: " + port);

    TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
    THsHaServer.Args targsInvoke = new THsHaServer.Args(socket);
    targsInvoke.workerThreads(64);
    targsInvoke.protocolFactory(new TBinaryProtocol.Factory());
    targsInvoke.processor(new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service));

    THsHaServer invokeServer = new THsHaServer(targsInvoke);

    LOG.info("Successfully inited DRPC invoke server at port: " + port);
    return invokeServer;
}
 
Example #9
Source File: NimbusServer.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private void initThrift(Map conf) throws TTransportException {
    Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT));
    TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port);

    Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE));

    THsHaServer.Args args = new THsHaServer.Args(socket);
    args.workerThreads(ServiceHandler.THREAD_NUM);
    args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1));

    args.processor(new Nimbus.Processor<Iface>(serviceHandler));
    args.maxReadBufferBytes = maxReadBufSize;

    thriftServer = new THsHaServer(args);

    LOG.info("Successfully started nimbus: started Thrift server...");
    thriftServer.serve();
}
 
Example #10
Source File: SimpleTransportPlugin.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int port = type.getPort(storm_conf);
    TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
    int numWorkerThreads = type.getNumThreads(storm_conf);
    int maxBufferSize = type.getMaxBufferSize(storm_conf);
    Integer queueSize = type.getQueueSize(storm_conf);

    THsHaServer.Args server_args =
            new THsHaServer.Args(serverTransport).processor(new SimpleWrapProcessor(processor)).workerThreads(numWorkerThreads)
                    .protocolFactory(new TBinaryProtocol.Factory(false, true, maxBufferSize, -1));

    if (queueSize != null) {
        server_args.executorService(new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize)));
    }

    // construct THsHaServer
    return new THsHaServer(server_args);
}
 
Example #11
Source File: PacketStreamerServer.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
/** 
 * The function to create a thrift Half-Sync and Half-Async Server.
 * @param processor
 */
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
    try {
        TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
        THsHaServer.Args args = new THsHaServer.Args(serverTransport);
        args.processor(processor);
        args.transportFactory(new TFramedTransport.Factory());
        args.protocolFactory(new TBinaryProtocol.Factory(true, true));
        TServer server = new THsHaServer(args);

        log.info("Starting the packetstreamer hsha server on port {} ...", port);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: ThriftTestingSource.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
public ThriftTestingSource(String handlerName, int port) throws Exception {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(new
    InetSocketAddress("0.0.0.0", port));
  ThriftSourceProtocol.Iface handler = null;
  if (handlerName.equals(HandlerType.OK.name())) {
    handler = new ThriftOKHandler();
  } else if (handlerName.equals(HandlerType.FAIL.name())) {
    handler = new ThriftFailHandler();
  } else if (handlerName.equals(HandlerType.ERROR.name())) {
    handler = new ThriftErrorHandler();
  } else if (handlerName.equals(HandlerType.SLOW.name())) {
    handler = new ThriftSlowHandler();
  } else if (handlerName.equals(HandlerType.TIMEOUT.name())) {
    handler = new ThriftTimeoutHandler();
  } else if (handlerName.equals(HandlerType.ALTERNATE.name())) {
    handler = new ThriftAlternateHandler();
  }

  server = new THsHaServer(new THsHaServer.Args
    (serverTransport).processor(
    new ThriftSourceProtocol.Processor(handler)).protocolFactory(
    new TCompactProtocol.Factory()));
  Executors.newSingleThreadExecutor().submit(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  });
}
 
Example #13
Source File: OracleServer.java    From fluo with Apache License 2.0 5 votes vote down vote up
private InetSocketAddress startServer() throws TTransportException {
  Preconditions.checkState(
      curatorFramework != null && curatorFramework.getState() == CuratorFrameworkState.STARTED);

  if (env.getConfiguration().containsKey(FluoConfigurationImpl.ORACLE_PORT_PROP)) {
    port = env.getConfiguration().getInt(FluoConfigurationImpl.ORACLE_PORT_PROP);
    Preconditions.checkArgument(port >= 1 && port <= 65535,
        FluoConfigurationImpl.ORACLE_PORT_PROP + " must be valid port (1-65535)");
  } else {
    port = PortUtils.getRandomFreePort();
  }
  InetSocketAddress addr = new InetSocketAddress(port);

  TNonblockingServerSocket socket = new TNonblockingServerSocket(addr);

  THsHaServer.Args serverArgs = new THsHaServer.Args(socket);
  TProcessor processor = new OracleService.Processor<OracleService.Iface>(this);
  serverArgs.processor(processor);
  serverArgs.maxReadBufferBytes = ORACLE_MAX_READ_BUFFER_BYTES;
  serverArgs.inputProtocolFactory(new TCompactProtocol.Factory());
  serverArgs.outputProtocolFactory(new TCompactProtocol.Factory());
  server = new THsHaServer(serverArgs);

  serverThread = new Thread(server::serve);
  serverThread.setDaemon(true);
  serverThread.start();

  return addr;
}
 
Example #14
Source File: ServerArgsAspect.java    From ikasoa with MIT License 4 votes vote down vote up
public THsHaServer.Args tHsHaServerArgsAspect(THsHaServer.Args args) {
	return args;
}
 
Example #15
Source File: ThriftHalfSyncHalfAsyncServerAsyncIT.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected ThriftEchoTestServer<THsHaServer> createEchoServer(TestEnvironment environment) throws TTransportException {
    return AsyncEchoTestServerFactory.halfSyncHalfAsyncServer(environment);
}
 
Example #16
Source File: ThriftHalfSyncHalfAsyncServerIT.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected ThriftEchoTestServer<THsHaServer> createEchoServer(TestEnvironment environment) throws TTransportException {
    return SyncEchoTestServerFactory.halfSyncHalfAsyncServer(environment);
}