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"); } } }); } }
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"); } } }); } }
private static boolean createThrift() { String flag = getClassName() + ".createThrift"; try { TProcessor tProcessor = new FrcService.Processor<FrcService.Iface>(theInstance); TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(thrift_port); TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport); tnbArgs.maxReadBufferBytes = DefaultValues.THRIFT_MAX_READ_BUF; tnbArgs.processor(tProcessor); // tnbArgs.transportFactory(new LCQTFramedTransport.Factory()); tnbArgs.transportFactory(new TFramedTransport.Factory()); tnbArgs.protocolFactory(new TBinaryProtocol.Factory()); server = new TNonblockingServer(tnbArgs); // server.setServerEventHandler(new LCQTServerEventHandler()); return true; } catch (Exception e) { FRCLogger.getInstance().warn(-100, flag, "exception", e); return false; } }
public TServer buildTServer(Args args) { if (DatabaseDescriptor.getClientEncryptionOptions().enabled) throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration."); final InetSocketAddress addr = args.addr; TNonblockingServerTransport serverTransport; try { serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize); } catch (TTransportException e) { throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e); } // This is single threaded hence the invocation will be all // in one thread. TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory) .outputTransportFactory(args.outTransportFactory) .inputProtocolFactory(args.tProtocolFactory) .outputProtocolFactory(args.tProtocolFactory) .processor(args.processor); return new CustomTNonBlockingServer(serverArgs); }
@Before public void setUp() throws Exception { rc = copyResourceTo("/pvdrc", temp.getRoot()); copyResourceTo("/test.thrift", temp.getRoot()); impl = Mockito.mock(MyService.Iface.class); TNonblockingServerSocket transport = new TNonblockingServerSocket(0); server = new TNonblockingServer(new TNonblockingServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory()) .processor(new MyService.Processor<>(impl))); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(server::serve); Thread.sleep(1); port = transport.getPort(); exitCode = 0; rpc = new RPC(console.tty()) { @Override protected void exit(int i) { exitCode = i; } }; }
@BeforeClass public static void setUpServer() throws Exception { setDefaultPollDelay(10, TimeUnit.MILLISECONDS); serializer = new TBinaryProtocolSerializer(); factory = new TBinaryProtocol.Factory(); port = findFreePort(); impl = Mockito.mock(Iface.class); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); server = new TNonblockingServer( new TNonblockingServer.Args(transport) .protocolFactory(factory) .processor(new Processor<>(impl))); executor = Executors.newSingleThreadExecutor(); executor.submit(server::serve); address = new InetSocketAddress("localhost", port); }
@SuppressWarnings("resource") public TServer buildTServer(Args args) { if (DatabaseDescriptor.getClientEncryptionOptions().enabled) throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration."); final InetSocketAddress addr = args.addr; TNonblockingServerTransport serverTransport; try { serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize); } catch (TTransportException e) { throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e); } // This is single threaded hence the invocation will be all // in one thread. TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory) .outputTransportFactory(args.outTransportFactory) .inputProtocolFactory(args.tProtocolFactory) .outputProtocolFactory(args.tProtocolFactory) .processor(args.processor); return new CustomTNonBlockingServer(serverArgs); }
public static AsyncEchoTestServer<TNonblockingServer> nonblockingServer(final TestEnvironment environment) throws TTransportException { TNonblockingServer server = new TNonblockingServer(new TNonblockingServer.Args( new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor()) .inputProtocolFactory(environment.getProtocolFactory()) .outputProtocolFactory(environment.getProtocolFactory())); return new AsyncEchoTestServer<TNonblockingServer>(server, environment) { @Override public SyncEchoTestClient getSynchronousClient() throws TTransportException { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override public AsyncEchoTestClient getAsynchronousClient() throws IOException { return new AsyncEchoTestClient.Client(environment); } }; }
public static SyncEchoTestServer<TNonblockingServer> nonblockingServer(final TestEnvironment environment) throws TTransportException { TNonblockingServer server = new TNonblockingServer(new TNonblockingServer.Args( new TNonblockingServerSocket(environment.getPort())).processor(getProcessor()) .inputProtocolFactory(environment.getProtocolFactory()) .outputProtocolFactory(environment.getProtocolFactory())); return new SyncEchoTestServer<TNonblockingServer>(server, environment) { @Override public SyncEchoTestClient getSynchronousClient() throws TTransportException { return new SyncEchoTestClient.ClientForNonblockingServer(environment); } @Override public AsyncEchoTestClient getAsynchronousClient() throws IOException { return new AsyncEchoTestClient.Client(environment); } }; }
/** * */ public ConcreteServer(AnnotateCommunicationService.Iface impl, int port) throws ServerException { try { this.serverXport = new TNonblockingServerSocket(port); // TODO: eval HaHs server? final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport); args.protocolFactory(new TCompactProtocol.Factory()); // TODO: eval FastFramedTransport? final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE); args.transportFactory(transFactory); // legitimately do not know type bound here - guessing Iface AnnotateCommunicationService.Processor<Iface> proc = new AnnotateCommunicationService.Processor<>(impl); args.processorFactory(new TProcessorFactory(proc)); args.maxReadBufferBytes = Long.MAX_VALUE; this.args = args; // final TNonblockingServer server = new TNonblockingServer(args); this.server = new TNonblockingServer(this.args); } catch (TTransportException e) { throw new ServerException(e); } }
public void run() { setName("Thrift Service"); try { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port); AsyncRainServiceImpl service = new AsyncRainServiceImpl(scenario); RainService.Processor<RainService.Iface> processor = new RainService.Processor<RainService.Iface>( service); TNonblockingServer.Args args = new TNonblockingServer.Args(serverTransport); args.processor(processor); // Server (connects transport and processor) server = new TNonblockingServer(args); server.serve(); } catch (TTransportException e) { e.printStackTrace(); } }
public ThriftServer(QueueService.Iface queueService, ServerConfig serverConfig, ThriftServerStats stats) throws TTransportException { this.queueService = queueService; this.serverConfig = serverConfig; this.stats = stats; // assemble thrift server TProcessor tprocessor = new QueueService.Processor(this.queueService); TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(serverConfig.getPort()); TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport); tnbArgs.processor(tprocessor); // Nonblocking server mode must use TFramedTransport tnbArgs.transportFactory(new TFramedTransport.Factory()); tnbArgs.protocolFactory(new TBinaryProtocol.Factory()); this.server = new TNonblockingServer(tnbArgs); // THsHaServer.Args thhArgs = new THsHaServer.Args(tnbSocketTransport); // thhArgs.processor(tprocessor); // // Nonblocking server mode must use TFramedTransport // thhArgs.transportFactory(new TFramedTransport.Factory()); // thhArgs.protocolFactory(new TBinaryProtocol.Factory()); // // this.server = new THsHaServer(thhArgs); this.serverThread = new ServerThread(this.server); }
private static TServer getTNonBlockingServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress); log.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString()); TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport); serverArgs.processor(processor); serverArgs.transportFactory(transportFactory); serverArgs.protocolFactory(protocolFactory); return new TNonblockingServer(serverArgs); }
private TServer startNonblockingServer(TProcessor processor, TProtocolFactory protocolFactory) { TNonblockingServerTransport nonblockingTransport = (TNonblockingServerTransport) serverTransport; TNonblockingServer.Args args = new TNonblockingServer.Args(nonblockingTransport) .processor(processor) .protocolFactory(protocolFactory); return new TNonblockingServer(args); }
private static TServer getTNonBlockingServer(TProtocolFactory protocolFactory, THBaseService.Processor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress); log.info("starting HBase Nonblocking Thrift server on " + inetSocketAddress.toString()); TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport); serverArgs.processor(processor); serverArgs.transportFactory(transportFactory); serverArgs.protocolFactory(protocolFactory); return new TNonblockingServer(serverArgs); }
public static void simple(Calculator.Processor<CalculatorHandler> processor) throws Exception { TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(9090); TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport).processor(processor)); // TServerTransport serverTransport = new TServerSocket(9090); // TServer server = new TSimpleServer(new Args(serverTransport).processor(processor)); // Use this for a multithreaded server // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor)); System.out.println("Starting the simple server..."); server.serve(); }
/** * @param args * @throws TTransportException */ public static void main(String[] args) throws TTransportException { // Read socket number from command line argument final TNonblockingServerTransport socket = new TNonblockingServerSocket(Integer.valueOf(args[0])); final Processor<CoresetServiceHandler> serverProcessor = new Processor<>(new CoresetServiceHandler()); final TServer server = new TNonblockingServer(new TNonblockingServer.Args(socket) .processor(serverProcessor)); server.serve(); }
private CoresetExternalServer(final int... portNums) throws TTransportException { // Read socket number from command line argument latch = new CountDownLatch(portNums.length); executors = Executors.newFixedThreadPool(portNums.length); for (int portNum : portNums) { log.info("Creating server with port number {}", portNum); final TNonblockingServerTransport socket = new TNonblockingServerSocket(portNum); final CoresetService.Processor<StreamingCoresetHandler> serverProcessor = new CoresetService.Processor<>(new StreamingCoresetHandler()); coresetServers.add(new TNonblockingServer(new TNonblockingServer.Args(socket) .processor(serverProcessor))); } }
@EventHandler public void onFMLServerStartedEvent(FMLServerStartedEvent e) { log.info("Starting BlockTransfer server on port 9090"); IsoBlockProjectorServiceHandler handler = new IsoBlockProjectorServiceHandler(); Processor processor = new IsoBlockProjectorService.Processor(handler); try { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket( 9090); TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport); serverArgs.processor(processor); serverArgs.transportFactory(new TFramedTransport.Factory()); serverArgs.protocolFactory(new TBinaryProtocol.Factory(true, true)); IBPserver = new TIsoBlockProjectorServer(serverArgs); IBPserverthread = new Thread() { public void run() { IBPserver.serve(); } }; IBPserverthread.start(); } catch (Exception ex) { throw new RuntimeException("Unable to start BlockTransfer server",ex); } MinecraftForge.EVENT_BUS.register(this); FMLCommonHandler.instance().bus().register(this); }
public static TServer createNonBlockingServer(TProcessorFactory processorFactory, int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize) throws TTransportException { TNonblockingServerTransport transport = new TNonblockingServerSocket(port, clientTimeoutMillisecs); TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize); TNonblockingServer.Args args = new TNonblockingServer.Args(transport) .processorFactory(processorFactory).protocolFactory(protocolFactory) .transportFactory(transportFactory); args.maxReadBufferBytes = maxReadBufferSize; TNonblockingServer server = new TNonblockingServer(args); return server; }
public TServer buildTServer(Args args) { if (DatabaseDescriptor.getClientEncryptionOptions().enabled) throw new RuntimeException("Client SSL is not supported for non-blocking sockets (hsha). Please remove client ssl from the configuration."); final InetSocketAddress addr = args.addr; TNonblockingServerTransport serverTransport; try { serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize); } catch (TTransportException e) { throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e); } // This is NIO selector service but the invocation will be Multi-Threaded with the Executor service. ExecutorService executorService = new JMXEnabledThreadPoolExecutor(DatabaseDescriptor.getRpcMinThreads(), DatabaseDescriptor.getRpcMaxThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("RPC-Thread"), "RPC-THREAD-POOL"); TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory) .outputTransportFactory(args.outTransportFactory) .inputProtocolFactory(args.tProtocolFactory) .outputProtocolFactory(args.tProtocolFactory) .processor(args.processor); // Check for available processors in the system which will be equal to the IO Threads. return new CustomTHsHaServer(serverArgs, executorService, FBUtilities.getAvailableProcessors()); }
public static void main(String [] args) throws TTransportException, IOException, InterruptedException { connectToCMD(); TProcessor proc = new LucidaService.AsyncProcessor( new QAServiceHandler.AsyncQAServiceHandler()); TNonblockingServerTransport transport = new TNonblockingServerSocket(8083); TNonblockingServer.Args arguments = new TNonblockingServer.Args(transport) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .transportFactory(new TFramedTransport.Factory()); final TNonblockingServer server = new TNonblockingServer(arguments); System.out.println("QA at port 8083"); server.serve(); }
public ConcreteZipArchiveFetchServiceThread(FetchCommunicationService.Iface impl, int port) throws TException { serverTransport = new TNonblockingServerSocket(port); serverArgs = new TNonblockingServer.Args(serverTransport); serverArgs.protocolFactory(new TCompactProtocol.Factory()); serverArgs.transportFactory(new TFramedTransport.Factory(Integer.MAX_VALUE)); serverArgs.processorFactory(new TProcessorFactory(new FetchCommunicationService.Processor<>(impl))); serverArgs.maxReadBufferBytes = Long.MAX_VALUE; server = new TNonblockingServer(serverArgs); }
/** * @param impl * @param port * @throws TException */ public SearchServiceWrapper(SearchService.Iface impl, int port) throws TException { this.serverXport = new TNonblockingServerSocket(port); final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport); args.protocolFactory(new TCompactProtocol.Factory()); final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE); args.transportFactory(transFactory); SearchService.Processor<Iface> proc = new SearchService.Processor<>(impl); args.processorFactory(new TProcessorFactory(proc)); args.maxReadBufferBytes = Long.MAX_VALUE; this.servArgs = args; this.server = new TNonblockingServer(this.servArgs); }
public FetchServiceWrapper(FetchCommunicationService.Iface impl, int port) throws TException { this.serverXport = new TNonblockingServerSocket(port); final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport); args.protocolFactory(new TCompactProtocol.Factory()); final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE); args.transportFactory(transFactory); FetchCommunicationService.Processor<Iface> proc = new FetchCommunicationService.Processor<>(impl); args.processorFactory(new TProcessorFactory(proc)); args.maxReadBufferBytes = Long.MAX_VALUE; this.servArgs = args; this.server = new TNonblockingServer(this.servArgs); }
public SummarizationServiceWrapper(SummarizationService.Iface impl, int port) throws TException { this.serverXport = new TNonblockingServerSocket(port); final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport); args.protocolFactory(new TCompactProtocol.Factory()); final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE); args.transportFactory(transFactory); SummarizationService.Processor<SummarizationService.Iface> proc = new SummarizationService.Processor<>(impl); args.processorFactory(new TProcessorFactory(proc)); args.maxReadBufferBytes = Long.MAX_VALUE; this.servArgs = args; this.server = new TNonblockingServer(this.servArgs); }
public StoreServiceWrapper(StoreCommunicationService.Iface impl, int port) throws TException { this.serverXport = new TNonblockingServerSocket(port); final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport); args.protocolFactory(new TCompactProtocol.Factory()); final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE); args.transportFactory(transFactory); StoreCommunicationService.Processor<Iface> proc = new StoreCommunicationService.Processor<>(impl); args.processorFactory(new TProcessorFactory(proc)); args.maxReadBufferBytes = Long.MAX_VALUE; this.servArgs = args; this.server = new TNonblockingServer(this.servArgs); }