Storm源码阅读(三):Thrift

Thrift指南:http://diwakergupta.github.io/thrift-missing-guide/

Defining Services

service Twitter {
    // A method definition looks like C code. It has a return type, arguments,
    void ping(),
 
    // The 'oneway' modifier indicates that the client only makes a request and does not wait for any response at all.
    oneway void zip()
}

 

在strom.thrift中找到

service Nimbus {

  void submitTopology(1: string name, 2: stringuploadedJarLocation, 3: string jsonConf, 4: StormTopology topology) throws (1:AlreadyAliveException e, 2: InvalidTopologyException ite);

  void killTopology(1: string name) throws (1:NotAliveException e);

  void activate(1: string name) throws (1:NotAliveException e);

 

  string beginFileUpload();

  void uploadChunk(1: string location, 2:binary chunk);

  void finishFileUpload(1: string location);

 

  // returns json

  string getNimbusConf();

 

  // stats functions

  ClusterSummary getClusterInfo();

  TopologyInfo getTopologyInfo(1: string id)throws (1: NotAliveException e);

 

  //returns json

  string getTopologyConf(1: string id) throws(1: NotAliveException e);

  StormTopology getTopology(1: string id)throws (1: NotAliveException e);

  StormTopology getUserTopology(1: string id)throws (1: NotAliveException e);

}

 

 

客户端:backtype.storm.generated.Nimbus的iface接口

服务器端:backtype.storm.daemon.nimbus.cljservice-handler (reify Nimbus$Iface

 

Thrift network stack:

 

The Transport layer provides a simpleabstraction for reading/writing from/to the network. This enables Thrift todecouple the underlying transport from the rest of the system(serialization/deserialization, for instance).

//org.apache.thrift7.transport.TTransport

 

The Protocol abstraction defines a mechanism tomap in-memory data structures to a wire-format. In other words, a protocolspecifies how datatypes use the underlying Transport to encode/decodethemselves.

//org.apache.thrift7.protocol.TProtocol接口

 

A Processor encapsulates the ability toread data from input streams and write to output streams. The input and outputstreams are represented by Protocol objects.

//org.apache.thrift7.TProcessor

public interfaceTProcessor{
    bool process(TProtocol in, TProtocol out)throws TException
}

 

Service-specific processor implementations aregeneratedby the compiler. The Processor essentially reads data from the wire (using theinput protocol),delegatesprocessing to thehandler(implemented by the user) and writes theresponseover the wire (using the output protocol).

 

A Server pullstogether all of the various features described above:

·        Create a transport

·        Create input/outputprotocols for the transport

·        Create a processorbased on the input/output protocols

·        Wait for incomingconnections and hand them off to the processor

 服务器端Server的代码:

(defnlaunch-server! [conf nimbus]

  (validate-distributed-mode! conf)

  (let[service-handler(service-handler confnimbus)

        options (->(TNonblockingServerSocket.(int(conf NIMBUS-THRIFT-PORT)))

 

                   (THsHaServer$Args.) //

                   (.workerThreads 64)->args.workerThreads

                    (.protocolFactory(TBinaryProtocol$Factory.))

                    (.processor(Nimbus$Processor. service-handler))

                   )

 

       server (THsHaServer. options)] ->newTHsHaServer(Args -> THsHaServer$Args)

 

 与网络栈的对应关系:

Server->THsHaServer

Processor -> Nimbus$Processor

Protocol ->TBinaryProtocol

Transport -> TNonblockingServerSocket


参考文档:

Thrift指南:http://diwakergupta.github.io/thrift-missing-guide/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值