protected TServer getTNonBlockingServer(TNonblockingServerTransport serverTransport, TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress 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); }
@Override protected void waitForShutdown() { joinSelector(); }
/** * Begin accepting connections and processing invocations. */ public void serve() { // start listening, or exit if (!startListening()) { return; } // start the selector, or exit if (!startSelectorThread()) { return; } // this will block while we serve joinSelector(); // do a little cleanup stopListening(); }
public static void main(String[] args) throws TException{ //处理器 TProcessor processor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl()); // 传输通道 - 非阻塞方式 TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(SERVER_PORT); //异步IO,需要使用TFramedTransport,它将分块缓存读取。 TNonblockingServer.Args tArgs = new TNonblockingServer.Args(serverTransport); tArgs.processor(processor); // 使用非阻塞式IO,服务端和客户端需要指定TFramedTransport数据传输的方式 tArgs.transportFactory(new TFramedTransport.Factory()); //使用高密度二进制协议 tArgs.protocolFactory(new TCompactProtocol.Factory()); TNonblockingServer server = new TNonblockingServer(tArgs); System.out.println("HelloTNonblockingServer start...."); server.serve(); } }
/** * Do the work required to read from a readable client. If the frame is * fully read, then invoke the method call. */ private void handleRead(SelectionKey key) { FrameBuffer buffer = (FrameBuffer)key.attachment(); if (buffer.read()) { // if the buffer's frame read is complete, invoke the method. if (buffer.isFrameFullyRead()) { requestInvoke(buffer); } } else { cleanupSelectionkey(key); } }
/** * When this FrameBuffer needs to change it's select interests and execution * might not be in the select thread, then this method will make sure the * interest change gets done when the select thread wakes back up. When the * current thread is the select thread, then it just does the interest change * immediately. */ private void requestSelectInterestChange() { if (Thread.currentThread() == selectThread_) { changeSelectInterests(); } else { TNonblockingServer.this.requestSelectInterestChange(this); } } } // FrameBuffer
/** * Begin accepting connections and processing invocations. */ public void serve() { // start listening, or exit if (!startListening()) { return; } // start the selector, or exit if (!startSelectorThread()) { return; } // this will block while we serve joinSelector(); // do a little cleanup stopListening(); }
/** * Do the work required to read from a readable client. If the frame is * fully read, then invoke the method call. */ private void handleRead(SelectionKey key) { FrameBuffer buffer = (FrameBuffer)key.attachment(); if (!buffer.read()) { cleanupSelectionkey(key); return; } // if the buffer's frame read is complete, invoke the method. if (buffer.isFrameFullyRead()) { if (!requestInvoke(buffer)) { cleanupSelectionkey(key); } } }
/** * When this FrameBuffer needs to change it's select interests and execution * might not be in the select thread, then this method will make sure the * interest change gets done when the select thread wakes back up. When the * current thread is the select thread, then it just does the interest change * immediately. */ private void requestSelectInterestChange() { if (Thread.currentThread() == selectThread_) { changeSelectInterests(); } else { TNonblockingServer.this.requestSelectInterestChange(this); } } } // FrameBuffer
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); }
/** * Begin accepting connections and processing invocations. */ public void serve() { // start listening, or exit if (!startListening()) { return; } // start the selector, or exit if (!startSelectorThread()) { return; } // this will block while we serve joinSelector(); // do a little cleanup stopListening(); }
/** * Do the work required to read from a readable client. If the frame is * fully read, then invoke the method call. */ private void handleRead(SelectionKey key) { FrameBuffer buffer = (FrameBuffer)key.attachment(); if (!buffer.read()) { cleanupSelectionkey(key); return; } // if the buffer's frame read is complete, invoke the method. if (buffer.isFrameFullyRead()) { if (!requestInvoke(buffer)) { cleanupSelectionkey(key); } } }
/** * When this FrameBuffer needs to change it's select interests and execution * might not be in the select thread, then this method will make sure the * interest change gets done when the select thread wakes back up. When the * current thread is the select thread, then it just does the interest change * immediately. */ private void requestSelectInterestChange() { if (Thread.currentThread() == selectThread_) { changeSelectInterests(); } else { TNonblockingServer.this.requestSelectInterestChange(this); } } } // FrameBuffer
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); }
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); }
throw new RpcException("Fail to create thrift server(" + url + ") due to null args"); final TServer thriftServer = new TNonblockingServer(tArgs);
throw new RpcException("Fail to create thrift server(" + url + ") due to null args"); final TServer thriftServer = new TNonblockingServer(tArgs);
public void run() { try { Class Processor = Class.forName(getServiceInterface() + "$Processor"); Class Iface = Class.forName(StringUtils.hasText(getServiceIface()) ? getServiceIface() : getServiceInterface() + "$Iface"); Constructor constructor = Processor.getConstructor(Iface); TProcessor processor = (TProcessor) constructor.newInstance(serviceImplObject); TNonblockingServerSocket transport = new TNonblockingServerSocket(getPort()); TNonblockingServer.Args tArgs = new TNonblockingServer.Args(transport); tArgs.processor(processor); tArgs.protocolFactory(new TCompactProtocol.Factory()); tArgs.transportFactory(new TFramedTransport.Factory()); TServer server = new TNonblockingServer(tArgs); logger.info(serviceInterface + "服务启动成功,端口:" + getPort()); server.serve(); } catch (TTransportException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }.start();
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(); }
.transportFactory(transportFactory) .protocolFactory(protocolFactory); tserver = new TNonblockingServer(serverArgs); } else if (implType == ImplType.HS_HA) { THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);