org.apache.thrift.server.TThreadPoolServer.Args Java Examples

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: IoTDBThreadPoolFactoryTest.java    From incubator-iotdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateJDBCClientThreadPool() throws InterruptedException {
  String reason = "(can be ignored in Tests) CreateJDBCClientThreadPool";
  TThreadPoolServer.Args args = new Args(null);
  args.maxWorkerThreads = 4;
  args.minWorkerThreads = 2;
  args.stopTimeoutVal = 10;
  args.stopTimeoutUnit = TimeUnit.SECONDS;
  Thread.UncaughtExceptionHandler handler = new TestExceptionHandler(reason);
  int threadCount = 4;
  latch = new CountDownLatch(threadCount);
  ExecutorService exec = IoTDBThreadPoolFactory
      .createThriftRpcClientThreadPool(args, POOL_NAME, handler);
  for (int i = 0; i < threadCount; i++) {
    Runnable task = new TestThread(reason);
    exec.execute(task);
  }
  try {
    latch.await();
    assertEquals(count.get(), threadCount);
  } catch (InterruptedException E) {
    fail();
  }
}
 
Example #2
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 #3
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 #4
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 #5
Source File: BasicAbstractTest.java    From Thrift-Connection-Pool with Apache License 2.0 4 votes vote down vote up
protected ThriftServerInfo startServer() throws Throwable {
	// 获取一个监听端口
	final int port = choseListenPort();
	ThriftServerInfo serverInfo = new ThriftServerInfo(LOACLHOST, port);
	final AtomicReference<Throwable> ex = new AtomicReference<Throwable>();

	Thread runner = new Thread("thrift-server-starter") {
		@Override
		public void run() {
			try {
				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 {
						logger.info("pong");
					}

					@Override
					public void ping() throws TException {
						logger.info("ping");
					}
				});
				Args thriftArgs = new Args(serverTransport);
				thriftArgs.processor(processor);
				thriftArgs.protocolFactory(proFactory);
				TServer tserver = new TThreadPoolServer(thriftArgs);
				servers.add(tserver);
				logger.info("启动测试服务监听:" + port);
				tserver.serve();
			} catch (TTransportException e) {
				logger.error("thrift服务器启动失败", e);
				ex.set(e);
			}
		}
	};

	runner.start();

	Throwable throwable = ex.get();
	if (throwable != null) {
		throw throwable;
	}
	// 等待服务器启动
	Thread.sleep(1000);
	return serverInfo;
}
 
Example #6
Source File: BasicAbstractTest.java    From Thrift-Connection-Pool with Apache License 2.0 4 votes vote down vote up
protected ThriftServerInfo startMulitServiceServer() throws Throwable {
	// 获取一个监听端口
	final int port = choseListenPort();
	ThriftServerInfo serverInfo = new ThriftServerInfo(LOACLHOST, port);
	final AtomicReference<Throwable> ex = new AtomicReference<Throwable>();
	// TODO
	Thread runner = new Thread("thrift-server-starter") {
		@Override
		public void run() {
			try {
				TMultiplexedProcessor processor = new TMultiplexedProcessor();
				TServerTransport serverTransport = new TServerSocket(port);
				Factory proFactory = new TBinaryProtocol.Factory();

				processor.registerProcessor("example", new Example.Processor<Example.Iface>(new Example.Iface() {

					@Override
					public void pong() throws TException {
						logger.info("example pong");
					}

					@Override
					public void ping() throws TException {
						logger.info("example ping");
					}
				}));

				processor.registerProcessor("other", new Other.Processor<Other.Iface>(new Other.Iface() {

					@Override
					public void pong() throws TException {
						logger.info("other pong");
					}

					@Override
					public void ping() throws TException {
						logger.info("other ping");
					}
				}));
				Args thriftArgs = new Args(serverTransport);
				thriftArgs.processor(processor);
				thriftArgs.protocolFactory(proFactory);
				TServer tserver = new TThreadPoolServer(thriftArgs);
				servers.add(tserver);
				logger.info("启动测试服务监听:" + port);
				tserver.serve();
			} catch (TTransportException e) {
				logger.error("thrift服务器启动失败", e);
				ex.set(e);
			}
		}
	};

	runner.start();

	Throwable throwable = ex.get();
	if (throwable != null) {
		throw throwable;
	}
	// 等待服务器启动
	Thread.sleep(1000);
	return serverInfo;
}