From bddc37a44a42d9914ed5b41de3584029427188d6 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 9 Oct 2014 18:05:11 +0100 Subject: [PATCH] minor refactors --- .../openhft/chronicle/map/NodeDiscovery.java | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java index 2a1c3d202..90b15382b 100644 --- a/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java +++ b/src/main/java/net/openhft/chronicle/map/NodeDiscovery.java @@ -20,9 +20,9 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import static java.nio.ByteBuffer.allocateDirect; -import static java.nio.ByteBuffer.wrap; import static java.util.concurrent.TimeUnit.SECONDS; import static net.openhft.chronicle.map.ConcurrentExpiryMap.getDefaultAddress; +import static net.openhft.chronicle.map.DiscoveryNodeBytesMarshallable.ProposedNodes; import static net.openhft.chronicle.map.NodeDiscoveryBroadcaster.BOOTSTRAP_BYTES; import static net.openhft.chronicle.map.NodeDiscoveryBroadcaster.LOG; import static net.openhft.chronicle.map.Replicators.tcp; @@ -70,20 +70,19 @@ public class NodeDiscovery { final AtomicInteger ourProposedIdentifier = new AtomicInteger(); final AtomicBoolean useAnotherIdentifier = new AtomicBoolean(); - final Set knownHostPorts = new ConcurrentSkipListSet(); final DirectBitSet knownAndProposedIdentifiers = new ATSDirectBitSet(new ByteBufferBytes(ByteBuffer.allocate (128 / 8))); - final AtomicReference countDownLatch = new AtomicReference(new - CountDownLatch(1)); + final AtomicReference countDownLatch + = new AtomicReference(new CountDownLatch(1)); final NodeDiscoveryEventListener nodeDiscoveryEventListener = new NodeDiscoveryEventListener() { @Override - public void onRemoteNodeEvent(KnownNodes remoteNodes, - ConcurrentExpiryMap proposedIdentifiersWithHost) { + public void onRemoteNodeEvent(@NotNull final KnownNodes remoteNodes, + @NotNull final ConcurrentExpiryMap proposedIdentifiersWithHost) { LOG.info("onRemoteNodeEvent " + remoteNodes + ", proposedIdentifiersWithHost=" + proposedIdentifiersWithHost); @@ -91,7 +90,7 @@ public class NodeDiscovery { orBitSets(remoteNodes.identifiers(), knownAndProposedIdentifiers); - for (DiscoveryNodeBytesMarshallable.ProposedNodes proposedIdentifierWithHost : + for (ProposedNodes proposedIdentifierWithHost : proposedIdentifiersWithHost.values()) { if (!proposedIdentifierWithHost.addressAndPort().equals(ourAddressAndPort)) { @@ -116,8 +115,8 @@ public class NodeDiscovery { nodeDiscoveryEventListenerAtomicReference.set(nodeDiscoveryEventListener); - final DiscoveryNodeBytesMarshallable.ProposedNodes ourHostPort = new - DiscoveryNodeBytesMarshallable.ProposedNodes(ourAddressAndPort, (byte) -1); + final ProposedNodes ourHostPort = new + ProposedNodes(ourAddressAndPort, (byte) -1); // to start with we will send a bootstrap that just contains our hostname without and identifier @@ -149,8 +148,8 @@ public class NodeDiscovery { isFistTime = false; - final DiscoveryNodeBytesMarshallable.ProposedNodes proposedNodes = new - DiscoveryNodeBytesMarshallable.ProposedNodes(ourAddressAndPort, identifier); + final ProposedNodes proposedNodes = new + ProposedNodes(ourAddressAndPort, identifier); Thread.sleep(100); @@ -234,6 +233,7 @@ public class NodeDiscovery { addresses[i++] = new InetSocketAddress(InetAddress.getByAddress(addressAndPort.address()) .getHostAddress(), addressAndPort.port()); } + return addresses; } @@ -303,17 +303,6 @@ public class NodeDiscovery { } } - /** - * creates a bit set based on a number of bits - * - * @param numberOfBits the number of bits the bit set should include - * @return a new DirectBitSet backed by a byteBuffer - */ - private static DirectBitSet newBitSet(int numberOfBits) { - final ByteBufferBytes bytes = new ByteBufferBytes(wrap(new byte[(numberOfBits + 7) / 8])); - return new ATSDirectBitSet(bytes); - } - } /** @@ -938,7 +927,7 @@ interface NodeDiscoveryEventListener { /** * called when we have received a UDP message, this is called after the message has been parsed */ - void onRemoteNodeEvent(KnownNodes remoteNode, ConcurrentExpiryMap proposedIdentifiersWithHost); + void onRemoteNodeEvent(KnownNodes remoteNode, ConcurrentExpiryMap proposedIdentifiersWithHost); } class ConcurrentExpiryMap implements BytesMarshallable {