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


Java ExchangeClient类代码示例

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


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

示例1: testClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Test
public void testClient() throws Throwable {
    // 读取参数
    if (PerformanceUtils.getProperty("server", null) == null) {
        logger.warn("Please set -Dserver=127.0.0.1:9911");
        return;
    }
    final String server = System.getProperty("server", "127.0.0.1:9911");
    final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
    final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
    final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
    int sleep = PerformanceUtils.getIntProperty("sleep", 60*1000*60);
    
    final String url = "exchange://" + server + "?transporter=" + transporter + "&serialization=" + serialization + "&timeout=" + timeout;
    ExchangeClient exchangeClient =initClient(url);
    Thread.sleep(sleep);
    closeClient(exchangeClient);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:19,代码来源:ChanelHandlerTest.java

示例2: getClients

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
private ExchangeClient[] getClients(URL url){
    //是否共享连接
    boolean service_share_connect = false;
    int connections = url.getParameter(Constants.CONNECTIONS_KEY, 0);
    //如果connections不配置,则共享连接,否则每服务每连接
    if (connections == 0){
        service_share_connect = true;
        connections = 1;
    }
    
    ExchangeClient[] clients = new ExchangeClient[connections];
    for (int i = 0; i < clients.length; i++) {
        if (service_share_connect){
            clients[i] = getSharedClient(url);
        } else {
            clients[i] = initClient(url);
        }
    }
    return clients;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:DubboProtocol.java

示例3: getSharedClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
/**
     *获取共享连接 
     */
    private ExchangeClient getSharedClient(URL url){
        String key = url.getAddress();
        ReferenceCountExchangeClient client = referenceClientMap.get(key);
        if ( client != null ){
            if ( !client.isClosed()){
                client.incrementAndGetCount();
                return client;
            } else {
//                logger.warn(new IllegalStateException("client is closed,but stay in clientmap .client :"+ client));
                referenceClientMap.remove(key);
            }
        }
        ExchangeClient exchagneclient = initClient(url);
        
        client = new ReferenceCountExchangeClient(exchagneclient, ghostClientMap);
        referenceClientMap.put(key, client);
        ghostClientMap.remove(key);
        return client; 
    }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:23,代码来源:DubboProtocol.java

示例4: getClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
private ExchangeClient getClient(Invoker<?> invoker){
    if (invoker.getUrl().getParameter(Constants.CONNECTIONS_KEY, 1) == 1){
        return getInvokerClient(invoker);
    } else {
        ReferenceCountExchangeClient client = getReferenceClient(invoker);
        try {
            Field clientField = ReferenceCountExchangeClient.class.getDeclaredField("client");
            clientField.setAccessible(true);
            return (ExchangeClient) clientField.get(client);
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:ReferenceCountExchangeClientTest.java

示例5: isAvailable

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Override
public boolean isAvailable() {

    if (!super.isAvailable()) {
        return false;
    }

    for (ExchangeClient client : clients){
        if (client.isConnected()
                && !client.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY)){
            //cannot write == not Available ?
            return true ;
        }
    }
    return false;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:ThriftInvoker.java

示例6: testExport

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());

    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class,
            newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
    
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:RegistryProtocolTest.java

示例7: testExport

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());

    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class,
            newRegistryUrl, new ExchangeClient[]{new MockedClient("10.20.20.20", 2222, true)});
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();

}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:20,代码来源:RegistryProtocolTest.java

示例8: getExchangeChannel

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Override
public ExchangeChannel getExchangeChannel(InetSocketAddress remoteAddress) {
    String host = remoteAddress.getAddress() != null ? remoteAddress.getAddress().getHostAddress() : remoteAddress.getHostName();
    int port = remoteAddress.getPort();
    ExchangeChannel channel = super.getExchangeChannel(remoteAddress);
    if (channel == null) {
        for (Map.Entry<URL, ExchangeClient> entry : clients.entrySet()) {
            URL url = entry.getKey();
            if (url.getIp().equals(host) && url.getPort() == port) {
                return entry.getValue();
            }
        }
    }
    return channel;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:ExchangeServerPeer.java

示例9: connect

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
protected Client connect(URL url) throws RemotingException {
    if (servers.containsKey(url)) {
        return null;
    }
    ExchangeClient client = clients.get(url);
    if (client == null) { // TODO 有并发间隙
        client = Exchangers.connect(url, dispatcher);
        clients.put(url, client);
    }
    return client;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:12,代码来源:AbstractExchangeGroup.java

示例10: initClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
public static  ExchangeClient initClient(String url){
    // 创建客户端
    ExchangeClient exchangeClient  = null;
    PeformanceTestHandler handler = new PeformanceTestHandler(url);
    boolean run = true;
    while(run){
        try{
            exchangeClient= Exchangers.connect(url,handler);
        } catch (Throwable t){
            
            if(t!=null && t.getCause()!=null && t.getCause().getClass()!=null && (t.getCause().getClass()==java.net.ConnectException.class 
                    || t.getCause().getClass()== java.net.ConnectException.class)){
                
            }else {
                t.printStackTrace();
            }
            
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (exchangeClient != null) {
            run = false;
        }
    }
    return exchangeClient;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:30,代码来源:ChanelHandlerTest.java

示例11: ReferenceCountExchangeClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
public ReferenceCountExchangeClient(ExchangeClient client, ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap) {
    this.client = client;
    refenceCount.incrementAndGet();
    this.url = client.getUrl();
    if (ghostClientMap == null){
        throw new IllegalStateException("ghostClientMap can not be null, url: " + url);
    }
    this.ghostClientMap = ghostClientMap;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:ReferenceCountExchangeClient.java

示例12: initClient

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
/**
 * 创建新连接.
 */
private ExchangeClient initClient(URL url) {
    
    // client type setting.
    String str = url.getParameter(Constants.CLIENT_KEY, url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_CLIENT));

    String version = url.getParameter(Constants.DUBBO_VERSION_KEY);
    boolean compatible = (version != null && version.startsWith("1.0."));
    url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() && compatible ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME);
    //默认开启heartbeat
    url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT));
    
    // BIO存在严重性能问题,暂时不允许使用
    if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) {
        throw new RpcException("Unsupported client type: " + str + "," +
                " supported client type is " + StringUtils.join(ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(), " "));
    }
    
    ExchangeClient client ;
    try {
        //设置连接应该是lazy的 
        if (url.getParameter(Constants.LAZY_CONNECT_KEY, false)){
            client = new LazyConnectExchangeClient(url ,requestHandler);
        } else {
            client = Exchangers.connect(url ,requestHandler);
        }
    } catch (RemotingException e) {
        throw new RpcException("Fail to create remoting client for service(" + url
                + "): " + e.getMessage(), e);
    }
    return client;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:35,代码来源:DubboProtocol.java

示例13: isAvailable

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
@Override
public boolean isAvailable() {
    if (!super.isAvailable())
        return false;
    for (ExchangeClient client : clients){
        if (client.isConnected() && !client.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY)){
            //cannot write == not Available ?
            return true ;
        }
    }
    return false;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:DubboInvoker.java

示例14: destroy

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
public void destroy() {
    //防止client被关闭多次.在connect per jvm的情况下,client.close方法会调用计数器-1,当计数器小于等于0的情况下,才真正关闭
    if (super.isDestroyed()){
        return ;
    } else {
        //dubbo check ,避免多次关闭
        destroyLock.lock();
        try{
            if (super.isDestroyed()){
                return ;
            }
            super.destroy();
            if (invokers != null){
                invokers.remove(this);
            }
            for (ExchangeClient client : clients) {
                try {
                    client.close();
                } catch (Throwable t) {
                    logger.warn(t.getMessage(), t);
                }
            }
            
        }finally {
            destroyLock.unlock();
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:29,代码来源:DubboInvoker.java

示例15: getClients

import com.alibaba.dubbo.remoting.exchange.ExchangeClient; //导入依赖的package包/类
private ExchangeClient[] getClients(URL url){

        int connections = url.getParameter(Constants.CONNECTIONS_KEY, 1);

        ExchangeClient[] clients = new ExchangeClient[connections];

        for (int i = 0; i < clients.length; i++) {
            clients[i] = initClient(url);
        }
        return clients;
    }
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:12,代码来源:ThriftProtocol.java


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