private void nonBlockMode() { AskerHandler handler = new AskerHandler(); Asker.Processor processor = new Asker.Processor(handler); try { TNonblockingServerTransport transport = new TNonblockingServerSocket(port); THsHaServer.Args arg = new THsHaServer.Args(transport); arg.protocolFactory(new TCompactProtocol.Factory()); // arg.transportFactory(new TFramedTransport.Factory()); // arg.processorFactory(new TProcessorFactory(processor)); arg.processor(processor); server = new THsHaServer(arg); start.countDown(); System.out.println("Starting the nonBlock server..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port)); ThriftSourceProtocol.Iface handler = getHandler(handlerName); TProtocolFactory transportProtocolFactory = null; if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) { transportProtocolFactory = new TBinaryProtocol.Factory(); } else { transportProtocolFactory = new TCompactProtocol.Factory(); } server = new THsHaServer(new THsHaServer.Args(serverTransport).processor( new ThriftSourceProtocol.Processor(handler)).protocolFactory( transportProtocolFactory)); Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { server.serve(); } }); }
public void run() { try { Scribe.Processor processor = new Scribe.Processor(new Receiver()); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); THsHaServer.Args args = new THsHaServer.Args(transport); args.workerThreads(workers); args.processor(processor); args.transportFactory(new TFramedTransport.Factory(maxReadBufferBytes)); args.protocolFactory(new TBinaryProtocol.Factory(false, false)); args.maxReadBufferBytes = maxReadBufferBytes; server = new THsHaServer(args); LOG.info("Starting Scribe Source on port " + port); server.serve(); } catch (Exception e) { LOG.warn("Scribe failed", e); } }
@Override protected boolean startThreads() { try { for (int i = 0; i < MAX_SELECTOR_THREADS; ++i) { selectorThreads.add(new TrackingSelectorThread(ACCEPT_QUEUE_LEN)); } acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_, createSelectorThreadLoadBalancer(selectorThreads)); selectorThreads.forEach(Thread::start); acceptThread.start(); return true; } catch (IOException e) { log.error("Failed to start threads!", e); return false; } }
/** * The function to create a thrift Half-Sync and Half-Async Server. * @param processor */ public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) { try { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port); THsHaServer.Args args = new THsHaServer.Args(serverTransport); args.processor(processor); args.transportFactory(new TFramedTransport.Factory()); args.protocolFactory(new TBinaryProtocol.Factory(true, true)); TServer server = new THsHaServer(args); log.info("Starting the packetstreamer hsha server on port {} ...", port); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
/** * Start the accept and selector threads running to deal with clients. * * @return true if everything went ok, false if we couldn't start for some * reason. */ @Override protected boolean startThreads() { LOGGER.info("Starting {}", TThreadedSelectorServerWithFix.class.getSimpleName()); try { for (int i = 0; i < args.selectorThreads; ++i) { selectorThreads.add(new SelectorThread(args.acceptQueueSizePerThread)); } acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_, createSelectorThreadLoadBalancer(selectorThreads)); stopped_ = false; for (SelectorThread thread : selectorThreads) { thread.start(); } acceptThread.start(); return true; } catch (IOException e) { LOGGER.error("Failed to start threads!", 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); }
@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); }
/** * Start the accept and selector threads running to deal with clients. * * @return true if everything went ok, false if we couldn't start for some * reason. */ @Override protected boolean startThreads() { try { for (int i = 0; i < args.selectorThreads; ++i) { selectorThreads.add(new SelectorThread(args.acceptQueueSizePerThread)); } acceptThread = new AcceptThread((TNonblockingServerTransport) serverTransport_, createSelectorThreadLoadBalancer(selectorThreads)); for (SelectorThread thread : selectorThreads) { thread.start(); } acceptThread.start(); return true; } catch (IOException e) { LOGGER.error("Failed to start threads!", e); return false; } }
@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 void main(String[] args) { try { handler = new CalculatorHandler(); processor = new Calculator.Processor(handler); try { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(9090); TServer server = new TThreadedSelectorServer( new TThreadedSelectorServer.Args(serverTransport).processor(processor)); System.out.println("Starting the server..."); server.serve(); } catch (TTransportException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception x) { x.printStackTrace(); } }
private static TServer getTHsHaServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, int workerThreads, int maxCallQueueSize, InetSocketAddress inetSocketAddress, ThriftMetrics metrics) throws TTransportException { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress); log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString()); THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); if (workerThreads > 0) { // Could support the min & max threads, avoiding to preserve existing functionality. serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads); } ExecutorService executorService = createExecutor( workerThreads, maxCallQueueSize, metrics); serverArgs.executorService(executorService); serverArgs.processor(processor); serverArgs.transportFactory(transportFactory); serverArgs.protocolFactory(protocolFactory); return new THsHaServer(serverArgs); }
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, int workerThreads, int selectorThreads, int maxCallQueueSize, InetSocketAddress inetSocketAddress, ThriftMetrics metrics) throws TTransportException { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress); log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString()); TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport); if (workerThreads > 0) { serverArgs.workerThreads(workerThreads); } if (selectorThreads > 0) { serverArgs.selectorThreads(selectorThreads); } ExecutorService executorService = createExecutor( workerThreads, maxCallQueueSize, metrics); serverArgs.executorService(executorService); serverArgs.processor(processor); serverArgs.transportFactory(transportFactory); serverArgs.protocolFactory(protocolFactory); return new TThreadedSelectorServer(serverArgs); }
public static TServer createThreadedSelectorServer(TProcessorFactory processorFactory, int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize) throws TTransportException { int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors()); int selectorThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2); TNonblockingServerTransport transport = new TNonblockingServerSocket(port, clientTimeoutMillisecs); TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize); TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport) .processorFactory(processorFactory).protocolFactory(protocolFactory) .transportFactory(transportFactory).workerThreads(numThreads) .acceptPolicy(AcceptPolicy.FAIR_ACCEPT).acceptQueueSizePerThread(10000) .selectorThreads(selectorThreads); args.maxReadBufferBytes = maxReadBufferSize; TThreadedSelectorServer server = new TThreadedSelectorServer(args); return server; }
public static void main(String [] args) throws TTransportException, IOException, InterruptedException { Properties port_cfg = new Properties(); InputStream input = new FileInputStream("../config.properties"); port_cfg.load(input); String port_str = port_cfg.getProperty("CA_PORT"); Integer port = Integer.valueOf(port_str); TProcessor proc = new LucidaService.AsyncProcessor( new CAServiceHandler.AsyncCAServiceHandler()); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .transportFactory(new TFramedTransport.Factory()); final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); System.out.println("CA at port " + port_str); server.serve(); }
/** * Entry point for question-answer. * @param args the argument list. Provide port numbers * for both sirius and qa. */ public static void main(String [] args) throws TTransportException, IOException, InterruptedException { Properties port_cfg = new Properties(); InputStream input = new FileInputStream("../../config.properties"); port_cfg.load(input); String port_str = port_cfg.getProperty("QA_PORT"); Integer port = Integer.valueOf(port_str); TProcessor proc = new LucidaService.AsyncProcessor( new QAServiceHandler.AsyncQAServiceHandler()); TNonblockingServerTransport transport = new TNonblockingServerSocket(port); TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport) .processor(proc) .protocolFactory(new TBinaryProtocol.Factory()) .transportFactory(new TFramedTransport.Factory()); final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments); System.out.println("QA at port " + port_str); server.serve(); }