@Test public void selectWithoutLast() { NavigableSet<ClientStreamIdentification> clients = new TreeSet<>(); clients.add(new ClientStreamIdentification(Topology.DEFAULT_CONTEXT, "client1")); ClientStreamIdentification selected = testSubject.select(new QueryDefinition("context", "request"), "component", clients); assertEquals("client1", selected.getClientStreamId()); clients = new TreeSet<>(); clients.add(new ClientStreamIdentification(Topology.DEFAULT_CONTEXT, "client2")); selected = testSubject.select(new QueryDefinition("context", "request"), "component", clients); assertEquals("client2", selected.getClientStreamId()); selected = testSubject.select(new QueryDefinition("context", "request"), "component", clients); assertEquals("client2", selected.getClientStreamId()); }
@Override public ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName, NavigableSet<ClientStreamIdentification> queryHandlers) { if (queryHandlers.isEmpty()) { return null; } QueryDefinitionComponent key = new QueryDefinitionComponent(queryDefinition, componentName); ClientStreamIdentification last = lastClientMap.computeIfAbsent(key, k -> queryHandlers.last()); SortedSet<ClientStreamIdentification> tail = queryHandlers.tailSet(last, false); if( tail.isEmpty()) { last = queryHandlers.first(); } else { last = tail.first(); } lastClientMap.put(key, last); return last; }
RoundRobinQueryHandlerSelector implements QueryHandlerSelector { @Override public ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName, NavigableSet<ClientStreamIdentification> queryHandlers) { if (queryHandlers.isEmpty()) { return null; } QueryDefinitionComponent key = new QueryDefinitionComponent(queryDefinition, componentName); ClientStreamIdentification last = lastClientMap.computeIfAbsent(key, k -> queryHandlers.last()); SortedSet<ClientStreamIdentification> tail = queryHandlers.tailSet(last, false); if( tail.isEmpty()) { last = queryHandlers.first(); } else { last = tail.first(); } lastClientMap.put(key, last); return last; } }
RoundRobinQueryHandlerSelector implements QueryHandlerSelector { @Override public ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName, NavigableSet<ClientStreamIdentification> queryHandlers) { if (queryHandlers.isEmpty()) { return null; } QueryDefinitionComponent key = new QueryDefinitionComponent(queryDefinition, componentName); ClientStreamIdentification last = lastClientMap.computeIfAbsent(key, k -> queryHandlers.last()); SortedSet<ClientStreamIdentification> tail = queryHandlers.tailSet(last, false); if( tail.isEmpty()) { last = queryHandlers.first(); } else { last = tail.first(); } lastClientMap.put(key, last); return last; }  }
RoundRobinQueryHandlerSelector implements QueryHandlerSelector { @Override public ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName, NavigableSet<ClientStreamIdentification> queryHandlers) { if (queryHandlers.isEmpty()) { return null; } QueryDefinitionComponent key = new QueryDefinitionComponent(queryDefinition, componentName); ClientStreamIdentification last = lastClientMap.computeIfAbsent(key, k -> queryHandlers.last()); SortedSet<ClientStreamIdentification> tail = queryHandlers.tailSet(last, false); if( tail.isEmpty()) { last = queryHandlers.first(); } else { last = tail.first(); } lastClientMap.put(key, last); return last; }  @Override ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName,
                                             NavigableSet<ClientStreamIdentification> queryHandlers); }
RoundRobinQueryHandlerSelector implements QueryHandlerSelector { @Override public ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName, NavigableSet<ClientStreamIdentification> queryHandlers) { if (queryHandlers.isEmpty()) { return null; } QueryDefinitionComponent key = new QueryDefinitionComponent(queryDefinition, componentName); ClientStreamIdentification last = lastClientMap.computeIfAbsent(key, k -> queryHandlers.last()); SortedSet<ClientStreamIdentification> tail = queryHandlers.tailSet(last, false); if( tail.isEmpty()) { last = queryHandlers.first(); } else { last = tail.first(); } lastClientMap.put(key, last); return last; }  @Override ClientStreamIdentification select(QueryDefinition queryDefinition, String componentName,
                                             NavigableSet<ClientStreamIdentification> queryHandlers);  }