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


Java LoadBalance类代码示例

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


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

示例1: select

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
/**
 * 使用loadbalance选择invoker.</br>
 * a)先lb选择,如果在selected列表中 或者 不可用且做检验时,进入下一步(重选),否则直接返回</br>
 * b)重选验证规则:selected > available .保证重选出的结果尽量不在select中,并且是可用的 
 * 
 * @param availablecheck 如果设置true,在选择的时候先选invoker.available == true
 * @param selected 已选过的invoker.注意:输入保证不重复
 * 
 */
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
    if (invokers == null || invokers.size() == 0)
        return null;
    String methodName = invocation == null ? "" : invocation.getMethodName();
    
    boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName,Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY) ;
    {
        //ignore overloaded method
        if ( stickyInvoker != null && !invokers.contains(stickyInvoker) ){
            stickyInvoker = null;
        }
        //ignore cucurrent problem
        if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))){
            if (availablecheck && stickyInvoker.isAvailable()){
                return stickyInvoker;
            }
        }
    }
    Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected);
    
    if (sticky){
        stickyInvoker = invoker;
    }
    return invoker;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:35,代码来源:AbstractClusterInvoker.java

示例2: invoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWhetherDestroyed();

        LoadBalance loadbalance;
        
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:AbstractClusterInvoker.java

示例3: invoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWheatherDestoried();

        LoadBalance loadbalance;
        
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:17,代码来源:AbstractClusterInvoker.java

示例4: select

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
/**
 * 使用loadbalance选择invoker.</br>
 * a)先lb选择,如果在selected列表中 或者 不可用且做检验时,进入下一步(重选),否则直接返回</br>
 * b)重选验证规则:selected > available .保证重选出的结果尽量不在select中,并且是可用的
 *
 * @param availablecheck 如果设置true,在选择的时候先选invoker.available == true
 * @param selected       已选过的invoker.注意:输入保证不重复
 */
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
    if (invokers == null || invokers.size() == 0)
        return null;
    String methodName = invocation == null ? "" : invocation.getMethodName();

    boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);
    {
        //ignore overloaded method
        if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
            stickyInvoker = null;
        }
        //ignore cucurrent problem
        if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
            if (availablecheck && stickyInvoker.isAvailable()) {
                return stickyInvoker;
            }
        }
    }
    Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected);

    if (sticky) {
        stickyInvoker = invoker;
    }
    return invoker;
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:34,代码来源:AbstractClusterInvoker.java

示例5: invoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWhetherDestroyed();

        LoadBalance loadbalance;

        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:l1325169021,项目名称:github-test,代码行数:17,代码来源:AbstractClusterInvoker.java

示例6: select

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
/**
 * 使用loadbalance选择invoker.</br>
 * a)先lb选择,如果在selected列表中 或者 不可用且做检验时,进入下一步(重选),否则直接返回</br>
 * b)重选验证规则:selected > available .保证重选出的结果尽量不在select中,并且是可用的 
 * 
 * @param availablecheck 如果设置true,在选择的时候先选invoker.available == true
 * @param selected 已选过的invoker.注意:输入保证不重复
 * 
 */
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
    if (invokers == null || invokers.size() == 0)
        return null;
    String methodName = invocation == null ? "" : invocation.getMethodName();

    boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName,Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY) ;
    {
        //ignore overloaded method
        if ( stickyInvoker != null && !invokers.contains(stickyInvoker) ){
            stickyInvoker = null;
        }
        //ignore cucurrent problem
        if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))){
            if (availablecheck && stickyInvoker.isAvailable()){
                return stickyInvoker;
            }
        }
    }
    Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected);
    
    if (sticky){
        stickyInvoker = invoker;
    }
    return invoker;
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:35,代码来源:AbstractClusterInvoker.java

示例7: invoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWheatherDestoried();

        LoadBalance loadbalance;
        //FIXME list是路由之后的结果  add by jileng
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            //FIXME  存在多个invoker的情况下  
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        //FIXME 如果是async调用,则把invocationId放到RpcInvocation里面  add by jileng
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:spccold,项目名称:dubbo-comments,代码行数:19,代码来源:AbstractClusterInvoker.java

示例8: invoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {

        checkWheatherDestoried();

        LoadBalance loadbalance;
        //从Directory中获得集群后面的Invoker列表
        List<Invoker<T>> invokers = list(invocation);
        //通过SPI机制加载需要的LoadBalance
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        //调用子类重写的doInvoker()方法
        return doInvoke(invocation, invokers, loadbalance);
    }
 
开发者ID:DoubleSmile,项目名称:dubbo-learning,代码行数:19,代码来源:AbstractClusterInvoker.java

示例9: doInvoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
    checkInvokers(invokers, invocation);
    Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
    try {
        return invoker.invoke(invocation);
    } catch (Throwable e) {
        if (e instanceof RpcException && ((RpcException)e).isBiz()) { // biz exception.
            throw (RpcException) e;
        }
        throw new RpcException(e instanceof RpcException ? ((RpcException)e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:FailfastClusterInvoker.java

示例10: doInvoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
    for (Invoker<T> invoker : invokers) {
        if (invoker.isAvailable()) {
            return invoker.invoke(invocation);
        }
    }
    throw new RpcException("No provider available in " + invokers);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:9,代码来源:AvailableClusterInvoker.java

示例11: doInvoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
    try {
        checkInvokers(invokers, invocation);
        Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
        return invoker.invoke(invocation);
    } catch (Throwable e) {
        logger.error("Failback to invoke method " + invocation.getMethodName() + ", wait for retry in background. Ignored exception: "
                             + e.getMessage() + ", ", e);
        addFailed(invocation, this);
        return new RpcResult(); // ignore
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:FailbackClusterInvoker.java

示例12: join

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public <T> Invoker<T> join(Directory<T> directory) throws RpcException {
    
    return new AbstractClusterInvoker<T>(directory) {
        public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
            for (Invoker<T> invoker : invokers) {
                if (invoker.isAvailable()) {
                    return invoker.invoke(invocation);
                }
            }
            throw new RpcException("No provider available in " + invokers);
        }
    };
    
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:15,代码来源:AvailableCluster.java

示例13: doselect

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
    if (invokers == null || invokers.size() == 0)
        return null;
    if (invokers.size() == 1)
        return invokers.get(0);
    // 如果只有两个invoker,退化成轮循
    if (invokers.size() == 2 && selected != null && selected.size() > 0) {
        return selected.get(0) == invokers.get(0) ? invokers.get(1) : invokers.get(0);
    }
    Invoker<T> invoker = loadbalance.select(invokers, getUrl(), invocation);
    
    //如果 selected中包含(优先判断) 或者 不可用&&availablecheck=true 则重试.
    if( (selected != null && selected.contains(invoker))
            ||(!invoker.isAvailable() && getUrl()!=null && availablecheck)){
        try{
            Invoker<T> rinvoker = reselect(loadbalance, invocation, invokers, selected, availablecheck);
            if(rinvoker != null){
                invoker =  rinvoker;
            }else{
                //看下第一次选的位置,如果不是最后,选+1位置.
                int index = invokers.indexOf(invoker);
                try{
                    //最后在避免碰撞
                    invoker = index <invokers.size()-1?invokers.get(index+1) :invoker;
                }catch (Exception e) {
                    logger.warn(e.getMessage()+" may because invokers list dynamic change, ignore.",e);
                }
            }
        }catch (Throwable t){
            logger.error("clustor relselect fail reason is :"+t.getMessage() +" if can not slove ,you can set cluster.availablecheck=false in url",t);
        }
    }
    return invoker;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:35,代码来源:AbstractClusterInvoker.java

示例14: doInvoke

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Result doInvoke(Invocation invocation, List<Invoker<T>> invokers, LoadBalance loadbalance) throws RpcException {
    try {
        checkInvokers(invokers, invocation);
        Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
        return invoker.invoke(invocation);
    } catch (Throwable e) {
        logger.error("Failsafe ignore exception: " + e.getMessage(), e);
        return new RpcResult(); // ignore
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:FailsafeClusterInvoker.java

示例15: getInvokeCounter

import com.alibaba.dubbo.rpc.cluster.LoadBalance; //导入依赖的package包/类
public Map<Invoker,AtomicLong> getInvokeCounter(int runs,String loadbalanceName) {
    Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(loadbalanceName);
    for(Invoker invoker :invokers){
        counter.put(invoker, new AtomicLong(0));
    }
    for(int i=0;i<runs;i++){
        Invoker sinvoker = lb.select(invokers, invokers.get(0).getUrl(), invocation);
        counter.get(sinvoker).incrementAndGet();
    }
    return counter;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:LoadBalanceTest.java


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