@Test public void testPartitionBindings() throws Exception { dispatcher.setPartitionSize(5); List partitions = dispatcher.partitionBindings(mockConnection(Version.Version4), getBindings("1.1.1.1/32", "2.2.2.2/32", "3.3.3.3/32", "4.4.4.0/24"), getBindings("5.5.5.5/32", "6.6.6.6/32", "7.7.7.7/32", "8.8.8.0/24")); assertEquals(2, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version4), getBindings("1.1.1.1/32", "2.2.2.2/32"), getBindings("5.5.5.5/32", "6.6.6.6/32", "7.7.7.7/32")); assertEquals(1, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version3), getBindings("1.1.1.1/32", "2.2.2.2/32", "3.3.3.3/32", "4.4.4.0/24"), getBindings("5.5.5.5/32", "6.6.6.6/32", "7.7.7.7/32", "8.8.8.0/24")); assertEquals(2, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version2), getBindings("1.1.1.1/32", "2.2.2.2/32", "3.3.3.3/32", "4.4.4.0/24"), getBindings("5.5.5.5/32", "6.6.6.6/32", "7.7.7.7/32", "8.8.8.0/24")); assertEquals(22, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version2), getBindings("1.1.1.1/32", "2.2.2.2/32", "3.3.3.3/32", "4.4.4.0/24"), null); assertEquals(11, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version2), null, getBindings("5.5.5.5/32", "6.6.6.6/32", "7.7.7.7/32", "8.8.8.0/24")); assertEquals(11, partitions.size()); partitions = dispatcher.partitionBindings(mockConnection(Version.Version2), null, null); assertEquals(0, partitions.size()); }
<T extends SxpBindingFields> List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitionBindings( SxpConnection connection, List<T> deleteBindings, List<T> addBindings) { List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitions = new ArrayList<>(); List<T> lastPartition = null; if (connection.isVersion4() && !connection.getCapabilitiesRemote().contains(CapabilityType.SubnetBindings) || connection.getVersion().getIntValue() < 3) { expandBindings(deleteBindings, owner.getExpansionQuantity()); expandBindings(addBindings, owner.getExpansionQuantity()); } if (deleteBindings != null && !deleteBindings.isEmpty()) { for (List<T> partition : Lists.partition(deleteBindings, getPartitionSize())) { partitions.add(generatePart(partition, null)); lastPartition = partition; } } if (addBindings != null && !addBindings.isEmpty()) { int splitFactor = 0; if (lastPartition != null) { splitFactor = getPartitionSize() - lastPartition.size(); partitions.set(partitions.size() - 1, generatePart(lastPartition, splitFactor > addBindings.size() ? addBindings : addBindings.subList(0, splitFactor))); } for (List<T> partition : Lists.partition( addBindings.subList(splitFactor > addBindings.size() ? 0 : splitFactor, addBindings.size()), getPartitionSize())) { partitions.add(generatePart(null, partition)); } } return partitions; }
BindingDispatcher { <T extends SxpBindingFields> List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitionBindings( SxpConnection connection, List<T> deleteBindings, List<T> addBindings) { List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitions = new ArrayList<>(); List<T> lastPartition = null; if (connection.isVersion4() && !connection.getCapabilitiesRemote().contains(CapabilityType.SubnetBindings) || connection.getVersion().getIntValue() < 3) { expandBindings(deleteBindings, owner.getExpansionQuantity()); expandBindings(addBindings, owner.getExpansionQuantity()); } if (deleteBindings != null && !deleteBindings.isEmpty()) { for (List<T> partition : Lists.partition(deleteBindings, getPartitionSize())) { partitions.add(generatePart(partition, null)); lastPartition = partition; } } if (addBindings != null && !addBindings.isEmpty()) { int splitFactor = 0; if (lastPartition != null) { splitFactor = getPartitionSize() - lastPartition.size(); partitions.set(partitions.size() - 1, generatePart(lastPartition, splitFactor > addBindings.size() ? addBindings : addBindings.subList(0, splitFactor))); } for (List<T> partition : Lists.partition( addBindings.subList(splitFactor > addBindings.size() ? 0 : splitFactor, addBindings.size()), getPartitionSize())) { partitions.add(generatePart(null, partition)); } } return partitions; } }
BindingDispatcher { <T extends SxpBindingFields> List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitionBindings( SxpConnection connection, List<T> deleteBindings, List<T> addBindings) { List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitions = new ArrayList<>(); List<T> lastPartition = null; if (connection.isVersion4() && !connection.getCapabilitiesRemote().contains(CapabilityType.SubnetBindings) || connection.getVersion().getIntValue() < 3) { expandBindings(deleteBindings, owner.getExpansionQuantity()); expandBindings(addBindings, owner.getExpansionQuantity()); } if (deleteBindings != null && !deleteBindings.isEmpty()) { for (List<T> partition : Lists.partition(deleteBindings, getPartitionSize())) { partitions.add(generatePart(partition, null)); lastPartition = partition; } } if (addBindings != null && !addBindings.isEmpty()) { int splitFactor = 0; if (lastPartition != null) { splitFactor = getPartitionSize() - lastPartition.size(); partitions.set(partitions.size() - 1, generatePart(lastPartition, splitFactor > addBindings.size() ? addBindings : addBindings.subList(0, splitFactor))); } for (List<T> partition : Lists.partition( addBindings.subList(splitFactor > addBindings.size() ? 0 : splitFactor, addBindings.size()), getPartitionSize())) { partitions.add(generatePart(null, partition)); } } return partitions; } BindingDispatcher(SxpNode owner); }
BindingDispatcher { <T extends SxpBindingFields> List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitionBindings( SxpConnection connection, List<T> deleteBindings, List<T> addBindings) { List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitions = new ArrayList<>(); List<T> lastPartition = null; if (connection.isVersion4() && !connection.getCapabilitiesRemote().contains(CapabilityType.SubnetBindings) || connection.getVersion().getIntValue() < 3) { expandBindings(deleteBindings, owner.getExpansionQuantity()); expandBindings(addBindings, owner.getExpansionQuantity()); } if (deleteBindings != null && !deleteBindings.isEmpty()) { for (List<T> partition : Lists.partition(deleteBindings, getPartitionSize())) { partitions.add(generatePart(partition, null)); lastPartition = partition; } } if (addBindings != null && !addBindings.isEmpty()) { int splitFactor = 0; if (lastPartition != null) { splitFactor = getPartitionSize() - lastPartition.size(); partitions.set(partitions.size() - 1, generatePart(lastPartition, splitFactor > addBindings.size() ? addBindings : addBindings.subList(0, splitFactor))); } for (List<T> partition : Lists.partition( addBindings.subList(splitFactor > addBindings.size() ? 0 : splitFactor, addBindings.size()), getPartitionSize())) { partitions.add(generatePart(null, partition)); } } return partitions; } BindingDispatcher(SxpNode owner); void setPartitionSize(int partitionSize); void propagateUpdate(List<T> deleteBindings, List<T> addBindings,
                                                             List<SxpConnection> connections); static ListenableFuture<Boolean> sendPurgeAllMessage(final SxpConnection connection); static boolean sendPurgeAllMessageSync(final SxpConnection connection); SxpNode getOwner(); }
BindingDispatcher { <T extends SxpBindingFields> List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitionBindings( SxpConnection connection, List<T> deleteBindings, List<T> addBindings) { List<BiFunction<SxpConnection, SxpBindingFilter, ByteBuf>> partitions = new ArrayList<>(); List<T> lastPartition = null; if (connection.isVersion4() && !connection.getCapabilitiesRemote().contains(CapabilityType.SubnetBindings) || connection.getVersion().getIntValue() < 3) { expandBindings(deleteBindings, owner.getExpansionQuantity()); expandBindings(addBindings, owner.getExpansionQuantity()); } if (deleteBindings != null && !deleteBindings.isEmpty()) { for (List<T> partition : Lists.partition(deleteBindings, getPartitionSize())) { partitions.add(generatePart(partition, null)); lastPartition = partition; } } if (addBindings != null && !addBindings.isEmpty()) { int splitFactor = 0; if (lastPartition != null) { splitFactor = getPartitionSize() - lastPartition.size(); partitions.set(partitions.size() - 1, generatePart(lastPartition, splitFactor > addBindings.size() ? addBindings : addBindings.subList(0, splitFactor))); } for (List<T> partition : Lists.partition( addBindings.subList(splitFactor > addBindings.size() ? 0 : splitFactor, addBindings.size()), getPartitionSize())) { partitions.add(generatePart(null, partition)); } } return partitions; } BindingDispatcher(SxpNode owner); void setPartitionSize(int partitionSize); void propagateUpdate(List<T> deleteBindings, List<T> addBindings,
                                                             List<SxpConnection> connections); static ListenableFuture<Boolean> sendPurgeAllMessage(final SxpConnection connection); static boolean sendPurgeAllMessageSync(final SxpConnection connection); SxpNode getOwner();  }