当前位置: 首页>>代码示例>>Java>>正文


Java ThriftClientPool类代码示例

本文整理汇总了Java中com.github.ddth.thriftpool.ThriftClientPool的典型用法代码示例。如果您正苦于以下问题:Java ThriftClientPool类的具体用法?Java ThriftClientPool怎么用?Java ThriftClientPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ThriftClientPool类属于com.github.ddth.thriftpool包,在下文中一共展示了ThriftClientPool类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
private static void runTest(final int numRuns, final int numThreads) throws TTransportException {
    final ThriftClientPool<TIdService.Client, TIdService.Iface> pool = clientPool("localhost",
            9090);

    BenchmarkResult result = new Benchmark(new Operation() {
        @Override
        public void run(int runId) {
            try {
                TIdService.Iface client = pool.borrowObject();
                try {
                    client.ping2();
                } finally {
                    pool.returnObject(client);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, numRuns, numThreads).run();
    System.out.println(result.summarize());

    pool.destroy();
}
 
开发者ID:btnguyen2k,项目名称:id-server,代码行数:24,代码来源:QndBenchmarkThriftClientPing2.java

示例2: runTest

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
private static void runTest(final int numRuns, final int numThreads) throws TTransportException {
    final ThriftClientPool<TIdService.Client, TIdService.Iface> pool = clientPool("localhost",
            9090);

    BenchmarkResult result = new Benchmark(new Operation() {
        @Override
        public void run(int runId) {
            try {
                TIdService.Iface client = pool.borrowObject();
                try {
                    client.ping();
                } finally {
                    pool.returnObject(client);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, numRuns, numThreads).run();
    System.out.println(result.summarize());

    pool.destroy();
}
 
开发者ID:btnguyen2k,项目名称:id-server,代码行数:24,代码来源:QndBenchmarkThriftClientPing.java

示例3: init

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ThriftIdClient init() {
    super.init();

    final int timeout = 10000;
    thriftClientPool = new ThriftClientPool<TIdService.Client, TIdService.Iface>();
    thriftClientPool.setClientClass(TIdService.Client.class).setClientInterface(
            TIdService.Iface.class);
    thriftClientPool.setTProtocolFactory(protocolFactory(idServerHost, idServerPort, timeout));
    thriftClientPool.setPoolConfig(new PoolConfig().setMaxActive(32).setMaxWaitTime(timeout));
    thriftClientPool.init();

    return this;
}
 
开发者ID:btnguyen2k,项目名称:id-jclient,代码行数:18,代码来源:ThriftIdClient.java

示例4: clientPool

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
protected static ThriftClientPool<TIdService.Client, TIdService.Iface> clientPool(
        final String host, final int port) {
    final ThriftClientPool<TIdService.Client, TIdService.Iface> pool = new ThriftClientPool<TIdService.Client, TIdService.Iface>();
    pool.setClientClass(TIdService.Client.class).setClientInterface(TIdService.Iface.class);
    pool.setTProtocolFactory(protocolFactory(host, port));
    pool.setPoolConfig(new PoolConfig().setMaxActive(8192).setMaxWaitTime(10000));
    pool.init();
    return pool;
}
 
开发者ID:btnguyen2k,项目名称:id-server,代码行数:10,代码来源:BaseQndThriftClient.java

示例5: runTest

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
private static void runTest(final int numRuns, final int numThreads, final int numNamespaces,
        final String engine) throws TTransportException {
    final ThriftClientPool<TIdService.Client, TIdService.Iface> pool = clientPool("localhost",
            9090);

    BenchmarkResult result = new Benchmark(new Operation() {
        @Override
        public void run(int runId) {
            String namespace = String.valueOf(runId % numNamespaces);
            try {
                TIdService.Iface client = pool.borrowObject();
                try {
                    TIdResponse id = client.nextId(namespace, engine);
                    if (id.status != 200) {
                        System.out.println(id);
                    }
                } finally {
                    pool.returnObject(client);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, numRuns, numThreads).run();
    System.out.println("[" + engine + "]:\t" + result.summarize());

    pool.destroy();
}
 
开发者ID:btnguyen2k,项目名称:id-server,代码行数:29,代码来源:QndBenchmarkThriftClientSnowflake.java

示例6: main

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    ITProtocolFactory protocolFactory = new AbstractTProtocolFactory(SCRIBE_HOST + ":"
            + SCRIBE_HOST) {
        @Override
        protected TProtocol create(HostAndPort hostAndPort) {
            TTransport transport = new TFramedTransport(new TSocket(hostAndPort.host,
                    hostAndPort.port));
            TProtocol protocol = new TBinaryProtocol(transport);
            return protocol;
        }
    };

    ThriftClientPool<scribe.Client, scribe.Iface> pool = new ThriftClientPool<scribe.Client, scribe.Iface>();
    PoolConfig poolConfig = new PoolConfig();
    poolConfig.setMaxActive(1).setMaxIdle(0).setMinIdle(0);
    pool.setClientClass(scribe.Client.class).setClientInterface(scribe.Iface.class)
            .setPoolConfig(poolConfig);
    pool.setTProtocolFactory(protocolFactory);
    pool.init();

    scribe.Iface client = pool.borrowObject();
    try {
        System.out.println("Name:\t\t" + client.getName());
        System.out.println("Version:\t" + client.getVersion());
        System.out.println("Status:\t\t" + client.getStatus());
        System.out.println("Alive since:\t" + client.aliveSince());
        System.out.println("Options:\t" + client.getOptions());
        System.out.println("Counters:\t" + client.getCounters());
    } finally {
        pool.returnObject(client);
    }

    pool.destroy();
}
 
开发者ID:DDTH,项目名称:ddth-thriftpool,代码行数:35,代码来源:QndScribeClient2.java

示例7: main

import com.github.ddth.thriftpool.ThriftClientPool; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    ITProtocolFactory protocolFactory = new ITProtocolFactory() {
        @Override
        public TProtocol create(int hash) {
            TTransport transport = new TFramedTransport(new TSocket(SCRIBE_HOST, SCRIBE_PORT));
            TProtocol protocol = new TBinaryProtocol(transport);
            return protocol;
        }

        @Override
        public int getNumServers() {
            return 1;
        }
    };

    ThriftClientPool<scribe.Client, scribe.Iface> pool = new ThriftClientPool<scribe.Client, scribe.Iface>();
    PoolConfig poolConfig = new PoolConfig();
    poolConfig.setMaxActive(1).setMaxIdle(0).setMinIdle(0);
    pool.setClientClass(scribe.Client.class).setClientInterface(scribe.Iface.class)
            .setPoolConfig(poolConfig);
    pool.setTProtocolFactory(protocolFactory);
    pool.init();

    scribe.Iface client = pool.borrowObject();
    try {
        System.out.println("Name:\t\t" + client.getName());
        System.out.println("Version:\t" + client.getVersion());
        System.out.println("Status:\t\t" + client.getStatus());
        System.out.println("Alive since:\t" + client.aliveSince());
        System.out.println("Options:\t" + client.getOptions());
        System.out.println("Counters:\t" + client.getCounters());
    } finally {
        pool.returnObject(client);
    }

    pool.destroy();
}
 
开发者ID:DDTH,项目名称:ddth-thriftpool,代码行数:38,代码来源:QndScribeClient.java


注:本文中的com.github.ddth.thriftpool.ThriftClientPool类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。