@Test public void multipleEndpoints() { RemoteEndpoint ep1 = new RemoteEndpoint().setServiceName(TEST_SERVICE1).setEndpoint("ep1"); RemoteEndpoint ep2 = new RemoteEndpoint().setServiceName(TEST_SERVICE1).setEndpoint("ep2"); RemoteEndpoint ep3 = new RemoteEndpoint().setServiceName(TEST_SERVICE2).setEndpoint("ep3"); RemoteEndpoint ep4 = new RemoteEndpoint().setServiceName(TEST_SERVICE2).setEndpoint("ep4"); registry.addEndpoint(ep1); registry.addEndpoint(ep2); registry.addEndpoint(ep3); registry.addEndpoint(ep4); Assert.assertEquals(ep1, robin.selectEndpoint(TEST_SERVICE1)); Assert.assertEquals(ep3, robin.selectEndpoint(TEST_SERVICE2)); Assert.assertEquals(ep2, robin.selectEndpoint(TEST_SERVICE1)); Assert.assertEquals(ep4, robin.selectEndpoint(TEST_SERVICE2)); Assert.assertEquals(ep1, robin.selectEndpoint(TEST_SERVICE1)); }
@Override public RemoteEndpoint selectEndpoint(QName serviceName) { if (getRegistry() == null) { return null; } RemoteEndpoint selectedEp = null; List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName); if (!eps.isEmpty()) { _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0)); AtomicInteger idx = _endpointIdxs.get(serviceName); synchronized (idx) { idx.set(idx.get() % eps.size()); selectedEp = eps.get(idx.getAndIncrement()); } } return selectedEp; }
RoundRobinStrategy extends BaseStrategy { @Override public RemoteEndpoint selectEndpoint(QName serviceName) { if (getRegistry() == null) { return null; } RemoteEndpoint selectedEp = null; List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName); if (!eps.isEmpty()) { _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0)); AtomicInteger idx = _endpointIdxs.get(serviceName); synchronized (idx) { idx.set(idx.get() % eps.size()); selectedEp = eps.get(idx.getAndIncrement()); } } return selectedEp; } }
RoundRobinStrategy extends BaseStrategy { @Override public RemoteEndpoint selectEndpoint(QName serviceName) { if (getRegistry() == null) { return null; } RemoteEndpoint selectedEp = null; List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName); if (!eps.isEmpty()) { _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0)); AtomicInteger idx = _endpointIdxs.get(serviceName); synchronized (idx) { idx.set(idx.get() % eps.size()); selectedEp = eps.get(idx.getAndIncrement()); } } return selectedEp; } RoundRobinStrategy(); }
RoundRobinStrategy extends BaseStrategy { @Override public RemoteEndpoint selectEndpoint(QName serviceName) { if (getRegistry() == null) { return null; } RemoteEndpoint selectedEp = null; List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName); if (!eps.isEmpty()) { _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0)); AtomicInteger idx = _endpointIdxs.get(serviceName); synchronized (idx) { idx.set(idx.get() % eps.size()); selectedEp = eps.get(idx.getAndIncrement()); } } return selectedEp; } RoundRobinStrategy(); @Override RemoteEndpoint selectEndpoint(QName serviceName); }
RoundRobinStrategy extends BaseStrategy { @Override public RemoteEndpoint selectEndpoint(QName serviceName) { if (getRegistry() == null) { return null; } RemoteEndpoint selectedEp = null; List<RemoteEndpoint> eps = getRegistry().getEndpoints(serviceName); if (!eps.isEmpty()) { _endpointIdxs.putIfAbsent(serviceName, new AtomicInteger(0)); AtomicInteger idx = _endpointIdxs.get(serviceName); synchronized (idx) { idx.set(idx.get() % eps.size()); selectedEp = eps.get(idx.getAndIncrement()); } } return selectedEp; } RoundRobinStrategy(); @Override RemoteEndpoint selectEndpoint(QName serviceName);  }