本文共 1937 字,大约阅读时间需要 6 分钟。
黄色部分是用户实现的业务逻辑
褐色部分是根据 Thrift 定义的服务接口描述文件生成的客户端和服务器端代码框架 红色部分是根据 Thrift 文件生成代码实现数据的读写操作 红色部分以下是 Thrift 的传输体系、协议以及底层 I/O 通信,使用 Thrift 可以很方便的自定义一个服务、传输协议和传输层。Thrift 服务器包含用于绑定协议和传输层的基础架构,它提供阻塞、非阻塞、单线程和多线程的模式运行在服务器上,可以配合服务器 / 容器一起运行,可以和现有的 J2EE 服务器 /Web 容器无缝的结合。
以PHP代码为例:
└── Thrift
├── Base │ └── TBase.php ├── ClassLoader │ └── ThriftClassLoader.php ├── Exception 异常类 │ ├── TApplicationException.php │ ├── TException.php │ ├── TProtocolException.php │ └── TTransportException.php ├── Factory │ ├── TBinaryProtocolFactory.php │ ├── TCompactProtocolFactory.php │ ├── TJSONProtocolFactory.php │ ├── TProtocolFactory.php │ ├── TStringFuncFactory.php │ └── TTransportFactory.php ├── Protocol(协议层),定义数据格式 │ ├── JSON │ │ ├── BaseContext.php │ │ ├── ListContext.php │ │ ├── LookaheadReader.php │ │ └── PairContext.php │ ├── SimpleJSON │ │ ├── CollectionMapKeyException.php │ │ ├── Context.php │ │ ├── ListContext.php │ │ ├── MapContext.php │ │ └── StructContext.php │ ├── TBinaryProtocolAccelerated.php │ ├── TBinaryProtocol.php 二进制格式 │ ├── TCompactProtocol.php 压缩格式 │ ├── TJSONProtocol.php json格式 │ ├── TMultiplexedProtocol.php │ ├── TProtocolDecorator.php │ ├── TProtocol.php │ └── TSimpleJSONProtocol.php ├── Serializer 序列化 │ └── TBinarySerializer.php ├── Server 服务器模式 │ ├── TForkingServer.php │ ├── TServer.php │ ├── TServerSocket.php │ ├── TServerTransport.php │ ├── TSimpleServer.php 简单的单线程服务模型,常用于测试 │ └── TSSLServerSocket.php ├── StringFunc │ ├── Core.php │ ├── Mbstring.php │ └── TStringFunc.php ├── TMultiplexedProcessor.php ├── Transport(传输层),定义数据传输方式, TCP/IP传输,内存共享或者文件共享等 │ ├── TBufferedTransport.php │ ├── TCurlClient.php │ ├── TFramedTransport.php 以frame为单位进行传输,非阻塞式方式 │ ├── THttpClient.php │ ├── TMemoryBuffer.php 将内存用于I/O │ ├── TNullTransport.php │ ├── TPhpStream.php │ ├── TSocket.php 阻塞式socket │ ├── TSocketPool.php │ ├── TSSLSocket.php │ └── TTransport.php └── Type 数据类型定义 ├── TConstant.php ├── TMessageType.php └── TType.php转载地址:http://tmuws.baihongyu.com/