|
20 | 20 | import io.rsocket.RSocket;
|
21 | 21 | import io.rsocket.frame.FrameType;
|
22 | 22 | import java.util.Arrays;
|
| 23 | +import java.util.Collection; |
23 | 24 | import java.util.HashMap;
|
| 25 | +import java.util.Iterator; |
24 | 26 | import java.util.List;
|
| 27 | +import java.util.ListIterator; |
25 | 28 | import java.util.concurrent.CancellationException;
|
26 | 29 | import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
27 | 30 | import java.util.function.Supplier;
|
|
34 | 37 | import reactor.util.annotation.Nullable;
|
35 | 38 |
|
36 | 39 | class RSocketPool extends ResolvingOperator<Void>
|
37 |
| - implements CoreSubscriber<List<LoadbalanceRSocketSource>> { |
| 40 | + implements CoreSubscriber<List<LoadbalanceRSocketSource>>, List<PooledRSocket> { |
38 | 41 |
|
39 | 42 | final DeferredResolutionRSocket deferredResolutionRSocket = new DeferredResolutionRSocket(this);
|
40 | 43 | final LoadbalanceStrategy loadbalanceStrategy;
|
@@ -200,7 +203,33 @@ RSocket doSelect() {
|
200 | 203 | return null;
|
201 | 204 | }
|
202 | 205 |
|
203 |
| - return this.loadbalanceStrategy.select(sockets); |
| 206 | + return this.loadbalanceStrategy.select(this); |
| 207 | + } |
| 208 | + |
| 209 | + @Override |
| 210 | + public PooledRSocket get(int index) { |
| 211 | + return activeSockets[index]; |
| 212 | + } |
| 213 | + |
| 214 | + @Override |
| 215 | + public int size() { |
| 216 | + return activeSockets.length; |
| 217 | + } |
| 218 | + |
| 219 | + @Override |
| 220 | + public boolean isEmpty() { |
| 221 | + return activeSockets.length == 0; |
| 222 | + } |
| 223 | + |
| 224 | + @Override |
| 225 | + public Object[] toArray() { |
| 226 | + return activeSockets; |
| 227 | + } |
| 228 | + |
| 229 | + @Override |
| 230 | + @SuppressWarnings("unchecked") |
| 231 | + public <T> T[] toArray(T[] a) { |
| 232 | + return (T[]) activeSockets; |
204 | 233 | }
|
205 | 234 |
|
206 | 235 | static class DeferredResolutionRSocket implements RSocket {
|
@@ -325,4 +354,94 @@ public void accept(Void aVoid, Throwable t) {
|
325 | 354 | }
|
326 | 355 | }
|
327 | 356 | }
|
| 357 | + |
| 358 | + @Override |
| 359 | + public boolean contains(Object o) { |
| 360 | + throw new UnsupportedOperationException(); |
| 361 | + } |
| 362 | + |
| 363 | + @Override |
| 364 | + public Iterator<PooledRSocket> iterator() { |
| 365 | + throw new UnsupportedOperationException(); |
| 366 | + } |
| 367 | + |
| 368 | + @Override |
| 369 | + public boolean add(PooledRSocket pooledRSocket) { |
| 370 | + throw new UnsupportedOperationException(); |
| 371 | + } |
| 372 | + |
| 373 | + @Override |
| 374 | + public boolean remove(Object o) { |
| 375 | + throw new UnsupportedOperationException(); |
| 376 | + } |
| 377 | + |
| 378 | + @Override |
| 379 | + public boolean containsAll(Collection<?> c) { |
| 380 | + throw new UnsupportedOperationException(); |
| 381 | + } |
| 382 | + |
| 383 | + @Override |
| 384 | + public boolean addAll(Collection<? extends PooledRSocket> c) { |
| 385 | + throw new UnsupportedOperationException(); |
| 386 | + } |
| 387 | + |
| 388 | + @Override |
| 389 | + public boolean addAll(int index, Collection<? extends PooledRSocket> c) { |
| 390 | + throw new UnsupportedOperationException(); |
| 391 | + } |
| 392 | + |
| 393 | + @Override |
| 394 | + public boolean removeAll(Collection<?> c) { |
| 395 | + throw new UnsupportedOperationException(); |
| 396 | + } |
| 397 | + |
| 398 | + @Override |
| 399 | + public boolean retainAll(Collection<?> c) { |
| 400 | + throw new UnsupportedOperationException(); |
| 401 | + } |
| 402 | + |
| 403 | + @Override |
| 404 | + public void clear() { |
| 405 | + throw new UnsupportedOperationException(); |
| 406 | + } |
| 407 | + |
| 408 | + @Override |
| 409 | + public PooledRSocket set(int index, PooledRSocket element) { |
| 410 | + throw new UnsupportedOperationException(); |
| 411 | + } |
| 412 | + |
| 413 | + @Override |
| 414 | + public void add(int index, PooledRSocket element) { |
| 415 | + throw new UnsupportedOperationException(); |
| 416 | + } |
| 417 | + |
| 418 | + @Override |
| 419 | + public PooledRSocket remove(int index) { |
| 420 | + throw new UnsupportedOperationException(); |
| 421 | + } |
| 422 | + |
| 423 | + @Override |
| 424 | + public int indexOf(Object o) { |
| 425 | + throw new UnsupportedOperationException(); |
| 426 | + } |
| 427 | + |
| 428 | + @Override |
| 429 | + public int lastIndexOf(Object o) { |
| 430 | + throw new UnsupportedOperationException(); |
| 431 | + } |
| 432 | + |
| 433 | + @Override |
| 434 | + public ListIterator<PooledRSocket> listIterator() { |
| 435 | + throw new UnsupportedOperationException(); |
| 436 | + } |
| 437 | + |
| 438 | + @Override |
| 439 | + public ListIterator<PooledRSocket> listIterator(int index) { |
| 440 | + throw new UnsupportedOperationException(); |
| 441 | + } |
| 442 | + |
| 443 | + @Override |
| 444 | + public List<PooledRSocket> subList(int fromIndex, int toIndex) { |
| 445 | + throw new UnsupportedOperationException(); |
| 446 | + } |
328 | 447 | }
|
0 commit comments