Netty Replicator - improve the reconnection and keepalive mechanisms
[mdsal.git] / replicate / mdsal-replicate-netty / src / main / java / org / opendaylight / mdsal / replicate / netty / NettyReplication.java
index 13f9c99eda4663c4f40942a234f703237d1604a2..14aed6437aa23fe9f5e7b4b8af71f80b6410f035 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.mdsal.replicate.netty;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Verify.verify;
 
 import java.net.InetAddress;
@@ -37,20 +38,22 @@ public final class NettyReplication {
     public static Registration createSink(final BootstrapSupport bootstrapSupport, final DOMDataBroker dataBroker,
             final ClusterSingletonServiceProvider singletonService, final boolean enabled,
             final InetAddress sourceAddress, final int sourcePort, final Duration reconnectDelay,
-            final Duration keepaliveInterval) {
+        final Duration keepaliveInterval, final int maxMissedKeepalives) {
         LOG.debug("Sink {}", enabled ? "enabled" : "disabled");
+        checkArgument(maxMissedKeepalives > 0, "max-missed-keepalives %s must be greater than 0", maxMissedKeepalives);
         return enabled ? singletonService.registerClusterSingletonService(new SinkSingletonService(bootstrapSupport,
-            dataBroker, new InetSocketAddress(sourceAddress, sourcePort), reconnectDelay, keepaliveInterval))
-                : new Disabled();
+            dataBroker, new InetSocketAddress(sourceAddress, sourcePort), reconnectDelay, keepaliveInterval,
+            maxMissedKeepalives)) : new Disabled();
     }
 
     public static Registration createSource(final BootstrapSupport bootstrapSupport, final DOMDataBroker dataBroker,
-            final ClusterSingletonServiceProvider singletonService, final boolean enabled, final int listenPort) {
+            final ClusterSingletonServiceProvider singletonService, final boolean enabled, final int listenPort,
+        final Duration keepaliveInterval, final int maxMissedKeepalives) {
         LOG.debug("Source {}", enabled ? "enabled" : "disabled");
         final DOMDataTreeChangeService dtcs = dataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class);
         verify(dtcs != null, "Missing DOMDataTreeChangeService in broker %s", dataBroker);
-
+        checkArgument(maxMissedKeepalives > 0, "max-missed-keepalives %s must be greater than 0", maxMissedKeepalives);
         return enabled ? singletonService.registerClusterSingletonService(new SourceSingletonService(bootstrapSupport,
-            dtcs, listenPort)) : new Disabled();
+            dtcs, listenPort, keepaliveInterval, maxMissedKeepalives)) : new Disabled();
     }
 }