Giter Club home page Giter Club logo

ethiftpool's Introduction

eThriftpool

Connection pool for facebook-thrift

eThriftPool can be used with any thrift client in your application, it use plain TSocket or TFrameTransport instead off pooling connection with pre-defined protocol.

Prerequisites:
  • Java 1.7 (1.6 is not tested)
  • Apache Common pool
  • Thrift library

Usage: For example, you define your thrift application like this:

service PlusMe {
    i32 plusMe(1:i32 a1, 2: i32 a2),
}

Save to file name plusme.thrift. Gen java code using command: $ thrift --gen java plusme.thrift

Import gen files to your netbeans/eclipse application and use it as following

Java Code

import com.ethicconsultant.thriftpool.GenericConnectionProvider;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TTransport;

public class Test {

    private static TTransport connection;

    public static int Test() {
        try {
            GenericConnectionProvider genericConnectionProvider =  GenericConnectionProvider.getInstance("127.0.0.1", 9999);
            connection = genericConnectionProvider.getConnection(true);
            TProtocol protocol = new TBinaryProtocol(connection);
            PlusMe.Client client = new PlusMe.Client(protocol);
            return client.plusMe(1, 2);
        } catch (TException ex) {
            connection = null;
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
            return -1;
        }
    }

    public static void main(String[] args) {
        try {
            for (int i = 0; i <= 2; i++) {
                System.out.println(Test());
            }
        } catch (Exception ex) {
            Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
License

Do whatever you want

ethiftpool's People

Contributors

whatvn avatar

Watchers

gspripple avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.