org.apache.thrift.TProcessorFactory Java Examples
The following examples show how to use
org.apache.thrift.TProcessorFactory.
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: ThriftTest.java From java-specialagent with Apache License 2.0 | 6 votes |
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 #2
Source File: ThriftITest.java From java-specialagent with Apache License 2.0 | 6 votes |
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 #3
Source File: ThriftServerTest2.java From ThriftJ with Apache License 2.0 | 6 votes |
public static void main(String[] args){ ExecutorService es = Executors.newFixedThreadPool(2); for(int i=0; i<ports.length; i++){ final int index = i; es.execute(new Runnable() { @Override public void run() { try{ TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]); TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp()); TNonblockingServer.Args arg = new TNonblockingServer.Args(socket); arg.protocolFactory(new TBinaryProtocol.Factory()); arg.transportFactory(new TFramedTransport.Factory()); arg.processorFactory(new TProcessorFactory(processor)); TServer server = new TNonblockingServer (arg); logger.info("127.0.0.1:" + ports[index] + " start"); server.serve(); }catch(Exception e){ logger.error("127.0.0.1:" + ports[index] + " error"); } } }); } }
Example #4
Source File: ThriftServerTest.java From ThriftJ with Apache License 2.0 | 6 votes |
public static void main(String[] args){ ExecutorService es = Executors.newFixedThreadPool(2); for(int i=0; i<ports.length; i++){ final int index = i; es.execute(new Runnable() { @Override public void run() { try{ TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]); TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp()); TNonblockingServer.Args arg = new TNonblockingServer.Args(socket); arg.protocolFactory(new TBinaryProtocol.Factory()); arg.transportFactory(new TFramedTransport.Factory()); arg.processorFactory(new TProcessorFactory(processor)); TServer server = new TNonblockingServer(arg); logger.info("127.0.0.1:" + ports[index] + " start"); server.serve(); }catch(Exception e){ logger.error("127.0.0.1:" + ports[index] + " error"); } } }); } }
Example #5
Source File: AysncServiceTest.java From ikasoa with MIT License | 6 votes |
@Test public void testAysncServiceImpl() { int serverPort = ServerUtil.getNewPort(); TProcessor p = new ServiceProcessor(new TestThriftServiceImpl1()); thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(p)); Factory factory = new GeneralFactory(thriftServerConfiguration); ThriftServer thriftServer = factory.getThriftServer(serverPort, new TestThriftServiceImpl1()); thriftServer.run(); waiting(); try { AsyncService service = factory .getAsyncService(new TNonblockingSocket(TestConstants.LOCAL_HOST, serverPort)); service.get(testString1, new TestCallback1()); waiting(); } catch (Exception e) { fail(); } finally { thriftServer.stop(); } }
Example #6
Source File: AysncServiceTest.java From ikasoa with MIT License | 6 votes |
@Test public void testAysncMultiplexedServiceImpl() { int serverPort = ServerUtil.getNewPort(); Map<String, TProcessor> processorMap = MapUtil.newHashMap(); processorMap.put("testAysncService1", new ServiceProcessor(new TestThriftServiceImpl1())); processorMap.put("testAysncService2", new ServiceProcessor(new TestThriftServiceImpl2())); MultiplexedProcessor p = new MultiplexedProcessor(processorMap); thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(p)); Factory factory = new GeneralFactory(thriftServerConfiguration); ThriftServer thriftServer = factory.getThriftServer("testAysncMultiplexedService", serverPort, p); thriftServer.run(); waiting(); try { AsyncService service1 = factory .getAsyncService(new TNonblockingSocket(TestConstants.LOCAL_HOST, serverPort), "testAysncService1"); service1.get(testString1, new TestCallback1()); AsyncService service2 = factory .getAsyncService(new TNonblockingSocket(TestConstants.LOCAL_HOST, serverPort), "testAysncService2"); service2.get(testString2, new TestCallback2()); waiting(); } catch (Exception e) { fail(); } finally { thriftServer.stop(); } }
Example #7
Source File: rpcServer.java From leaf-snowflake with Apache License 2.0 | 5 votes |
public static void startRPCServer3(leafServer leafserver , String ip , int port) throws Exception { TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver)); //传输通道,非阻塞模式 InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(ip),port); TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(address,10000); TNonblockingServer.Args args = new TNonblockingServer.Args(serverTransport); args.protocolFactory(new TBinaryProtocol.Factory()); args.transportFactory(new TFramedTransport.Factory()); args.processorFactory(new TProcessorFactory(processor)); TServer server = new TNonblockingServer(args); LOG.info("leaf RPCServer(type:TNonblockingServerSocket) start at ip:port : "+ ip +":" + port ); server.serve(); }
Example #8
Source File: NettyServerImpl.java From ikasoa with MIT License | 5 votes |
public NettyServerImpl(final String serverName, final int serverPort, final NettyServerConfiguration configuration, final TProcessor processor, final ChannelGroup allChannels) { setServerName(serverName); requestedPort = serverPort; setConfiguration(ObjectUtil.isNull(configuration) ? new NettyServerConfiguration(new TProcessorFactory(processor)) : configuration); setProcessor(processor); this.allChannels = allChannels; }
Example #9
Source File: ServerTest.java From ikasoa with MIT License | 5 votes |
@Test public void testAysncThriftServerImpl() { int serverPort = ServerUtil.getNewPort(); ThriftServerConfiguration thriftServerConfiguration = new ThriftServerConfiguration(); thriftServerConfiguration.setProtocolFactory(new TCompactProtocol.Factory()); thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(processor)); thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() { @Override public TThreadPoolServer.Args tThreadPoolServerArgsAspect(TThreadPoolServer.Args args) { args.stopTimeoutVal = 1; return args; } }); Factory factory = new GeneralFactory(thriftServerConfiguration); ThriftServer thriftServer = factory.getThriftServer(serverName, serverPort, processor); thriftServer.run(); waiting(); try { ThriftSimpleService.AsyncClient thriftClient = new ThriftSimpleService.AsyncClient( new TCompactProtocol.Factory(), new TAsyncClientManager(), new TNonblockingSocket(TestConstants.LOCAL_HOST, serverPort)); thriftClient.get(TestConstants.TEST_STRING, new TestCallback()); waiting(); } catch (Exception e) { fail(); } finally { thriftServer.stop(); } }
Example #10
Source File: ThriftFactories.java From disruptor_thrift_server with Apache License 2.0 | 5 votes |
public ThriftFactories(TTransportFactory inputTransportFactory, TTransportFactory outputTransportFactory, TProtocolFactory inputProtocolFactory, TProtocolFactory outputProtocolFactory, TProcessorFactory processorFactory, int maxFrameSizeInBytes) { this.inputTransportFactory = inputTransportFactory; this.outputTransportFactory = outputTransportFactory; this.inputProtocolFactory = inputProtocolFactory; this.outputProtocolFactory = outputProtocolFactory; this.processorFactory = processorFactory; this.maxFrameSizeInBytes = maxFrameSizeInBytes; }
Example #11
Source File: NettyServerConfiguration.java From ikasoa with MIT License | 4 votes |
public NettyServerConfiguration(TProcessorFactory processorFactory) { super.processorFactory = processorFactory; }
Example #12
Source File: ThriftServerConfiguration.java From ikasoa with MIT License | 4 votes |
public ThriftServerConfiguration(TProcessorFactory processorFactory) { super.processorFactory = processorFactory; }