5050 * pool of children ReactiveSockets.
5151 * It estimates the load of each ReactiveSocket based on statistics collected.
5252 */
53- public class LoadBalancer < T > implements ReactiveSocket {
53+ public class LoadBalancer implements ReactiveSocket {
5454 public static final double DEFAULT_EXP_FACTOR = 4.0 ;
5555 public static final double DEFAULT_LOWER_QUANTILE = 0.2 ;
5656 public static final double DEFAULT_HIGHER_QUANTILE = 0.8 ;
@@ -78,7 +78,7 @@ public class LoadBalancer<T> implements ReactiveSocket {
7878
7979 private int pendingSockets ;
8080 private final List <WeightedSocket > activeSockets ;
81- private final List <ReactiveSocketFactory < T > > activeFactories ;
81+ private final List <ReactiveSocketFactory > activeFactories ;
8282 private final FactoriesRefresher factoryRefresher ;
8383
8484 private Ewma pendings ;
@@ -109,7 +109,7 @@ public class LoadBalancer<T> implements ReactiveSocket {
109109 * ReactiveSocket is closed. (unit is millisecond)
110110 */
111111 public LoadBalancer (
112- Publisher <? extends Collection <ReactiveSocketFactory < T > >> factories ,
112+ Publisher <? extends Collection <ReactiveSocketFactory >> factories ,
113113 double expFactor ,
114114 double lowQuantile ,
115115 double highQuantile ,
@@ -144,7 +144,7 @@ public LoadBalancer(
144144 factories .subscribe (factoryRefresher );
145145 }
146146
147- public LoadBalancer (Publisher <? extends Collection <ReactiveSocketFactory < T > >> factories ) {
147+ public LoadBalancer (Publisher <? extends Collection <ReactiveSocketFactory >> factories ) {
148148 this (factories ,
149149 DEFAULT_EXP_FACTOR ,
150150 DEFAULT_LOWER_QUANTILE , DEFAULT_HIGHER_QUANTILE ,
@@ -196,16 +196,16 @@ private synchronized void addSockets(int numberOfNewSocket) {
196196 while (n > 0 ) {
197197 int size = activeFactories .size ();
198198 if (size == 1 ) {
199- ReactiveSocketFactory < T > factory = activeFactories .get (0 );
199+ ReactiveSocketFactory factory = activeFactories .get (0 );
200200 if (factory .availability () > 0.0 ) {
201201 activeFactories .remove (0 );
202202 pendingSockets ++;
203203 factory .apply ().subscribe (new SocketAdder (factory ));
204204 }
205205 break ;
206206 }
207- ReactiveSocketFactory < T > factory0 = null ;
208- ReactiveSocketFactory < T > factory1 = null ;
207+ ReactiveSocketFactory factory0 = null ;
208+ ReactiveSocketFactory factory1 = null ;
209209 int i0 = 0 ;
210210 int i1 = 0 ;
211211 for (int i = 0 ; i < EFFORT ; i ++) {
@@ -323,10 +323,6 @@ private synchronized void quickSlowestRS() {
323323 return ;
324324 }
325325
326- activeSockets .forEach (value -> {
327- logger .info ("> " + value );
328- });
329-
330326 WeightedSocket slowest = null ;
331327 double lowestAvailability = Double .MAX_VALUE ;
332328 for (WeightedSocket socket : activeSockets ) {
@@ -500,7 +496,7 @@ public Publisher<Void> onClose() {
500496 * This subscriber role is to subscribe to the list of server identifier, and update the
501497 * factory list.
502498 */
503- private class FactoriesRefresher implements Subscriber <Collection <ReactiveSocketFactory < T > >> {
499+ private class FactoriesRefresher implements Subscriber <Collection <ReactiveSocketFactory >> {
504500 private Subscription subscription ;
505501
506502 @ Override
@@ -510,21 +506,21 @@ public void onSubscribe(Subscription subscription) {
510506 }
511507
512508 @ Override
513- public void onNext (Collection <ReactiveSocketFactory < T > > newFactories ) {
509+ public void onNext (Collection <ReactiveSocketFactory > newFactories ) {
514510 synchronized (LoadBalancer .this ) {
515511
516- Set <ReactiveSocketFactory < T > > current =
512+ Set <ReactiveSocketFactory > current =
517513 new HashSet <>(activeFactories .size () + activeSockets .size ());
518514 current .addAll (activeFactories );
519515 for (WeightedSocket socket : activeSockets ) {
520- ReactiveSocketFactory < T > factory = socket .getFactory ();
516+ ReactiveSocketFactory factory = socket .getFactory ();
521517 current .add (factory );
522518 }
523519
524- Set <ReactiveSocketFactory < T > > removed = new HashSet <>(current );
520+ Set <ReactiveSocketFactory > removed = new HashSet <>(current );
525521 removed .removeAll (newFactories );
526522
527- Set <ReactiveSocketFactory < T > > added = new HashSet <>(newFactories );
523+ Set <ReactiveSocketFactory > added = new HashSet <>(newFactories );
528524 added .removeAll (current );
529525
530526 boolean changed = false ;
@@ -541,9 +537,9 @@ public void onNext(Collection<ReactiveSocketFactory<T>> newFactories) {
541537 }
542538 }
543539 }
544- Iterator <ReactiveSocketFactory < T > > it1 = activeFactories .iterator ();
540+ Iterator <ReactiveSocketFactory > it1 = activeFactories .iterator ();
545541 while (it1 .hasNext ()) {
546- ReactiveSocketFactory < T > factory = it1 .next ();
542+ ReactiveSocketFactory factory = it1 .next ();
547543 if (removed .contains (factory )) {
548544 it1 .remove ();
549545 changed = true ;
@@ -554,7 +550,7 @@ public void onNext(Collection<ReactiveSocketFactory<T>> newFactories) {
554550
555551 if (changed && logger .isDebugEnabled ()) {
556552 String msg = "\n Updated active factories (size: " + activeFactories .size () + ")\n " ;
557- for (ReactiveSocketFactory < T > f : activeFactories ) {
553+ for (ReactiveSocketFactory f : activeFactories ) {
558554 msg += " + " + f + "\n " ;
559555 }
560556 msg += "Active sockets:\n " ;
@@ -583,9 +579,9 @@ void close() {
583579 }
584580
585581 private class SocketAdder implements Subscriber <ReactiveSocket > {
586- private final ReactiveSocketFactory < T > factory ;
582+ private final ReactiveSocketFactory factory ;
587583
588- private SocketAdder (ReactiveSocketFactory < T > factory ) {
584+ private SocketAdder (ReactiveSocketFactory factory ) {
589585 this .factory = factory ;
590586 }
591587
@@ -602,8 +598,7 @@ public void onNext(ReactiveSocket rs) {
602598 }
603599
604600 WeightedSocket weightedSocket = new WeightedSocket (rs , factory , lowerQuantile , higherQuantile );
605- logger .info ("Adding new WeightedSocket "
606- + weightedSocket + " connected to " + factory .remote ());
601+ logger .info ("Adding new WeightedSocket {}" , weightedSocket );
607602
608603 activeSockets .add (weightedSocket );
609604 pendingSockets -= 1 ;
@@ -711,7 +706,7 @@ private class WeightedSocket extends ReactiveSocketProxy {
711706 private static final double STARTUP_PENALTY = Long .MAX_VALUE >> 12 ;
712707
713708 private final ReactiveSocket child ;
714- private ReactiveSocketFactory < T > factory ;
709+ private ReactiveSocketFactory factory ;
715710 private final Quantile lowerQuantile ;
716711 private final Quantile higherQuantile ;
717712 private final long inactivityFactor ;
@@ -728,7 +723,7 @@ private class WeightedSocket extends ReactiveSocketProxy {
728723
729724 WeightedSocket (
730725 ReactiveSocket child ,
731- ReactiveSocketFactory < T > factory ,
726+ ReactiveSocketFactory factory ,
732727 Quantile lowerQuantile ,
733728 Quantile higherQuantile ,
734729 int inactivityFactor
@@ -751,7 +746,7 @@ private class WeightedSocket extends ReactiveSocketProxy {
751746
752747 WeightedSocket (
753748 ReactiveSocket child ,
754- ReactiveSocketFactory < T > factory ,
749+ ReactiveSocketFactory factory ,
755750 Quantile lowerQuantile ,
756751 Quantile higherQuantile
757752 ) {
@@ -794,7 +789,7 @@ public Publisher<Payload> requestChannel(Publisher<Payload> payloads) {
794789 child .requestChannel (payloads ).subscribe (new CountingSubscriber <>(subscriber , this ));
795790 }
796791
797- ReactiveSocketFactory < T > getFactory () {
792+ ReactiveSocketFactory getFactory () {
798793 return factory ;
799794 }
800795
0 commit comments