HCOLL-134 ( release draft cut of the code so that I can test it across my network )

This commit is contained in:
Rob Austin
2014-09-26 15:23:29 +01:00
parent 26a32c7c58
commit c67673a0a2
2 changed files with 42 additions and 5 deletions
@@ -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();
}
}
@@ -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);
}
}