X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2FMdsalLowLevelTestProvider.java;h=10dafba452be749dbafd447f93c70b65ccd2f1e3;hb=HEAD;hp=e700e6696b69432ec15985c456e45dc4bb1f5f9f;hpb=60bb47b5ce43a0bdbd297130d1321bb1fb5f7ba3;p=controller.git diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java index e700e6696b..10dafba452 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java @@ -12,7 +12,6 @@ import akka.dispatch.Futures; import akka.dispatch.OnComplete; import akka.pattern.Patterns; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.util.HashMap; @@ -41,15 +40,12 @@ import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; -import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; -import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; +import org.opendaylight.mdsal.dom.api.DOMDataBroker.DataTreeChangeExtension; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction; -import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration; import org.opendaylight.mdsal.dom.api.DOMRpcProviderService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; -import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; -import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; +import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.AddShardReplica; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.AddShardReplicaInput; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.AddShardReplicaOutput; @@ -133,10 +129,11 @@ import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.l import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactions; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsInput; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput; -import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.target.rev170215.IdSequence; +import org.opendaylight.yangtools.concepts.AbstractObjectRegistration; +import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.Rpc; import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -163,19 +160,17 @@ public final class MdsalLowLevelTestProvider { private final NotificationService notificationService; private final ClusterSingletonServiceProvider singletonService; private final DOMRpcProviderService domRpcService; - private final DOMDataTreeChangeService domDataTreeChangeService; + private final DataTreeChangeExtension dataTreeChangeExtension; - private final Map, DOMRpcImplementationRegistration> - routedRegistrations = new HashMap<>(); - - private final Map> ynlRegistrations = new HashMap<>(); + private final Map, Registration> routedRegistrations = new HashMap<>(); + private final Map> ynlRegistrations = new HashMap<>(); + private final Map publishNotificationsTasks = new HashMap<>(); - private DOMRpcImplementationRegistration globalGetConstantRegistration = null; - private ClusterSingletonServiceRegistration getSingletonConstantRegistration; + private Registration globalGetConstantRegistration = null; + private Registration getSingletonConstantRegistration; private FlappingSingletonService flappingSingletonService; - private ListenerRegistration dtclReg; + private Registration dtclReg; private IdIntsListener idIntsListener; - private final Map publishNotificationsTasks = new HashMap<>(); @Inject @Activate @@ -197,33 +192,32 @@ public final class MdsalLowLevelTestProvider { this.domDataBroker = domDataBroker; this.configDataStore = configDataStore; - domDataTreeChangeService = domDataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class); - - registration = rpcRegistry.registerRpcImplementations(ImmutableClassToInstanceMap.>builder() - .put(UnregisterSingletonConstant.class, this::unregisterSingletonConstant) - .put(StartPublishNotifications.class, this::startPublishNotifications) - .put(SubscribeDdtl.class, this::subscribeDdtl) - .put(WriteTransactions.class, this::writeTransactions) - .put(IsClientAborted.class, this::isClientAborted) - .put(RemoveShardReplica.class, this::removeShardReplica) - .put(SubscribeYnl.class, this::subscribeYnl) - .put(UnregisterBoundConstant.class, this::unregisterBoundConstant) - .put(RegisterSingletonConstant.class, this::registerSingletonConstant) - .put(RegisterDefaultConstant.class, this::registerDefaultConstant) - .put(UnregisterConstant.class, this::unregisterConstant) - .put(UnregisterFlappingSingleton.class, this::unregisterFlappingSingleton) - .put(AddShardReplica.class, this::addShardReplica) - .put(RegisterBoundConstant.class, this::registerBoundConstant) - .put(RegisterFlappingSingleton.class, this::registerFlappingSingleton) - .put(UnsubscribeDdtl.class, this::unsubscribeDdtl) - .put(UnsubscribeYnl.class, this::unsubscribeYnl) - .put(CheckPublishNotifications.class, this::checkPublishNotifications) - .put(ShutdownShardReplica.class, this::shutdownShardReplica) - .put(RegisterConstant.class, this::registerConstant) - .put(UnregisterDefaultConstant.class, this::unregisterDefaultConstant) - .put(SubscribeDtcl.class, this::subscribeDtcl) - .put(UnsubscribeDtcl.class, this::unsubscribeDtcl) - .build()); + dataTreeChangeExtension = domDataBroker.extension(DataTreeChangeExtension.class); + + registration = rpcRegistry.registerRpcImplementations( + (UnregisterSingletonConstant) this::unregisterSingletonConstant, + (StartPublishNotifications) this::startPublishNotifications, + (SubscribeDdtl) this::subscribeDdtl, + (WriteTransactions) this::writeTransactions, + (IsClientAborted) this::isClientAborted, + (RemoveShardReplica) this::removeShardReplica, + (SubscribeYnl) this::subscribeYnl, + (UnregisterBoundConstant) this::unregisterBoundConstant, + (RegisterSingletonConstant) this::registerSingletonConstant, + (RegisterDefaultConstant) this::registerDefaultConstant, + (UnregisterConstant) this::unregisterConstant, + (UnregisterFlappingSingleton) this::unregisterFlappingSingleton, + (AddShardReplica) this::addShardReplica, + (RegisterBoundConstant) this::registerBoundConstant, + (RegisterFlappingSingleton) this::registerFlappingSingleton, + (UnsubscribeDdtl) this::unsubscribeDdtl, + (UnsubscribeYnl) this::unsubscribeYnl, + (CheckPublishNotifications) this::checkPublishNotifications, + (ShutdownShardReplica) this::shutdownShardReplica, + (RegisterConstant) this::registerConstant, + (UnregisterDefaultConstant) this::unregisterDefaultConstant, + (SubscribeDtcl) this::subscribeDtcl, + (UnsubscribeDtcl) this::unsubscribeDtcl); } @PreDestroy @@ -281,8 +275,8 @@ public final class MdsalLowLevelTestProvider { idIntsListener = new IdIntsListener(); - dtclReg = domDataTreeChangeService.registerDataTreeChangeListener( - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, WriteTransactionsHandler.ID_INT_YID), + dtclReg = dataTreeChangeExtension.registerTreeChangeListener( + DOMDataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, WriteTransactionsHandler.ID_INT_YID), idIntsListener); return RpcResultBuilder.success(new SubscribeDtclOutputBuilder().build()).buildFuture(); @@ -311,8 +305,15 @@ public final class MdsalLowLevelTestProvider { .buildFuture(); } - ynlRegistrations.put(input.getId(), - notificationService.registerNotificationListener(new YnlListener(input.getId()))); + final var id = input.getId(); + final var listener = new YnlListener(id); + final var reg = notificationService.registerListener(IdSequence.class, listener); + ynlRegistrations.put(id, new AbstractObjectRegistration<>(listener) { + @Override + protected void removeRegistration() { + reg.close(); + } + }); return RpcResultBuilder.success(new SubscribeYnlOutputBuilder().build()).buildFuture(); } @@ -322,9 +323,7 @@ public final class MdsalLowLevelTestProvider { final UnregisterBoundConstantInput input) { LOG.info("In unregisterBoundConstant - {}", input); - final DOMRpcImplementationRegistration rpcRegistration = - routedRegistrations.remove(input.getContext()); - + final var rpcRegistration = routedRegistrations.remove(input.getContext()); if (rpcRegistration == null) { return RpcResultBuilder.failed() .withError(ErrorType.RPC, ErrorTag.DATA_MISSING, @@ -418,9 +417,8 @@ public final class MdsalLowLevelTestProvider { .buildFuture(); } - final DOMRpcImplementationRegistration rpcRegistration = - RoutedGetConstantService.registerNew(bindingNormalizedNodeSerializer, domRpcService, - input.getConstant(), input.getContext()); + final var rpcRegistration = RoutedGetConstantService.registerNew(bindingNormalizedNodeSerializer, domRpcService, + input.getConstant(), input.getContext()); routedRegistrations.put(input.getContext(), rpcRegistration); return RpcResultBuilder.success(new RegisterBoundConstantOutputBuilder().build()).buildFuture(); @@ -505,12 +503,11 @@ public final class MdsalLowLevelTestProvider { .buildFuture(); } - final ListenerRegistration reg = ynlRegistrations.remove(input.getId()); - final UnsubscribeYnlOutput output = reg.getInstance().getOutput(); - - reg.close(); - - return RpcResultBuilder.success().withResult(output).buildFuture(); + try (var reg = ynlRegistrations.remove(input.getId())) { + return RpcResultBuilder.success() + .withResult(reg.getInstance().getOutput()) + .buildFuture(); + } } private ListenableFuture> checkPublishNotifications(