- Forward


Thrift
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Purpose
Back SMYC Forward
  • Cross-Language Communications:
    • Abstract away from the portions of different languages that require the most customization
  • Remote Procedure Calls:
    • Define data types
    • Define service interfaces
    • Generate necessary code (e.g., stubs, skeletons)
History
Back SMYC Forward
  • Original Developer:
    • Facebook
  • Open Sourced:
    • April 2007
  • Now:
    • An Apache TPL
Types
Back SMYC Forward
  • Base Types:
    • bool
    • byte
    • i16, i32, i64 (i.e., 16,32, and 64 bit signed integers)
    • double (i.e., 64 bit floating point)
    • string
    • void (for return type)
  • Heterogeneous Structures/Records:
    • struct
    • exception
  • Homogeneous Collections:
    • list (i.e., ordered)
    • set (i.e., unordered)
    • map (i.e., with unique keys)
Services
Back SMYC Forward
  • Comparable To:
    • An interface in Java
    • A pure virtual method in C++
  • Syntax:
    •         service <name>
              {
                <returntype> <name>([<arguments>]...)
                [throws(<exception>...)]
              }
      	
  • Asynchronous Calls:
    • void functions can be declared async
Transport
Back SMYC Forward
  • Philosophy:
    • Abstract away from a specific protocol
    • Uses TSocket, TBufferedTransport, TFileTransport
  • Operations:
    • close()
    • flush()
    • isOpen()
    • open()
    • read()
    • write()
Protocol
Back SMYC Forward
  • Base Types:
    • read*() and write*() functions for all types
  • Structures, and Collections:
    • read*Begin() and read*End()
    • write*Begin() and write*End()
  • Messages:
    • writeMessageBegin(name, type, seq) and writeMessageEnd()
    • name, type, seq = readMessageBegin() and readMessageEnd()
Remote Procedure Calls
Back SMYC Forward
  • TProcessor:
    •         interface TProcessor 
              {
                  bool process(TProtocol in, TProtocol out) throws TException
              }
      	
  • On the Server Side:
    • Get TTransport from a TServerTransport
    • Use TTrasportFactory to "decorate" the TTransport
    • Create a protocol using TProtocolFactory
    • Call process() on the TProcessor
There's Always More to Learn
Back -