Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Apache Thrift 0.9.0

    Download button

    Downloads: 601  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Thrift Developers | More programs
    The Apache License 2.0 / FREE
    October 18th, 2012, 13:16 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Apache Thrift description

    Thrift Python Libraries

    Thrift is a software framework for scalable cross-language services development. Thrift combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.

    Originally developed at Facebook, Thrift was open sourced in April 2007 and entered the Apache Incubator in May, 2008.

    An Example

    Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.

    For instance, say you would like to write a service to store user objects for your web frontend. You could write a Thrift file as follows:

    struct UserProfile {
     1: i32 uid,
     2: string name,
     3: string blurb
    }
    service UserStorage {
     void store(1: UserProfile user),
     UserProfile retrieve(1: i32 uid)
    }


    Thrift does the heavy lifting. Instead of writing a load of boilerplate code to serialize and transport your objects and invoke remote methods, you can get right down to business. Here is some sample Python client code:

    # Make an object
    up = UserProfile(uid=1,
     name="Mark Slee",
     blurb="I'll find something to put here.")

    # Talk to a server via TCP sockets, using a binary protocol
    transport = TSocket.TSocket("localhost", 9090)
    transport.open()
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Use the service we already defined
    service = UserStorage.Client(protocol)
    service.store(up)

    # Retrieve something as well
    up2 = service.retrieve(2)


    Not much to it. Implementing the server as simple as filling in the blanks:

    class UserStorageHandler : virtual public UserStorageIf {
     public:
     UserStorageHandler() {
     // Your initialization goes here
     }

     void store(const UserProfile& user) {
     // Your implementation goes here
     printf("store\n");
     }

     void retrieve(UserProfile& _return, const int32_t uid) {
     // Your implementation goes here
     printf("retrieve\n");
     }
    };

    int main(int argc, char **argv) {
     int port = 9090;
     shared_ptr< UserStorageHandler > handler(new UserStorageHandler());
     shared_ptr< TProcessor > processor(new UserStorageProcessor(handler));
     shared_ptr< TServerTransport > serverTransport(new TServerSocket(port));
     shared_ptr< TTransportFactory > transportFactory(new TBufferedTransportFactory());
     shared_ptr< TProtocolFactory > protocolFactory(new TBinaryProtocolFactory());
     TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
     server.serve();
     return 0;
    }



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    Thrift library | Python library | Apache Thrift | Thrift | Python | library

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM