org.apache.thrift.transport.TServerTransport Java Examples

The following examples show how to use org.apache.thrift.transport.TServerTransport. 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: DKMLServer.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
    try {
        int port = Integer.valueOf(prop.get("dkml.port"));
        //设置传输通道,普通通道
        TServerTransport serverTransport = new TServerSocket(port);
        //使用高密度二进制协议
        TProtocolFactory proFactory = new TCompactProtocol.Factory();
        //设置处理器
        TProcessor processor = new DKML.Processor(new DKMLImpl());
        //创建服务器
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport)
                        .protocolFactory(proFactory)
                        .processor(processor)
        );

        System.out.println("Start server on port "+ port +"...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: TestThriftClientPool.java    From thrift-client-pool-java with Artistic License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    int port = 9090;

    try {
        TServerTransport serverTransport = new TServerSocket(port);

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

        logger.info("Starting test server...");
        new Thread(server::serve).start();
        Thread.sleep(1000); // waiting server init
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #3
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 #4
Source File: ThriftITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2);
  final TServerTransport serverTransport = new TServerSocket(port);
  final TServer server = startNewThreadPoolServer(serverTransport);

  final TTransport transport = new TSocket("localhost", port);
  transport.open();

  final TProtocol protocol = new TBinaryProtocol(transport);

  final CustomService.Client client = new CustomService.Client(protocol);
  final String res = client.say("one", "two");
  if (!"Say one two".equals(res))
    throw new AssertionError("ERROR: wrong result");

  TestUtil.checkSpan(latch, new ComponentSpanCount("java-thrift", 2, true));

  server.stop();
  transport.close();
}
 
Example #5
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 #6
Source File: TestThriftServiceStarter.java    From thrift-client-pool-java with Artistic License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    int port = 9090;

    try {
        TServerTransport serverTransport = new TServerSocket(port);

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

        System.out.println("Starting the server...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
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 #8
Source File: ServerTrans.java    From ThriftBook with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) 
       throws TTransportException, UnsupportedEncodingException {
    final String msg = "Hello Thrift!\n";
    final String stop_cmd = "STOP";
    final int buf_size = 1024*8;
    byte[] buf = new byte[buf_size];
    final int port = 9090;

    TServerTransport acceptor = new TServerSocket(9090);
    acceptor.listen();
    System.out.println("[Server] listening on port: " + port);
    
    String input;
    do {
        TTransport trans = acceptor.accept();
        int len = trans.read(buf, 0, buf_size);
        input = new String(buf, 0, len,"UTF-8");
        System.out.println("[Server] handling request: " + input);
        trans.write(msg.getBytes());
        trans.flush();
        trans.close();
    } while (! stop_cmd.regionMatches(0, input, 0, 4)); 

    System.out.println("[Server] exiting");
    acceptor.close();
}
 
Example #9
Source File: ThriftServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor,
    TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws Exception {
  LOG.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
  // Thrift's implementation uses '0' as a placeholder for 'use the default.'
  int backlog = conf.getInt(BACKLOG_CONF_KEY, BACKLOG_CONF_DEAFULT);
  int readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY,
      THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);
  TServerTransport serverTransport = new TServerSocket(
      new TServerSocket.ServerSocketTransportArgs().
          bindAddr(inetSocketAddress).backlog(backlog).
          clientTimeout(readTimeout));

  TBoundedThreadPoolServer.Args serverArgs =
      new TBoundedThreadPoolServer.Args(serverTransport, conf);
  serverArgs.processor(processor).transportFactory(transportFactory)
      .protocolFactory(protocolFactory);
  return new TBoundedThreadPoolServer(serverArgs, metrics);
}
 
Example #10
Source File: AbstractThriftServer.java    From metacat with Apache License 2.0 6 votes vote down vote up
/**
 * Server initialization.
 *
 * @throws Exception error
 */
public void start() throws Exception {
    log.info("initializing thrift server {}", getServerName());
    final ThreadFactory threadFactory = new ThreadFactoryBuilder()
        .setNameFormat(threadPoolNameFormat)
        .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: {}", t.getName(), e))
        .build();
    final ExecutorService executorService = new ThreadPoolExecutor(
        Math.min(2, config.getThriftServerMaxWorkerThreads()),
        config.getThriftServerMaxWorkerThreads(),
        60L,
        TimeUnit.SECONDS,
        new SynchronousQueue<>(),
        threadFactory
    );
    RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService);
    final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000;
    final TServerTransport serverTransport = new TServerSocket(portNumber, timeout);
    startServing(executorService, serverTransport);
}
 
Example #11
Source File: NonblockingThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
/**
 * 初始化Thrift服务
 * 
 * @param serverTransport
 *            服务传输类型
 */
@Override
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getServerConfiguration();
	// 使用多线程半同步半异步方式
	TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args((TNonblockingServerSocket) serverTransport)
			.transportFactory(configuration.getTransportFactory())
			.protocolFactory(configuration.getProtocolFactory());
	if (ObjectUtil.isNotNull(configuration.getExecutorService()))
		args.executorService(configuration.getExecutorService());
	server = new TThreadedSelectorServer(
			configuration.getServerArgsAspect().tThreadedSelectorServerArgsAspect(args).processor(getProcessor()));
	if (ObjectUtil.isNotNull(configuration.getServerEventHandler()))
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
Example #12
Source File: DKDataSourceServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void simple(TMultiplexedProcessor processor) {
    try {
        Properties Prop = PropUtil.loadProp(System.getProperty("user.dir") + "/conf/datasource.properties");
        //Properties Prop = PropUtil.loadProp("D:\\workspace\\fitting\\fitting-datasource\\src\\main\\resources\\datasource.properties");
        int port = Integer.valueOf(Prop.getProperty("datasource.port"));
        TServerTransport serverTransport = new TServerSocket(port);
        TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Start server on port " + port + "...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #13
Source File: SimpleThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getServerConfiguration();
	server = new TSimpleServer(configuration.getServerArgsAspect().tServerArgsAspect(
			new TServer.Args(serverTransport).transportFactory(configuration.getTransportFactory())
					.protocolFactory(configuration.getProtocolFactory()).processor(getProcessor())));
	if (ObjectUtil.isNotNull(configuration.getServerEventHandler()))
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
Example #14
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 #15
Source File: AbstractThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
/**
 * 获取一个服务传输类型
 * <p>
 * 如果使用非Socket传输类型,需要重写此方法.
 * 
 * @return TServerTransport 服务传输类型
 */
@Override
public TServerTransport getTransport() throws TTransportException {
	if (ObjectUtil.isNull(serverSocket)) {
		TSSLTransportParameters params = getServerConfiguration().getSslTransportParameters();
		serverSocket = ObjectUtil.isNull(params) ? new TServerSocket(getServerPort())
				: TSSLTransportFactory.getServerSocket(getServerPort(), 0, null, params);
	}
	return serverSocket;
}
 
Example #16
Source File: AbstractTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

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

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
 
Example #17
Source File: ExampleServer.java    From Thrift-Connection-Pool with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	try {
		int port = 9119;
		TServerTransport serverTransport = new TServerSocket(port);
		Factory proFactory = new TBinaryProtocol.Factory();
		Processor<Iface> processor = new Example.Processor<Example.Iface>(new Example.Iface() {

			@Override
			public void pong() throws TException {
				System.out.println("pong");
			}

			@Override
			public void ping() throws TException {
				System.out.println("ping");
			}
		});
		Args thriftArgs = new Args(serverTransport);
		thriftArgs.processor(processor);
		thriftArgs.protocolFactory(proFactory);
		TServer tserver = new TThreadPoolServer(thriftArgs);
		System.out.println("启动监听:" + port);
		tserver.serve();
	} catch (TTransportException e) {
		e.printStackTrace();
	}
}
 
Example #18
Source File: AbstractTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

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

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
 
Example #19
Source File: TBoundedThreadPoolServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
public Args(TServerTransport transport, Configuration conf) {
  super(transport);
  minWorkerThreads = conf.getInt(MIN_WORKER_THREADS_CONF_KEY,
      DEFAULT_MIN_WORKER_THREADS);
  maxWorkerThreads = conf.getInt(MAX_WORKER_THREADS_CONF_KEY,
      DEFAULT_MAX_WORKER_THREADS);
  maxQueuedRequests = conf.getInt(MAX_QUEUED_REQUESTS_CONF_KEY,
      DEFAULT_MAX_QUEUED_REQUESTS);
  threadKeepAliveTimeSec = conf.getInt(THREAD_KEEP_ALIVE_TIME_SEC_CONF_KEY,
      DEFAULT_THREAD_KEEP_ALIVE_TIME_SEC);
}
 
Example #20
Source File: ServerFrame.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) 
         throws TTransportException, UnsupportedEncodingException, SocketException {
     final String msg = "Hello Thrift!\n";
     final String stop_cmd = "STOP";
     final int buf_size = 1024*8;
     byte[] buf = new byte[buf_size];
     final int port = 9090;

     TServerTransport acceptor = new TServerSocket(port);
     acceptor.listen();
     System.out.println("[Server] listening on port " + port);

     while (true) {
         TTransport trans_ep = acceptor.accept();
TTransport trans = new TFramedTransport(trans_ep);
         int len = trans.read(buf, 0, buf_size);
         String input = new String(buf, 0, len, "UTF-8");
         System.out.println("[Server] handling request: " + input);
         trans.write(msg.getBytes());
         trans.flush();
         trans.close();
         if (stop_cmd.regionMatches(0, input, 0, 4)) {
            break;
         }
     }
     System.out.println("[Server] exiting");
     acceptor.close();
 }
 
Example #21
Source File: CrossPlatformServiceServer.java    From tutorials with MIT License 5 votes vote down vote up
public void start() throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(9090);
    server = new TSimpleServer(new TServer.Args(serverTransport)
        .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl())));

    System.out.print("Starting the server... ");

    server.serve();

    System.out.println("done.");
}
 
Example #22
Source File: AMServer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public void simple(JstormAM.Processor processor) {
    try {
        TServerTransport serverTransport = new TServerSocket(port);
        TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        LOG.info("Starting the simple server...");

        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #23
Source File: DKSQLUtilsServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void simple(TMultiplexedProcessor processor) {
    try {
        Properties Prop = PropUtil.loadProp(System.getProperty("user.dir") + "/conf/sqlutils.properties");
        //Properties Prop = PropUtil.loadProp("D:\\workspace\\fitting\\fitting-sqlutils\\src\\main\\resources\\sqlutils.properties");
        int port = Integer.valueOf(Prop.getProperty("sqlutils.port"));
        TServerTransport serverTransport = new TServerSocket(port);
        TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Start server on port " + port + "...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #24
Source File: DKGraphxServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
    try {
        int port = Integer.valueOf(prop.get("dkgraphx.port"));
        //设置传输通道,普通通道
        TServerTransport serverTransport = new TServerSocket(port);

        //使用高密度二进制协议
        TProtocolFactory proFactory = new TCompactProtocol.Factory();

        //设置处理器
        TProcessor processor = new DKGraphx.Processor(new DKGraphxImpl());

        //创建服务器
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport)
                        .protocolFactory(proFactory)
                        .processor(processor)
        );

        System.out.println("Start server on port "+ port +"...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #25
Source File: AbstractTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

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

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
 
Example #26
Source File: AbstractTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

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

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
 
Example #27
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 #28
Source File: TestBookKeeperFactory.java    From rubix with Apache License 2.0 5 votes vote down vote up
void startServer(Configuration conf) throws TException
{
  BookKeeperService.Iface bookKeeper = mock(BookKeeperService.Iface.class);
  when(bookKeeper.isBookKeeperAlive()).then(new GetBookKeeperAliveStatus());

  try {
    TServerTransport serverTransport = new TServerSocket(CacheConfig.getBookKeeperServerPort(conf));
    BookKeeperService.Processor processor = new BookKeeperService.Processor<>(bookKeeper);
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
    server.serve();
  }
  catch (TException e) {
    log.error("Error starting MockBookKeeperServer", e);
  }
}
 
Example #29
Source File: GfxdThriftServerThreadPool.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public Args(TServerTransport transport) {
  super(transport);
}
 
Example #30
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);
  }
}