private THsHaServer initHandlerServer(Map conf, final Drpc service) throws Exception { int port = JStormUtils.parseInt(conf.get(Config.DRPC_PORT)); int workerThreadNum = JStormUtils.parseInt(conf.get(Config.DRPC_WORKER_THREADS)); int queueSize = JStormUtils.parseInt(conf.get(Config.DRPC_QUEUE_SIZE)); LOG.info("Begin to init DRPC handler server at port: " + port); TNonblockingServerSocket socket = new TNonblockingServerSocket(port); THsHaServer.Args targs = new THsHaServer.Args(socket); targs.workerThreads(64); targs.protocolFactory(new TBinaryProtocol.Factory()); targs.processor(new DistributedRPC.Processor<DistributedRPC.Iface>(service)); ThreadPoolExecutor executor = new ThreadPoolExecutor( workerThreadNum, workerThreadNum, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize)); targs.executorService(executor); THsHaServer handlerServer = new THsHaServer(targs); LOG.info("Successfully inited DRPC handler server at port: " + port); return handlerServer; }
protected TServer getTHsHaServer(TNonblockingServerTransport serverTransport, TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) { LOG.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString()); THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport); int queueSize = conf.getInt(TBoundedThreadPoolServer.MAX_QUEUED_REQUESTS_CONF_KEY, TBoundedThreadPoolServer.DEFAULT_MAX_QUEUED_REQUESTS); CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(queueSize), metrics); int workerThread = conf.getInt(TBoundedThreadPoolServer.MAX_WORKER_THREADS_CONF_KEY, serverArgs.getMaxWorkerThreads()); ExecutorService executorService = createExecutor( callQueue, workerThread, workerThread); serverArgs.executorService(executorService).processor(processor) .transportFactory(transportFactory).protocolFactory(protocolFactory); return new THsHaServer(serverArgs); }
private THsHaServer initInvokeServer(Map conf, final Drpc service) throws Exception { int port = JStormUtils.parseInt(conf.get(Config.DRPC_INVOCATIONS_PORT)); LOG.info("Begin to init DRPC invoke server at port: " + port); TNonblockingServerSocket socket = new TNonblockingServerSocket(port); THsHaServer.Args targsInvoke = new THsHaServer.Args(socket); targsInvoke.workerThreads(64); targsInvoke.protocolFactory(new TBinaryProtocol.Factory()); targsInvoke.processor(new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service)); THsHaServer invokeServer = new THsHaServer(targsInvoke); LOG.info("Successfully inited DRPC invoke server at port: " + port); return invokeServer; }
callQueue, serverArgs.getWorkerThreads()); serverArgs.executorService(executorService) .processor(processor) .transportFactory(transportFactory) .protocolFactory(protocolFactory);
args.processor(processor);
serverArgs.processor(processor); serverArgs.maxReadBufferBytes = config.getThriftMaxReadBufferBytes();
public void start() { log.info("启动更新索引服务!"); try { Inet4Address inet4Address = (Inet4Address) Inet4Address.getByName(ip); InetSocketAddress socketAddress = new InetSocketAddress(inet4Address, port); TNonblockingServerSocket socket = new TNonblockingServerSocket(socketAddress, 30000); Processor<AdminServiceImpl> processor = new Processor<AdminServiceImpl>(this); THsHaServer.Args args = new THsHaServer.Args(socket); args.processor(processor); args.protocolFactory(new TBinaryProtocol.Factory()); args.transportFactory(new TFramedTransport.Factory()); server = new THsHaServer(args); executor.execute(new Runnable() { @Override public void run() { server.serve(); } }); } catch (Exception e) { log.error(e.getMessage(), e); } }
private InetSocketAddress startServer() throws TTransportException { if (env.getConfiguration().containsKey(FluoConfigurationImpl.ORACLE_PORT_PROP)) { port = env.getConfiguration().getInt(FluoConfigurationImpl.ORACLE_PORT_PROP); Preconditions.checkArgument(port >= 1 && port <= 65535, FluoConfigurationImpl.ORACLE_PORT_PROP + " must be valid port (1-65535)"); } else { port = PortUtils.getRandomFreePort(); } InetSocketAddress addr = new InetSocketAddress(port); TNonblockingServerSocket socket = new TNonblockingServerSocket(addr); THsHaServer.Args serverArgs = new THsHaServer.Args(socket); TProcessor processor = new OracleService.Processor<OracleService.Iface>(this); serverArgs.processor(processor); serverArgs.maxReadBufferBytes = ORACLE_MAX_READ_BUFFER_BYTES; serverArgs.inputProtocolFactory(new TCompactProtocol.Factory()); serverArgs.outputProtocolFactory(new TCompactProtocol.Factory()); server = new THsHaServer(serverArgs); Runnable st = new Runnable() { @Override public void run() { server.serve(); } }; serverThread = new Thread(st); serverThread.setDaemon(true); serverThread.start(); return addr; }
public void start() { log.info("启动更新索引服务!"); try { Inet4Address inet4Address = (Inet4Address) Inet4Address.getByName(ip); InetSocketAddress socketAddress = new InetSocketAddress(inet4Address, port); TNonblockingServerSocket socket = new TNonblockingServerSocket(socketAddress, 30000); Processor<UpdateServiceImpl> processor = new Processor<UpdateServiceImpl>(this); THsHaServer.Args args = new THsHaServer.Args(socket); args.processor(processor); args.protocolFactory(new TBinaryProtocol.Factory()); args.transportFactory(new TFramedTransport.Factory()); server = new THsHaServer(args); executor.execute(new Runnable() { @Override public void run() { server.serve(); } }); } catch (Exception e) { log.error(e.getMessage(), e); } }
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 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); }
/** * start serving the thrift server. doesn't return. * * @throws IOException * @throws TException */ private void serve() throws IOException, TException { // set up the service handler HankSmartClient handler = new HankSmartClient(coordinator, ringGroupName); // launch the thrift server TNonblockingServerSocket serverSocket = new TNonblockingServerSocket(configurator.getPortNumber()); Args options = new THsHaServer.Args(serverSocket); options.processor(new SmartClient.Processor(handler)); options.workerThreads(configurator.getNumThreads()); options.protocolFactory(new TCompactProtocol.Factory()); server = new THsHaServer(options); server.serve(); }
public static void main(String[] args) throws TException{ TProcessor processor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl()); // 传输通道 - 非阻塞方式 TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(SERVER_PORT); //半同步半异步 THsHaServer.Args tArgs = new THsHaServer.Args(serverTransport); tArgs.processor(processor); tArgs.transportFactory(new TFramedTransport.Factory()); //二进制协议 tArgs.protocolFactory(new TBinaryProtocol.Factory()); THsHaServer server = new THsHaServer(tArgs); System.out.println("HelloTHsHaServer start...."); server.serve(); } }
private static TServer getTHsHaServer(TProtocolFactory protocolFactory, THBaseService.Processor processor, TTransportFactory transportFactory, 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); ExecutorService executorService = createExecutor( serverArgs.getWorkerThreads(), metrics); serverArgs.executorService(executorService); serverArgs.processor(processor); serverArgs.transportFactory(transportFactory); serverArgs.protocolFactory(protocolFactory); return new THsHaServer(serverArgs); }
public static void startRPCServer4(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); THsHaServer.Args args = new THsHaServer.Args(serverTransport); args.processor(processor); args.protocolFactory(new TBinaryProtocol.Factory()); args.transportFactory(new TFramedTransport.Factory()); TServer server = new THsHaServer(args); LOG.info("leaf RPCServer(type:THsHaServer) start at ip:port : "+ ip +":" + port ); server.serve(); }
CalculatorHandler handler = new CalculatorHandler(); Calculator.Processor processor = new Calculator.Processor(handler); TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(9090); THsHaServer.Args args = new THsHaServer.Args(serverTransport); args.processor(processor); args.transportFactory(new TFramedTransport.Factory()); TServer server = new THsHaServer(args); server.serve();
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.minWorkerThreads(workers); args.maxWorkerThreads(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 public TServer getServer(TProcessor processor) throws IOException, TTransportException { int port = type.getPort(storm_conf); TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port); int numWorkerThreads = type.getNumThreads(storm_conf); int maxBufferSize = type.getMaxBufferSize(storm_conf); Integer queueSize = type.getQueueSize(storm_conf); THsHaServer.Args server_args = new THsHaServer.Args(serverTransport).processor(new SimpleWrapProcessor(processor)).workerThreads(numWorkerThreads) .protocolFactory(new TBinaryProtocol.Factory(false, true, maxBufferSize, -1)); if (queueSize != null) { server_args.executorService(new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize))); } // construct THsHaServer return new THsHaServer(server_args); }
@SuppressWarnings("rawtypes") private void initThrift(Map conf) throws TTransportException { Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT)); TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port); Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE)); THsHaServer.Args args = new THsHaServer.Args(socket); args.workerThreads(ServiceHandler.THREAD_NUM); args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1)); args.processor(new Nimbus.Processor<Iface>(serviceHandler)); args.maxReadBufferBytes = maxReadBufSize; thriftServer = new THsHaServer(args); LOG.info("Successfully started nimbus: started Thrift server..."); thriftServer.serve(); }