org.apache.thrift.server.TServer.Args Java Examples
The following examples show how to use
org.apache.thrift.server.TServer.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: DKMLServer.java From dk-fitting with Apache License 2.0 | 6 votes |
/** * 阻塞式、多线程处理 * * @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: TestApacheThriftMethodInvoker.java From drift with Apache License 2.0 | 5 votes |
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients) throws Exception { try (TServerSocket serverTransport = new TServerSocket(0)) { TProtocolFactory protocolFactory = new Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(); TServer server = new TSimpleServer(new Args(serverTransport) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor)); Thread serverThread = new Thread(server::serve); try { serverThread.start(); int localPort = serverTransport.getServerSocket().getLocalPort(); HostAndPort address = HostAndPort.fromParts("localhost", localPort); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { server.stop(); serverThread.interrupt(); } } }
Example #3
Source File: TestDriftNettyMethodInvoker.java From drift with Apache License 2.0 | 5 votes |
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients) throws Exception { try (TServerSocket serverTransport = new TServerSocket(0)) { TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(); TServer server = new TSimpleServer(new Args(serverTransport) .protocolFactory(protocolFactory) .transportFactory(transportFactory) .processor(processor)); Thread serverThread = new Thread(server::serve); try { serverThread.start(); int localPort = serverTransport.getServerSocket().getLocalPort(); HostAndPort address = HostAndPort.fromParts("localhost", localPort); int sum = 0; for (ToIntFunction<HostAndPort> client : clients) { sum += client.applyAsInt(address); } return sum; } finally { server.stop(); serverThread.interrupt(); } } }
Example #4
Source File: Configurator.java From xio with Apache License 2.0 | 5 votes |
public void run() { log.info("Starting up!"); try { serverTransport = new TServerSocket(bindAddress); server = new TSimpleServer(new Args(serverTransport).processor(processor)); server.serve(); // blocks until stop() is called. // timer and timer task should be stopped at this point writeToStorage(); } catch (TTransportException e) { log.error("Couldn't start Configurator {}", this, e); } }