diff --git a/src/main/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcaster.java b/src/main/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcaster.java index ed88341cd..88a6f6eea 100644 --- a/src/main/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcaster.java +++ b/src/main/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcaster.java @@ -267,6 +267,8 @@ class BytesExternalizableImpl implements BytesExternalizable { this.allNodes = allNodes; } + private final AtomicBoolean modificationsComplete = new AtomicBoolean(true); + /** * this is used to tell nodes that are connecting to us which host and ports are in our grid, along with * all the identifiers. @@ -277,6 +279,8 @@ class BytesExternalizableImpl implements BytesExternalizable { @Override public void writeExternalBytes(@NotNull Bytes destination) { + modificationsComplete.set(true); + if (bootstrapRequired.getAndSet(false)) { //destination.write(BOOTSTRAP_BYTES); BOOTSTRAP_BYTES.clear(); @@ -303,7 +307,8 @@ class BytesExternalizableImpl implements BytesExternalizable { destination.writeUnsignedShort((int) bytes.remaining()); destination.write(bytes); - + if (!(modificationsComplete.get())) + modificationNotifier.onChange(); } @Override @@ -311,7 +316,7 @@ class BytesExternalizableImpl implements BytesExternalizable { if (isBootstrap(source)) { System.out.println("received Bootstrap"); - //modificationNotifier.onChange(); + onChange(); return; } @@ -352,6 +357,11 @@ class BytesExternalizableImpl implements BytesExternalizable { } + private void onChange() { + modificationsComplete.set(false); + modificationNotifier.onChange(); + } + /** * @param source @@ -414,18 +424,18 @@ class BytesExternalizableImpl implements BytesExternalizable { public void sendBootStrap() { bootstrapRequired.set(true); + onChange(); } public void add(InetSocketAddress interfaceAddress) { allNodes.add(interfaceAddress); - modificationNotifier.onChange(); - + onChange(); } public void add(byte identifier) { allNodes.activeIdentifierBitSet().set(identifier); - modificationNotifier.onChange(); + onChange(); } } \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java b/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java index 3226199c7..4dc213935 100644 --- a/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java +++ b/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java @@ -47,4 +47,31 @@ public class NodeDiscoveryHostPortBroadcasterTest extends TestCase { } + + @Test + public void testJustListen() throws IOException, InterruptedException { + + final UdpReplicationConfig udpConfig = UdpReplicationConfig + .simple(Inet4Address.getByName("255.255.255.255"), 1235); + + final Bytes identifierBitSetBits = new ByteBufferBytes(ByteBuffer.allocate(128 / 8)); + + final RemoteNodes remoteNodes = new RemoteNodes(identifierBitSetBits); + + BytesExternalizableImpl externalizable = new BytesExternalizableImpl(remoteNodes); + + + final NodeDiscoveryHostPortBroadcaster nodeDiscoveryHostPortBroadcaster + = new NodeDiscoveryHostPortBroadcaster(udpConfig, 1024, externalizable); + + externalizable.setModificationNotifier(nodeDiscoveryHostPortBroadcaster); + + + Thread.sleep(10000000); + + + + + } + }