Java Code Examples for org.apache.thrift.server.TThreadPoolServer#serve()
The following examples show how to use
org.apache.thrift.server.TThreadPoolServer#serve() .
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: TestThriftServiceStarter.java From thrift-client-pool-java with Artistic License 2.0 | 6 votes |
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 2
Source File: DKDataSourceServer.java From dk-fitting with Apache License 2.0 | 5 votes |
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 3
Source File: DKSQLUtilsServer.java From dk-fitting with Apache License 2.0 | 5 votes |
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 4
Source File: AbstractTest.java From dubbox with Apache License 2.0 | 5 votes |
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 5
Source File: ThriftServer.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TTransportException, IOException { TradeHistory.Processor proc = new TradeHistory.Processor(new TradeHistoryHandler()); TServerSocket trans_svr = new TServerSocket(9090); TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(trans_svr).processor(proc)); System.out.println("[Server] listening of port 9090"); server.serve(); }
Example 6
Source File: AbstractTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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 7
Source File: ThriftServer.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TTransportException, IOException { TradeHistory.Processor proc = new TradeHistory.Processor(new TradeHistoryHandler()); TServerSocket trans_svr = new TServerSocket(9090); TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(trans_svr) .protocolFactory(new TJSONProtocol.Factory()) .processor(proc)); System.out.println("[Server] listening of port 9090"); server.serve(); }
Example 8
Source File: AbstractTest.java From dubbox with Apache License 2.0 | 5 votes |
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 9
Source File: TestBookKeeperFactory.java From rubix with Apache License 2.0 | 5 votes |
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 10
Source File: AbstractTest.java From dubbox with Apache License 2.0 | 5 votes |
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 11
Source File: MetaStoreProxyServer.java From waggle-dance with Apache License 2.0 | 4 votes |
/** * 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 12
Source File: AbstractTest.java From dubbo-2.6.5 with Apache License 2.0 | 3 votes |
protected void init() throws Exception { 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 13
Source File: ServiceMethodNotFoundTest.java From dubbox with Apache License 2.0 | 2 votes |
protected void init() throws Exception { TServerTransport serverTransport = new TServerSocket( PORT ); DubboDemoImpl impl = new DubboDemoImpl(); $__DemoStub.Processor processor = new $__DemoStub.Processor( impl ); // for test Field field = processor.getClass().getSuperclass().getDeclaredField( "processMap" ); field.setAccessible( true ); Object obj = field.get( processor ); if ( obj instanceof Map ) { ( ( Map ) obj ).remove( "echoString" ); } // ~ TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory(); MultiServiceProcessor wrapper = new MultiServiceProcessor(); wrapper.addProcessor( Demo.class, processor ); server = new TThreadPoolServer( new TThreadPoolServer.Args( serverTransport ) .inputProtocolFactory( bFactory ) .outputProtocolFactory( bFactory ) .inputTransportFactory( getTransportFactory() ) .outputTransportFactory( getTransportFactory() ) .processor( wrapper ) ); Thread startTread = new Thread() { @Override public void run() { server.serve(); } }; startTread.start(); while ( !server.isServing() ) { Thread.sleep( 100 ); } }
Example 14
Source File: ServiceMethodNotFoundTest.java From dubbox with Apache License 2.0 | 2 votes |
protected void init() throws Exception { TServerTransport serverTransport = new TServerSocket( PORT ); DubboDemoImpl impl = new DubboDemoImpl(); $__DemoStub.Processor processor = new $__DemoStub.Processor( impl ); // for test Field field = processor.getClass().getSuperclass().getDeclaredField( "processMap" ); field.setAccessible( true ); Object obj = field.get( processor ); if ( obj instanceof Map ) { ( ( Map ) obj ).remove( "echoString" ); } // ~ TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory(); MultiServiceProcessor wrapper = new MultiServiceProcessor(); wrapper.addProcessor( Demo.class, processor ); server = new TThreadPoolServer( new TThreadPoolServer.Args( serverTransport ) .inputProtocolFactory( bFactory ) .outputProtocolFactory( bFactory ) .inputTransportFactory( getTransportFactory() ) .outputTransportFactory( getTransportFactory() ) .processor( wrapper ) ); Thread startTread = new Thread() { @Override public void run() { server.serve(); } }; startTread.start(); while ( !server.isServing() ) { Thread.sleep( 100 ); } }
Example 15
Source File: ServiceMethodNotFoundTest.java From dubbox-hystrix with Apache License 2.0 | 2 votes |
protected void init() throws Exception { TServerTransport serverTransport = new TServerSocket( PORT ); DubboDemoImpl impl = new DubboDemoImpl(); $__DemoStub.Processor processor = new $__DemoStub.Processor( impl ); // for test Field field = processor.getClass().getSuperclass().getDeclaredField( "processMap" ); field.setAccessible( true ); Object obj = field.get( processor ); if ( obj instanceof Map ) { ( ( Map ) obj ).remove( "echoString" ); } // ~ TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory(); MultiServiceProcessor wrapper = new MultiServiceProcessor(); wrapper.addProcessor( Demo.class, processor ); server = new TThreadPoolServer( new TThreadPoolServer.Args( serverTransport ) .inputProtocolFactory( bFactory ) .outputProtocolFactory( bFactory ) .inputTransportFactory( getTransportFactory() ) .outputTransportFactory( getTransportFactory() ) .processor( wrapper ) ); Thread startTread = new Thread() { @Override public void run() { server.serve(); } }; startTread.start(); while ( !server.isServing() ) { Thread.sleep( 100 ); } }
Example 16
Source File: ServiceMethodNotFoundTest.java From dubbox with Apache License 2.0 | 2 votes |
protected void init() throws Exception { TServerTransport serverTransport = new TServerSocket( PORT ); DubboDemoImpl impl = new DubboDemoImpl(); $__DemoStub.Processor processor = new $__DemoStub.Processor( impl ); // for test Field field = processor.getClass().getSuperclass().getDeclaredField( "processMap" ); field.setAccessible( true ); Object obj = field.get( processor ); if ( obj instanceof Map ) { ( ( Map ) obj ).remove( "echoString" ); } // ~ TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory(); MultiServiceProcessor wrapper = new MultiServiceProcessor(); wrapper.addProcessor( Demo.class, processor ); server = new TThreadPoolServer( new TThreadPoolServer.Args( serverTransport ) .inputProtocolFactory( bFactory ) .outputProtocolFactory( bFactory ) .inputTransportFactory( getTransportFactory() ) .outputTransportFactory( getTransportFactory() ) .processor( wrapper ) ); Thread startTread = new Thread() { @Override public void run() { server.serve(); } }; startTread.start(); while ( !server.isServing() ) { Thread.sleep( 100 ); } }
Example 17
Source File: ServiceMethodNotFoundTest.java From dubbo-2.6.5 with Apache License 2.0 | 2 votes |
protected void init() throws Exception { TServerTransport serverTransport = new TServerSocket(PORT); DubboDemoImpl impl = new DubboDemoImpl(); $__DemoStub.Processor processor = new $__DemoStub.Processor(impl); // for test Field field = processor.getClass().getSuperclass().getDeclaredField("processMap"); field.setAccessible(true); Object obj = field.get(processor); if (obj instanceof Map) { ((Map) obj).remove("echoString"); } // ~ TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory(); MultiServiceProcessor wrapper = new MultiServiceProcessor(); wrapper.addProcessor(Demo.class, processor); server = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport) .inputProtocolFactory(bFactory) .outputProtocolFactory(bFactory) .inputTransportFactory(getTransportFactory()) .outputTransportFactory(getTransportFactory()) .processor(wrapper)); Thread startTread = new Thread() { @Override public void run() { server.serve(); } }; startTread.start(); while (!server.isServing()) { Thread.sleep(100); } }