Java 类org.apache.thrift.TServiceClientFactory 实例源码

项目:albedo-thrift    文件:ThriftServiceClientProxyFactory.java   
@Override
    public void afterPropertiesSet() throws Exception {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        // 加载Iface接口
        objectClass = classLoader.loadClass(serverAddressProvider.getService() + "$Iface");
        // 加载Client.Factory类
        Class<TServiceClientFactory<TServiceClient>> fi =
                (Class<TServiceClientFactory<TServiceClient>>) classLoader.
                        loadClass(serverAddressProvider.getService() + "$Client$Factory");
        TServiceClientFactory<TServiceClient> clientFactory = fi.newInstance();

        ThriftClientPoolFactory clientPool = new ThriftClientPoolFactory(serverAddressProvider,
                clientFactory, callback);
        pool = new GenericObjectPool<TServiceClient>(clientPool, makePoolConfig());

//        InvocationHandler handler = makeProxyHandler();//方式1
        InvocationHandler handler = makeProxyHandler2();//方式2
        proxyClient = Proxy.newProxyInstance(classLoader, new Class[] { objectClass }, handler);
    }
项目:albedo-thrift    文件:ProxyFactoryBean.java   
@Override
public T getObject() throws Exception {

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    Server server = serverManager.getService(innerClass.getName());

    // 加载Iface接口
    innerClass = classLoader.loadClass(server.getName());
    String temp = server.getName().replace("$Iface", "");
    // 加载Client.Factory类
    Class<TServiceClientFactory<TServiceClient>> fi =
            (Class<TServiceClientFactory<TServiceClient>>) classLoader.
                    loadClass(temp + "$Client$Factory");
    TServiceClientFactory<TServiceClient> clientFactory = fi.newInstance();

    ThriftClientPoolFactory clientPool =
            new ThriftClientPoolFactory(server,
                    clientFactory, callback, proccessName);
    pool = new GenericObjectPool<TServiceClient>(clientPool, makePoolConfig());

    ServiceProxy serviceProxy = new ServiceProxy(pool);

    return (T)Proxy.newProxyInstance(innerClass.getClassLoader(),new Class[]{innerClass}, serviceProxy);

}
项目:CodeCheckerEclipsePlugin    文件:ThriftTransportFactory.java   
/**
 * Creates a client based on the TypeToken pointing to a Thrift interface class.
 *
 * This method uses black magic, based on the structure and names of generated
 * cc.ecl.action.thrift classes. If that changes, this here breaks.
 *
 * @throws TTransportException    if transport creation fails (e.g. timeout)
 * @throws ThriftFactoryException if factory creation fails (probably bad ifaceType parameter,
 *                                or Thrift internals changed)
 */
@Override
public <IFaceT> IFaceT initializeClient(String url, TypeToken<IFaceT> ifaceType) throws
        TTransportException, ThriftFactoryException {

    // assume same class loader
    ClassLoader classLoader = ifaceType.getRawType().getClassLoader();
    String factoryName = ifaceType.toString().replace("Iface", "Client$Factory");

    try {

        if (!clientFactoryMappings.containsKey(ifaceType)) {
            clientFactoryMappings.put(ifaceType, (TServiceClientFactory<?>) classLoader
                    .loadClass(factoryName).newInstance());
        }
    } catch (Exception e) {
        throw new RuntimeException("IllegalAccessException while initializing: " +
                factoryName, e);
    }

    return (IFaceT) clientFactoryMappings.get(ifaceType).getClient(requestTransport(url));
}
项目:albedo-thrift    文件:ThriftClientPoolFactory.java   
public ThriftClientPoolFactory(Server server, TServiceClientFactory<TServiceClient> clientFactory,
                               PoolOperationCallBack callback, String proccessName) throws Exception {
    this.server = server;
    this.clientFactory = clientFactory;
    this.callback = callback;
    this.proccessName = proccessName;
}
项目:albedo-thrift    文件:ThriftClientPoolFactory.java   
protected ThriftClientPoolFactory(ThriftServerAddressProvider addressProvider, TServiceClientFactory<TServiceClient> clientFactory) throws Exception {
    this.serverAddressProvider = addressProvider;
    this.clientFactory = clientFactory;
}
项目:albedo-thrift    文件:ThriftClientPoolFactory.java   
protected ThriftClientPoolFactory(ThriftServerAddressProvider addressProvider, TServiceClientFactory<TServiceClient> clientFactory,
                                  PoolOperationCallBack callback) throws Exception {
    this.serverAddressProvider = addressProvider;
    this.clientFactory = clientFactory;
    this.callback = callback;
}