JdbcNodeRegistry extends JdbcHelper implements NodeRegistry { @Override public void offerAddresses(List<NetworkAddress> nodes) { cleanUp(); nodes.stream() .filter(node -> node.getTime() < now(+2 * MINUTE) && node.getTime() > now(-28 * DAY)) .forEach(node -> { synchronized (this) { NetworkAddress existing = loadExisting(node); if (existing == null) { insert(node); } else if (node.getTime() > existing.getTime()) { update(node); } } }); } JdbcNodeRegistry(JdbcConfig config); @Override List<NetworkAddress> getKnownAddresses(int limit, long... streams); @Override void offerAddresses(List<NetworkAddress> nodes);  }
@Test public void testOfferAddresses() throws Exception { registry.offerAddresses(Arrays.asList( createAddress(1, 8444, 1, now()), createAddress(10, 8444, 1, now()), createAddress(11, 8444, 1, now()) )); List<NetworkAddress> knownAddresses = registry.getKnownAddresses(1000, 1); assertEquals(5, knownAddresses.size()); registry.offerAddresses(Collections.singletonList( createAddress(1, 8445, 1, now()) )); knownAddresses = registry.getKnownAddresses(1000, 1); assertEquals(6, knownAddresses.size()); }