admin 管理员组文章数量: 1086019
2024年1月17日发(作者:easyui主题包欣赏)
76
77 tWeight -= total; 78 return r; 79 } 80
81 public void onInvokeSuccess(Invoker invoker){ 82 if (checkNodes()){ 83 () 84 .filter((Node node)->().equals(())) 85 .findFirst() 86 .get() 87 .onInvokeSuccess(); 88 } 89 } 90
91 public void onInvokeFail(Invoker invoker){ 92 if (checkNodes()){ 93 () 94 .filter((Node node)->().equals(())) 95 .findFirst() 96 .get() 97 .onInvokeFail(); 98 } 99 }100
101 private boolean checkNodes(){102 return (nodes != null && () > 0);103 }104
105 public void printCurrenctWeightBeforeSelect(){106 if (checkNodes()) {107 final StringBuffer out = new StringBuffer("{");108 h(node->(())109 .append("=")110 .append(tWeight+iveWeight)111 .append(","));112 ("}");113 (out);114 }115 }116
117 public void printCurrenctWeight(){118 if (checkNodes()) {119 final StringBuffer out = new StringBuffer("{");120 h(node->(())121 .append("=")122 .append(tWeight)123 .append(","));124 ("}");125 (out);126 }127 }128
129 public interface Invoker{130 Boolean isAvalable();131 String id();132 }133
134 private static class Node implements Comparable
140 Node(Invoker invoker, Integer weight){141 r = invoker;142 = weight;143 iveWeight = weight;144 tWeight = 0;145 }146
147 @Override148 public int compareTo(Node o) {149 return currentWeight > tWeight ? 1 : ((tWeight) ? 0 : -1);150 }151
152 public void onInvokeSuccess(){153 if (effectiveWeight < )154 effectiveWeight++;155 }156
157 public void onInvokeFail(){158 effectiveWeight--;159 }
160 }161
162 public static void main(String[] args){163 Map
168 (new Invoker() {169 @Override170 public Boolean isAvalable() {171 return true;172 }173 @Override174 public String id() {175 return "a";176 }177 }, aWeight);178
179 (new Invoker() {180 @Override181 public Boolean isAvalable() {182 return true;183 }184 @Override185 public String id() {186 return "b";187 }188 }, bWeight);189
190 (new Invoker() {191 @Override192 public Boolean isAvalable() {193 return true;194 }195 @Override196 public String id() {197 return "c";198 }199 }, cWeight);200
201 Integer times = 7;202 RoundRobinByWeightLoadBalance roundRobin = new RoundRobinByWeightLoadBalance(invokersWeight);203 for(int i=1; i<=times; i++){204 (new StringBuffer(i+"").append(" "));205 urrenctWeightBeforeSelect();206 Invoker invoker = ();207 (new StringBuffer(" ").append(()).append(" "));208 urrenctWeight();209 n();210 }211 }212 }
版权声明:本文标题:负载均衡算法WeightedRoundRobin(加权轮询)简介及算法实现 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1705462759a485739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论