2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.replicate.netty;
10 import static com.google.common.base.Verify.verify;
12 import java.net.InetAddress;
13 import java.net.InetSocketAddress;
14 import java.time.Duration;
15 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.yangtools.concepts.AbstractRegistration;
19 import org.opendaylight.yangtools.concepts.Registration;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public final class NettyReplication {
24 private static final Logger LOG = LoggerFactory.getLogger(NettyReplication.class);
26 private static final class Disabled extends AbstractRegistration {
28 protected void removeRegistration() {
33 private NettyReplication() {
37 public static Registration createSink(final BootstrapSupport bootstrapSupport, final DOMDataBroker dataBroker,
38 final ClusterSingletonServiceProvider singletonService, final boolean enabled,
39 final InetAddress sourceAddress, final int sourcePort, final Duration reconnectDelay) {
40 LOG.debug("Sink {}", enabled ? "enabled" : "disabled");
41 return enabled ? singletonService.registerClusterSingletonService(new SinkSingletonService(bootstrapSupport,
42 dataBroker, new InetSocketAddress(sourceAddress, sourcePort), reconnectDelay)) : new Disabled();
45 public static Registration createSource(final BootstrapSupport bootstrapSupport, final DOMDataBroker dataBroker,
46 final ClusterSingletonServiceProvider singletonService, final boolean enabled, final int listenPort) {
47 LOG.debug("Source {}", enabled ? "enabled" : "disabled");
48 final DOMDataTreeChangeService dtcs = dataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class);
49 verify(dtcs != null, "Missing DOMDataTreeChangeService in broker %s", dataBroker);
51 return enabled ? singletonService.registerClusterSingletonService(new SourceSingletonService(bootstrapSupport,
52 dtcs, listenPort)) : new Disabled();