Thrift 非阻塞异步I/O例子
来源:互联网 发布:被x是什么体验 知乎 编辑:程序博客网 时间:2024/05/29 17:59
Thrift支持多路复用I/O通信模型。需要客户端和服务端同时采用异步I/O模型。
HelloService.thrift
namespace java thriftservice HelloService { string sayHello(1:string name)}
服务器端代码:
import org.apache.thrift.TProcessor;import org.apache.thrift.server.THsHaServer;import org.apache.thrift.transport.TNonblockingServerSocket;public class ThriftAsyncServer {public static void main(String[] args) throws Exception {TNonblockingServerSocket transport = new TNonblockingServerSocket(1001);TProcessor processor = new HelloService.Processor<HelloServiceHandler>(new HelloServiceHandler());THsHaServer server = new THsHaServer(new THsHaServer.Args(transport).processor(processor));server.serve();}}
客户端代码:
import org.apache.thrift.async.AsyncMethodCallback;import org.apache.thrift.async.TAsyncClientManager;import org.apache.thrift.protocol.TBinaryProtocol;import org.apache.thrift.protocol.TProtocolFactory;import org.apache.thrift.transport.TNonblockingSocket;public class ThriftAsyncClient {public static void main(String[] args) throws Exception {TNonblockingSocket socket = new TNonblockingSocket("127.0.0.1", 1001);TAsyncClientManager clientManager = new TAsyncClientManager();TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();HelloService.AsyncClient client = new HelloService.AsyncClient(protocolFactory , clientManager, socket);client.sayHello("Andy", new AsyncMethodCallback<String>() {@Overridepublic void onError(Exception e) {e.printStackTrace();}@Overridepublic void onComplete(String response) {System.out.println("Response: " + response);}});Thread.sleep(1000);socket.close();}}
阅读全文
0 0
- Thrift 非阻塞异步I/O例子
- 同步异步阻塞非阻塞I/O
- I/O 阻塞&非阻塞&同步&异步
- 网络I/O中的阻塞,非阻塞,同步,异步的两个例子讲解
- 一个非阻塞I/O的例子
- 同步I/O(阻塞I/O),异步I/O(非阻塞)
- 阻塞与非阻塞I/O,I/O复用,同步和异步I/O
- 对I/O阻塞、非阻塞;同步I/O、异步I/O的理解
- I/O 同步,异步,阻塞,非阻塞问题
- Windows I/O模型、同步/异步、阻塞/非阻塞
- unix下的I/O------阻塞,非阻塞,同步,异步
- Windows I/O模型、同步/异步、阻塞/非阻塞
- Windows I/O模型、同步/异步、阻塞/非阻塞
- I/O模型:阻塞、非阻塞 & 同步、异步
- Windows I/O模型、同步/异步、阻塞/非阻塞
- I/O模型:阻塞、非阻塞 & 同步、异步
- Unix下的I/O------阻塞,非阻塞,同步,异步
- Windows I/O模型、同步/异步、阻塞/非阻塞
- 文件深度遍历以及删除
- Jsoncpp数据交互文本格式
- ORACLE生成邀请码
- Redis 安装
- eclipse写java代码想后移代码按空格就把后面内容删除了 解决方法
- Thrift 非阻塞异步I/O例子
- Windows下如何构建和发布Python模块
- eclipse里程序左边项目列表消失解决办法
- NZT使用教程
- 腾讯手游如何提早揭露游戏外挂风险?
- 围观探讨:香港验血测不到y就是女孩吗?-----香港戴学良医生
- StatusBarUtil 状态栏工具类(实现沉浸式状态栏/变色状态栏)
- DPM,windows环境搭建测试
- 国内的机器学习几个人