Default throttle bucketing interval is 100 millis. + * Returns the throttle bucketing interval in the given time units.
Default throttle bucketing + * interval is 100 millis. * * @param unit the time unit of the interval * @return the bucketing interval for throttling in the given time units diff --git a/src/main/java/net/openhft/chronicle/map/ThrottlingConfigBean.java b/src/main/java/net/openhft/chronicle/map/ThrottlingConfigBean.java new file mode 100644 index 000000000..8d67b336e --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/ThrottlingConfigBean.java @@ -0,0 +1,87 @@ +package net.openhft.chronicle.map; + +import java.util.concurrent.TimeUnit; + +@javax.annotation.Generated("com.google.auto.value.processor.AutoValueProcessor") +final class ThrottlingConfigBean extends ThrottlingConfig { + private final long throttle; + private final TimeUnit throttlePerUnit; + private final long bucketInterval; + private final TimeUnit bucketIntervalUnit; + + ThrottlingConfigBean( + long throttle, + TimeUnit throttlePerUnit, + long bucketInterval, + TimeUnit bucketIntervalUnit) { + this.throttle = throttle; + if (throttlePerUnit == null) { + throw new NullPointerException("Null throttlePerUnit"); + } + this.throttlePerUnit = throttlePerUnit; + this.bucketInterval = bucketInterval; + if (bucketIntervalUnit == null) { + throw new NullPointerException("Null bucketIntervalUnit"); + } + this.bucketIntervalUnit = bucketIntervalUnit; + } + + @Override + long throttle() { + return throttle; + } + + @Override + TimeUnit throttlePerUnit() { + return throttlePerUnit; + } + + @Override + long bucketInterval() { + return bucketInterval; + } + + @Override + TimeUnit bucketIntervalUnit() { + return bucketIntervalUnit; + } + + @Override + public String toString() { + return "ThrottlingConfig{" + + "throttle=" + throttle + + ", throttlePerUnit=" + throttlePerUnit + + ", bucketInterval=" + bucketInterval + + ", bucketIntervalUnit=" + bucketIntervalUnit + + "}"; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof ThrottlingConfig) { + ThrottlingConfig that = (ThrottlingConfig) o; + return (this.throttle == that.throttle()) + && (this.throttlePerUnit.equals(that.throttlePerUnit())) + && (this.bucketInterval == that.bucketInterval()) + && (this.bucketIntervalUnit.equals(that.bucketIntervalUnit())); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= (throttle >>> 32) ^ throttle; + h *= 1000003; + h ^= throttlePerUnit.hashCode(); + h *= 1000003; + h ^= (bucketInterval >>> 32) ^ bucketInterval; + h *= 1000003; + h ^= bucketIntervalUnit.hashCode(); + return h; + } +} diff --git a/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java b/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java index 5d6b39548..2ab0ba098 100644 --- a/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/UdpChannelReplicator.java @@ -209,6 +209,8 @@ class UdpChannelReplicator extends AbstractChannelReplicator implements Replica. final SelectionKey selectionKey = writeChannel.keyFor(this.selector); if (selectionKey != null) selectionKey.interestOps(selectionKey.interestOps() | OP_WRITE); + // we have just enabled it, so don't have to do this again. + shouldEnableOpWrite = false; } catch (Exception e) { LOG.error("", e); } diff --git a/src/main/java/net/openhft/chronicle/map/UdpReplicationConfig.java b/src/main/java/net/openhft/chronicle/map/UdpReplicationConfig.java index 13725a13d..0e02d9e9d 100644 --- a/src/main/java/net/openhft/chronicle/map/UdpReplicationConfig.java +++ b/src/main/java/net/openhft/chronicle/map/UdpReplicationConfig.java @@ -16,14 +16,13 @@ package net.openhft.chronicle.map; -import com.google.auto.value.AutoValue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.net.InetAddress; import java.net.NetworkInterface; -@AutoValue + public abstract class UdpReplicationConfig { /** @@ -36,6 +35,9 @@ public abstract class UdpReplicationConfig { public static UdpReplicationConfig simple(@NotNull InetAddress address, int port) { if (address.isMulticastAddress()) throw new IllegalArgumentException(); + + + return create(address, port, null, ThrottlingConfig.noThrottling()); } @@ -49,7 +51,7 @@ public abstract class UdpReplicationConfig { static UdpReplicationConfig create(InetAddress address, int port, NetworkInterface networkInterface, ThrottlingConfig throttlingConfig) { - return new AutoValue_UdpReplicationConfig(address, port, networkInterface, + return new UdpReplicationConfigBean(address, port, networkInterface, throttlingConfig); } diff --git a/src/main/java/net/openhft/chronicle/map/UdpReplicationConfigBean.java b/src/main/java/net/openhft/chronicle/map/UdpReplicationConfigBean.java new file mode 100644 index 000000000..441aa4eac --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/UdpReplicationConfigBean.java @@ -0,0 +1,89 @@ +package net.openhft.chronicle.map; + +import java.net.InetAddress; +import java.net.NetworkInterface; + + +final class UdpReplicationConfigBean extends UdpReplicationConfig { + private final InetAddress address; + private final int port; + private final NetworkInterface networkInterface; + private final ThrottlingConfig throttlingConfig; + + UdpReplicationConfigBean( + InetAddress address, + int port, + NetworkInterface networkInterface, + ThrottlingConfig throttlingConfig) { + if (address == null) { + throw new NullPointerException("Null address"); + } + this.address = address; + this.port = port; + + this.networkInterface = networkInterface; + if (throttlingConfig == null) { + throw new NullPointerException("Null throttlingConfig"); + } + this.throttlingConfig = throttlingConfig; + } + + @Override + public InetAddress address() { + return address; + } + + @Override + public int port() { + return port; + } + + @Override + public NetworkInterface networkInterface() { + return networkInterface; + } + + @Override + public ThrottlingConfig throttlingConfig() { + return throttlingConfig; + } + + @Override + public String toString() { + return "UdpReplicationConfig{" + + "address=" + address + + ", port=" + port + + ", networkInterface=" + networkInterface + + ", throttlingConfig=" + throttlingConfig + + "}"; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o instanceof UdpReplicationConfig) { + UdpReplicationConfig that = (UdpReplicationConfig) o; + return (this.address.equals(that.address())) + && (this.port == that.port()) + && (this.networkInterface.equals(that.networkInterface())) + && (this.throttlingConfig.equals(that.throttlingConfig())); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= address.hashCode(); + h *= 1000003; + h ^= port; + h *= 1000003; + h ^= networkInterface.hashCode(); + h *= 1000003; + h ^= throttlingConfig.hashCode(); + return h; + } +} diff --git a/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java b/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java new file mode 100644 index 000000000..2797273f8 --- /dev/null +++ b/src/test/java/net/openhft/chronicle/map/NodeDiscoveryHostPortBroadcasterTest.java @@ -0,0 +1,31 @@ +package net.openhft.chronicle.map; + +import junit.framework.TestCase; +import net.openhft.lang.io.ByteBufferBytes; +import net.openhft.lang.io.Bytes; +import org.junit.Test; + +import java.io.IOException; +import java.net.Inet4Address; +import java.nio.ByteBuffer; + +public class NodeDiscoveryHostPortBroadcasterTest extends TestCase { + + @Test + public void test() 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); + + final NodeDiscoveryHostPortBroadcaster nodeDiscoveryHostPortBroadcaster + = new NodeDiscoveryHostPortBroadcaster(udpConfig, 1024, remoteNodes); + + Thread.sleep(5000); + } + + +} \ No newline at end of file diff --git a/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java b/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java index 71690a2b5..3d14cb7fd 100644 --- a/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java +++ b/src/test/java/net/openhft/chronicle/map/UDPSocketReplicationTest.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.map; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import java.io.Closeable; @@ -43,8 +42,8 @@ public class UDPSocketReplicationTest { UdpReplicationConfig udpConfig = UdpReplicationConfig .simple(Inet4Address.getByName("255.255.255.255"), udpPort); - return ChronicleMapBuilder.of(Integer.class, CharSequence.class) + return ChronicleMapBuilder.of(Integer.class, CharSequence.class) .entries(1000) .addReplicator(udp((byte) identifier, udpConfig)) .create(Builder.getPersistenceFile()); @@ -75,7 +74,7 @@ public class UDPSocketReplicationTest { @Test - @Ignore + // @Ignore public void testBufferOverflow() throws IOException, InterruptedException { for (int i = 0; i < 1024; i++) {