Java Code Examples for org.apache.thrift.server.TThreadPoolServer#Args

The following examples show how to use org.apache.thrift.server.TThreadPoolServer#Args . 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: DKSearchService.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *  线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
 */
public void startTThreadPoolServer() {
    try {
        System.out.println("UserInfoServiceDemo TThreadPoolServer start ....");
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) );
        processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl()  ) );
        processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) );
        //TProcessor tprocessor = new UserInfoService.Processor<UserInfoService.Iface>(new UserInfoServiceImpl());
        TServerSocket serverTransport = new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")));
        TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
        ttpsArgs.processor(processor);
        ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
        // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
        TServer server = new TThreadPoolServer(ttpsArgs);
        server.serve();
    } catch (Exception e) {
        System.out.println("Server start error!!!");
        e.printStackTrace();

    }

}
 
Example 2
Source File: HiveTableBaseTest.java    From iceberg with Apache License 2.0 6 votes vote down vote up
private TServer thriftServer() throws IOException,
        TTransportException,
        MetaException,
        InvocationTargetException,
        NoSuchMethodException,
        IllegalAccessException,
        NoSuchFieldException {
  final TServerSocketKeepAlive socket = new TServerSocketKeepAlive(new TServerSocket(0));
  this.hiveConf = hiveConf(new Configuration(), socket.getServerSocket().getLocalPort());
  HiveMetaStore.HMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", hiveConf);
  IHMSHandler handler = RetryingHMSHandler.getProxy(hiveConf, baseHandler, true);
  final TTransportFactory transportFactory = new TTransportFactory();
  final TSetIpAddressProcessor<IHMSHandler> processor = new TSetIpAddressProcessor<>(handler);

  TThreadPoolServer.Args args = new TThreadPoolServer.Args(socket)
          .processor(processor)
          .transportFactory(transportFactory)
          .protocolFactory(new TBinaryProtocol.Factory())
          .minWorkerThreads(3)
          .maxWorkerThreads(5);

  return new TThreadPoolServer(args);
}
 
Example 3
Source File: HelloServerConfig.java    From jigsaw-payment with Apache License 2.0 6 votes vote down vote up
@Bean(name = "pool-server")
public TServer poolServer() throws Exception {
	TServerTransport transport = new TServerSocket(this.port());

	TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
	args.transportFactory(new TTransportFactory());
	args.protocolFactory(new TBinaryProtocol.Factory());

	args.processor(this.processor());
	args.executorService(new ThreadPoolExecutor(env.getProperty(
			"rpc.server.min.worker.threads", Integer.class, 512), env
			.getProperty("rpc.server.max.worker.threads", Integer.class,
					65535), env.getProperty(
			"rpc.server.thread.keep.alive.time", Long.class, 600l),
			TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));

	return new TThreadPoolServer(args);
}
 
Example 4
Source File: ThriftITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static TServer startNewThreadPoolServer(final TServerTransport transport) {
  final TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();

  final CustomHandler customHandler = new CustomHandler();
  final CustomService.Processor<CustomService.Iface> customProcessor = new CustomService.Processor<CustomService.Iface>(customHandler);

  final TThreadPoolServer.Args args = new TThreadPoolServer
    .Args(transport)
    .processorFactory(new TProcessorFactory(customProcessor))
    .protocolFactory(protocolFactory)
    .minWorkerThreads(5)
    .maxWorkerThreads(10);

  final TServer server = new TThreadPoolServer(args);
  new Thread(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  }).start();

  return server;
}
 
Example 5
Source File: ThriftTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private void startNewThreadPoolServer() throws Exception {
  final TServerTransport transport = new TServerSocket(port);
  final TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
  // TTransportFactory transportFactory = new TFramedTransport.Factory();

  final CustomHandler customHandler = new CustomHandler();
  final TProcessor customProcessor = new CustomService.Processor<CustomService.Iface>(customHandler);

  final TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport)
    .processorFactory(new TProcessorFactory(customProcessor))
    .protocolFactory(protocolFactory)
    // .transportFactory(transportFactory)
    .minWorkerThreads(5)
    // .executorService(Executors.newCachedThreadPool())
    .maxWorkerThreads(10);

  server = new TThreadPoolServer(args);
  new Thread(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  }).start();
}
 
Example 6
Source File: CoronaTaskTracker.java    From RDFS with Apache License 2.0 6 votes vote down vote up
private synchronized void initializeClusterManagerCallbackServer()
    throws IOException {
  // Create thrift RPC to serve ClusterManager
  int soTimeout = fConf.getInt(
      CORONA_TASK_TRACKER_SERVER_CLIENTTIMEOUT_KEY, 30 * 1000);
  ServerSocket serverSocket = new ServerSocket();
  serverSocket.setReuseAddress(true);
  serverSocket.bind(new InetSocketAddress(0));
  TServerSocket tSocket = new TServerSocket(serverSocket, soTimeout);
  CoronaTaskTrackerService.Processor proc =
      new CoronaTaskTrackerService.Processor(this);
  TBinaryProtocol.Factory protocolFactory =
      new TBinaryProtocol.Factory(true, true);
  TThreadPoolServer.Args args = new TThreadPoolServer.Args(tSocket);
  args.processor(proc);
  args.protocolFactory(protocolFactory);
  clusterManagerCallbackServer = new TThreadPoolServer(args);
  clusterManagerCallbackServerThread =
      new TServerThread(clusterManagerCallbackServer);
  clusterManagerCallbackServerThread.start();
  clusterManagerCallbackServerAddr = new InetAddress(
      getLocalHostname(), serverSocket.getLocalPort());
  LOG.info("SessionServer up at " + serverSocket.getLocalSocketAddress());
}
 
Example 7
Source File: IoTDBThreadPoolFactory.java    From incubator-iotdb with Apache License 2.0 5 votes vote down vote up
/**
 * function for creating thrift rpc client thread pool.
 */
public static ExecutorService createThriftRpcClientThreadPool(TThreadPoolServer.Args args, String poolName,
    Thread.UncaughtExceptionHandler handler) {
  SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<>();
  return new ThreadPoolExecutor(args.minWorkerThreads, args.maxWorkerThreads, args.stopTimeoutVal,
      args.stopTimeoutUnit, executorQueue, new IoTThreadFactory(poolName, handler));
}
 
Example 8
Source File: TestHiveMetastore.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private TServer newThriftServer(TServerSocket socket, HiveConf conf) throws Exception {
  HiveConf serverConf = new HiveConf(conf);
  serverConf.set(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, "jdbc:derby:" + getDerbyPath() + ";create=true");
  HiveMetaStore.HMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", serverConf);
  IHMSHandler handler = RetryingHMSHandler.getProxy(serverConf, baseHandler, false);

  TThreadPoolServer.Args args = new TThreadPoolServer.Args(socket)
      .processor(new TSetIpAddressProcessor<>(handler))
      .transportFactory(new TTransportFactory())
      .protocolFactory(new TBinaryProtocol.Factory())
      .minWorkerThreads(3)
      .maxWorkerThreads(5);

  return new TThreadPoolServer(args);
}
 
Example 9
Source File: AbstractThriftServer.java    From metacat with Apache License 2.0 5 votes vote down vote up
private void startServing(final ExecutorService executorService, final TServerTransport serverTransport) {
    if (!stopping.get()) {
        final TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport)
            .processor(getProcessor())
            .executorService(executorService);
        server = new TThreadPoolServer(serverArgs);
        if (hasServerEventHandler()) {
            server.setServerEventHandler(getServerEventHandler());
        }

        final String threadName = getServerName() + "-thread-#" + serverThreadCount.incrementAndGet();
        new Thread(threadName) {
            @Override
            public void run() {
                log.debug("starting serving");
                try {
                    server.serve();
                } catch (Throwable t) {
                    if (!stopping.get()) {
                        log.error("Unexpected exception in {}. This probably "
                            + "means that the worker pool was exhausted. "
                            + "Increase 'metacat.thrift.server_max_worker_threads' "
                            + "from {} or throttle the number of requests. "
                            + "This server thread is not in a bad state so starting a new one.",
                            getServerName(), config.getThriftServerMaxWorkerThreads(), t);
                        startServing(executorService, serverTransport);
                    } else {
                        log.debug("stopping serving");
                    }
                }
                log.debug("started serving");
            }
        }.start();
    }
}
 
Example 10
Source File: ThreadPoolThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
/**
 * 初始化Thrift服务
 * <p>
 * 启动Thrift服务之前必须要进行初始化.
 * 
 * @param serverTransport
 *            服务传输类型
 */
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getServerConfiguration();
	// 使用TThreadPoolServer方式启动Thrift服务器,对每个连接都会单独建立一个线程.
	TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport)
			.transportFactory(configuration.getTransportFactory())
			.protocolFactory(configuration.getProtocolFactory());
	// 如果不设置ExecutorService,则默认使用ThreadPoolExecutor实现.
	if (ObjectUtil.isNotNull(configuration.getExecutorService()))
		args.executorService(configuration.getExecutorService());
	server = new TThreadPoolServer(
			configuration.getServerArgsAspect().tThreadPoolServerArgsAspect(args).processor(getProcessor()));
	if (ObjectUtil.isNotNull(configuration.getServerEventHandler()))
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
Example 11
Source File: ServiceProvider.java    From ourea with Apache License 2.0 5 votes vote down vote up
/**
 * 启动thrift server,如果存在server容器或者多个service,则一些需要设置为daemon模式
 */
private void startServer() throws Exception {

    TServerSocket serverTransport = new TServerSocket(serverConfig.getPort());
    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
    args.maxWorkerThreads = serverConfig.getMaxWorkerThreads();
    args.minWorkerThreads = serverConfig.getMinWorkerThreads();
    args.protocolFactory(new TBinaryProtocol.Factory());

    TProcessor tProcessor = getProcessorIface(getIfaceClass());
    args.processor(tProcessor);
    final TServer server = new TThreadPoolServer(args);
    server.setServerEventHandler(serverConfig.getServerEventHandler());
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    });
    thread.setDaemon(serverConfig.isDaemonRun());
    thread.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override public void run() {
            if (!serverConfig.isDirectInvoke()) {
                unZkRegister(providerInfo, serviceInfo);
            }
            server.stop();
        }
    }));

    LOGGER.info("----------------start thrift server--------------");
}
 
Example 12
Source File: HiveService.java    From kite with Apache License 2.0 4 votes vote down vote up
public TServer startMetaStore(String forceBindIP, int port,
    HiveConf conf) throws IOException {
  try {
    // Server will create new threads up to max as necessary. After an idle
    // period, it will destory threads to keep the number of threads in the
    // pool to min.
    int minWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMINTHREADS);
    int maxWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMAXTHREADS);
    boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.METASTORE_TCP_KEEP_ALIVE);
    boolean useFramedTransport = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);

    // don't support SASL yet
    //boolean useSasl = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL);

    TServerTransport serverTransport;
    if (forceBindIP != null) {
      InetSocketAddress address = new InetSocketAddress(forceBindIP, port);
      serverTransport = tcpKeepAlive ?
          new TServerSocketKeepAlive(address) : new TServerSocket(address);

    } else {
      serverTransport = tcpKeepAlive ?
          new TServerSocketKeepAlive(port) : new TServerSocket(port);
    }

    TProcessor processor;
    TTransportFactory transFactory;

    IHMSHandler handler = (IHMSHandler) HiveMetaStore
        .newRetryingHMSHandler("new db based metaserver", conf, true);

    if (conf.getBoolVar(HiveConf.ConfVars.METASTORE_EXECUTE_SET_UGI)) {
      transFactory = useFramedTransport ?
          new ChainedTTransportFactory(new TFramedTransport.Factory(),
              new TUGIContainingTransport.Factory())
          : new TUGIContainingTransport.Factory();

      processor = new TUGIBasedProcessor<IHMSHandler>(handler);
      LOG.info("Starting DB backed MetaStore Server with SetUGI enabled");
    } else {
      transFactory = useFramedTransport ?
          new TFramedTransport.Factory() : new TTransportFactory();
      processor = new TSetIpAddressProcessor<IHMSHandler>(handler);
      LOG.info("Starting DB backed MetaStore Server");
    }

    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport)
        .processor(processor)
        .transportFactory(transFactory)
        .protocolFactory(new TBinaryProtocol.Factory())
        .minWorkerThreads(minWorkerThreads)
        .maxWorkerThreads(maxWorkerThreads);

    final TServer tServer = new TThreadPoolServer(args);
    executorService.submit(new Runnable() {
      @Override
      public void run() {
        tServer.serve();
      }
    });
    return tServer;
  } catch (Throwable x) {
    throw new IOException(x);
  }
}
 
Example 13
Source File: IoTDBThreadPoolFactory.java    From incubator-iotdb with Apache License 2.0 4 votes vote down vote up
/**
 * function for creating thrift rpc client thread pool.
 */
public static ExecutorService createThriftRpcClientThreadPool(TThreadPoolServer.Args args, String poolName) {
  SynchronousQueue<Runnable> executorQueue = new SynchronousQueue<>();
  return new ThreadPoolExecutor(args.minWorkerThreads, args.maxWorkerThreads, args.stopTimeoutVal,
      args.stopTimeoutUnit, executorQueue, new IoTThreadFactory(poolName));
}
 
Example 14
Source File: RpcServerConfiguration.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
/**
 * 这个bean启动后会独占线程,导致其他的bean无法执行。所以必须保证这个bean在最后才能够执行。
 * @return
 * @throws Exception
 */
@Bean(initMethod = "start", destroyMethod = "stop")
public ServerRunner serverRunner()
		throws Exception {
	String ip = this.ip;
	if (ip == null)
		ip = new IpPortResolver().getIpV4Address();

	String instanceId = this.ip + ":" + this.port;
	
	CuratorFramework curatorFramework =CuratorFrameworkFactory.builder()
			.connectString(this.connectString)
			.sessionTimeoutMs(this.sessionTimeoutMs)
			.connectionTimeoutMs(this.connectionTimeoutMs)
			.retryPolicy(this.retryPolicy())
			.aclProvider(this.aclProvider()).authorization(this.authInfo())
			.build();
	InstanceSerializer<RpcPayload> serializer = new JsonSerializer();

	TServerTransport transport = new TServerSocket(this.port);

	TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
	args.transportFactory(new TTransportFactory());
	args.protocolFactory(new TBinaryProtocol.Factory());

	TProcessor processor= new TProtobufProcessor();		
	args.processor(processor);
	
	args.executorService(new ThreadPoolExecutor(this.minTheads,
			this.maxTheads, this.keepAliveTime, TimeUnit.SECONDS,
			new SynchronousQueue<Runnable>()));

	TServer server = new TThreadPoolServer(args);

	ServiceInstanceBuilder<RpcPayload> instanceBuilder = ServiceInstance
			.builder();
	instanceBuilder.name(this.serviceName)
			.uriSpec(new UriSpec(this.uriSpec)).payload(this.payload())
			.port(port).id(instanceId).address(ip);

	ServiceDiscoveryBuilder<RpcPayload> discoveryBuilder = ServiceDiscoveryBuilder
			.builder(RpcPayload.class);
	discoveryBuilder.client(curatorFramework).basePath(zkBasePath)
			.serializer(serializer).thisInstance(instanceBuilder.build())
			.build();
	return ServerRunner
			.newBuilder()
			.server(server)
			.curatorFramework(curatorFramework)
			.serviceDiscovery(discoveryBuilder.build())
			.zookeeperDeferRegisterPeriod(this.zookeeperDeferRegisterPeriod)
			.zookeeperUnregisterPeriod(this.zookeeperUnregisterPeriod).build();
}
 
Example 15
Source File: MetaStoreProxyServer.java    From waggle-dance with Apache License 2.0 4 votes vote down vote up
/**
 * Start Metastore based on a passed {@link HadoopThriftAuthBridge}
 *
 * @param bridge
 * @param startLock
 * @param startCondition
 * @param startedServing
 * @throws Throwable
 */
private void startWaggleDance(
    HadoopThriftAuthBridge bridge,
    Lock startLock,
    Condition startCondition,
    AtomicBoolean startedServing)
  throws Throwable {
  try {
    // Server will create new threads up to max as necessary. After an idle
    // period, it will destory threads to keep the number of threads in the
    // pool to min.
    int minWorkerThreads = hiveConf.getIntVar(ConfVars.METASTORESERVERMINTHREADS);
    int maxWorkerThreads = hiveConf.getIntVar(ConfVars.METASTORESERVERMAXTHREADS);
    boolean tcpKeepAlive = hiveConf.getBoolVar(ConfVars.METASTORE_TCP_KEEP_ALIVE);
    boolean useFramedTransport = hiveConf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);
    boolean useSSL = hiveConf.getBoolVar(ConfVars.HIVE_METASTORE_USE_SSL);

    TServerSocket serverSocket = createServerSocket(useSSL, waggleDanceConfiguration.getPort());

    if (tcpKeepAlive) {
      serverSocket = new TServerSocketKeepAlive(serverSocket);
    }

    TTransportFactory transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory();
    LOG.info("Starting WaggleDance Server");

    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverSocket)
        .processorFactory(tSetIpAddressProcessorFactory)
        .transportFactory(transFactory)
        .protocolFactory(new TBinaryProtocol.Factory())
        .minWorkerThreads(minWorkerThreads)
        .maxWorkerThreads(maxWorkerThreads)
        .stopTimeoutVal(waggleDanceConfiguration.getThriftServerStopTimeoutValInSeconds())
        .requestTimeout(waggleDanceConfiguration.getThriftServerRequestTimeout())
        .requestTimeoutUnit(waggleDanceConfiguration.getThriftServerRequestTimeoutUnit());

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

    if (startLock != null) {
      signalOtherThreadsToStart(tServer, startLock, startCondition, startedServing);
    }
    tServer.serve();
  } catch (Throwable x) {
    LOG.error(StringUtils.stringifyException(x));
    throw x;
  }
  LOG.info("Waggle Dance has stopped");
}
 
Example 16
Source File: ServerArgsAspect.java    From ikasoa with MIT License 4 votes vote down vote up
public TThreadPoolServer.Args tThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
	return args;
}
 
Example 17
Source File: HiveTestService.java    From hudi with Apache License 2.0 4 votes vote down vote up
public TServer startMetaStore(String forceBindIP, int port, HiveConf conf) throws IOException {
  try {
    // Server will create new threads up to max as necessary. After an idle
    // period, it will destory threads to keep the number of threads in the
    // pool to min.
    int minWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMINTHREADS);
    int maxWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMAXTHREADS);
    boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.METASTORE_TCP_KEEP_ALIVE);
    boolean useFramedTransport = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);

    // don't support SASL yet
    // boolean useSasl = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL);

    TServerTransport serverTransport;
    if (forceBindIP != null) {
      InetSocketAddress address = new InetSocketAddress(forceBindIP, port);
      serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(address) : new TServerSocket(address);

    } else {
      serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(port) : new TServerSocket(port);
    }

    TProcessor processor;
    TTransportFactory transFactory;

    HiveMetaStore.HMSHandler baseHandler = new HiveMetaStore.HMSHandler("new db based metaserver", conf, false);
    IHMSHandler handler = RetryingHMSHandler.getProxy(conf, baseHandler, true);

    if (conf.getBoolVar(HiveConf.ConfVars.METASTORE_EXECUTE_SET_UGI)) {
      transFactory = useFramedTransport
          ? new ChainedTTransportFactory(new TFramedTransport.Factory(), new TUGIContainingTransport.Factory())
          : new TUGIContainingTransport.Factory();

      processor = new TUGIBasedProcessor<>(handler);
      LOG.info("Starting DB backed MetaStore Server with SetUGI enabled");
    } else {
      transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory();
      processor = new TSetIpAddressProcessor<>(handler);
      LOG.info("Starting DB backed MetaStore Server");
    }

    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor)
        .transportFactory(transFactory).protocolFactory(new TBinaryProtocol.Factory())
        .minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads);

    final TServer tServer = new TThreadPoolServer(args);
    executorService.submit(tServer::serve);
    return tServer;
  } catch (Throwable x) {
    throw new IOException(x);
  }
}
 
Example 18
Source File: CustomTThreadPoolServer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public CustomTThreadPoolServer(TThreadPoolServer.Args args, ExecutorService executorService) {
    super(args);
    this.executorService = executorService;
    this.args = args;
}
 
Example 19
Source File: CustomTThreadPoolServer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public TServer buildTServer(Args args)
{
    final InetSocketAddress addr = args.addr;
    TServerTransport serverTransport;
    try
    {
        final ClientEncryptionOptions clientEnc = DatabaseDescriptor.getClientEncryptionOptions();
        if (clientEnc.enabled)
        {
            logger.info("enabling encrypted thrift connections between client and server");
            TSSLTransportParameters params = new TSSLTransportParameters(clientEnc.protocol, clientEnc.cipher_suites);
            params.setKeyStore(clientEnc.keystore, clientEnc.keystore_password);
            if (clientEnc.require_client_auth)
            {
                params.setTrustStore(clientEnc.truststore, clientEnc.truststore_password);
                params.requireClientAuth(true);
            }
            TServerSocket sslServer = TSSLTransportFactory.getServerSocket(addr.getPort(), 0, addr.getAddress(), params);
            SSLServerSocket sslServerSocket = (SSLServerSocket) sslServer.getServerSocket();
            sslServerSocket.setEnabledProtocols(SSLFactory.ACCEPTED_PROTOCOLS);
            serverTransport = new TCustomServerSocket(sslServer.getServerSocket(), args.keepAlive, args.sendBufferSize, args.recvBufferSize);
        }
        else
        {
            serverTransport = new TCustomServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize, args.listenBacklog);
        }
    }
    catch (TTransportException e)
    {
        throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
    }
    // ThreadPool Server and will be invocation per connection basis...
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport)
                                                             .minWorkerThreads(DatabaseDescriptor.getRpcMinThreads())
                                                             .maxWorkerThreads(DatabaseDescriptor.getRpcMaxThreads())
                                                             .inputTransportFactory(args.inTransportFactory)
                                                             .outputTransportFactory(args.outTransportFactory)
                                                             .inputProtocolFactory(args.tProtocolFactory)
                                                             .outputProtocolFactory(args.tProtocolFactory)
                                                             .processor(args.processor);
    ExecutorService executorService = new ThreadPoolExecutor(serverArgs.minWorkerThreads,
                                                             serverArgs.maxWorkerThreads,
                                                             60,
                                                             TimeUnit.SECONDS,
                                                             new SynchronousQueue<Runnable>(),
                                                             new NamedThreadFactory("Thrift"));
    return new CustomTThreadPoolServer(serverArgs, executorService);
}
 
Example 20
Source File: DataProcess.java    From dk-fitting with Apache License 2.0 2 votes vote down vote up
public void startServer() {

        try {
            System.out.println("Start server on port "+ SERVER_PORT +"...");

            // 简单的单线程服务模型,一般用于测试
            TServerSocket serverTransport = new TServerSocket(SERVER_PORT);

            TMultiplexedProcessor processor = new TMultiplexedProcessor();


            DataAnalysisService.Processor<DataAnalysisService.Iface> tprocessor =
                    new DataAnalysisService.Processor<>(new DataAnalysisImpl());
            processor.registerProcessor("DataAnalysisService", tprocessor);


            DataStaticKerberosService.Processor<DataStaticKerberosService.Iface> tprocessor1 =
                    new DataStaticKerberosService.Processor<DataStaticKerberosService.Iface>(new DataStaticKerberosImpl());
            processor.registerProcessor("DataStaticKerberosService", tprocessor1);

            DataStaticService.Processor<DataStaticService.Iface> tprocessor2 =
                    new DataStaticService.Processor<DataStaticService.Iface>(new DataStaticImpl());
            processor.registerProcessor("DataStaticService", tprocessor2);


            DedupeKerberosService.Processor<DedupeKerberosService.Iface> tprocessor3 =
                    new DedupeKerberosService.Processor<DedupeKerberosService.Iface>(new DedupeKerberosImpl());
            processor.registerProcessor("DedupeKerberosService", tprocessor3);


            DedupeService.Processor<DedupeService.Iface> tprocessor4 =
                    new DedupeService.Processor<DedupeService.Iface>(new DedupeImpl());
            processor.registerProcessor("DedupeService", tprocessor4);

            FormatFieldService.Processor<FormatFieldService.Iface> tprocessor5 =
                    new FormatFieldService.Processor<FormatFieldService.Iface>(new FormatFieldImpl());
            processor.registerProcessor("FormatFieldService", tprocessor5);


            FormatRecService.Processor<FormatRecService.Iface> tprocessor6 =
                    new FormatRecService.Processor<FormatRecService.Iface>(new FormatRecImpl());
            processor.registerProcessor("FormatRecService", tprocessor6);

            SelectFieldService.Processor<SelectFieldService.Iface> tprocessor7 =
                    new SelectFieldService.Processor<SelectFieldService.Iface>(new SelectFieldImlp());
            processor.registerProcessor("SelectFieldService", tprocessor7);

            SelectRecService.Processor<SelectRecService.Iface> tprocessor8 =
                    new SelectRecService.Processor<SelectRecService.Iface>(new SelectRecImpl());
            processor.registerProcessor("SelectRecService", tprocessor8);


            DataCleanKerberosService.Processor<DataCleanKerberosService.Iface> tprocessor9 =
                    new DataCleanKerberosService.Processor<DataCleanKerberosService.Iface>(new DataCleanKerberosImpl());
            processor.registerProcessor("DataCleanKerberosService", tprocessor9);

            TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
            ttpsArgs.processor(processor);
            ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());

            // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
            TServer server = new TThreadPoolServer(ttpsArgs);
            server.serve();



        } catch (Exception e) {
            System.out.println("Server start error!!!");
            e.printStackTrace();
        }


    }