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{135 final Invoker invoker;136 final Integer weight;137 Integer effectiveWeight;138 Integer currentWeight;139

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 invokersWeight = new HashMap<>(3);164 Integer aWeight = 4;165 Integer bWeight = 2;166 Integer cWeight = 1;167

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 }


本文标签: 主题 作者 欣赏