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;
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;
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;
private final NotificationService notificationService;
private final ClusterSingletonServiceProvider singletonService;
private final DOMRpcProviderService domRpcService;
- private final DOMDataTreeChangeService domDataTreeChangeService;
+ private final DataTreeChangeExtension dataTreeChangeExtension;
- private final Map<InstanceIdentifier<?>, DOMRpcImplementationRegistration<RoutedGetConstantService>>
- routedRegistrations = new HashMap<>();
-
- private final Map<String, ListenerRegistration<YnlListener>> ynlRegistrations = new HashMap<>();
+ private final Map<InstanceIdentifier<?>, Registration> routedRegistrations = new HashMap<>();
+ private final Map<String, ObjectRegistration<YnlListener>> ynlRegistrations = new HashMap<>();
+ private final Map<String, PublishNotificationsTask> publishNotificationsTasks = new HashMap<>();
- private DOMRpcImplementationRegistration<GetConstantService> globalGetConstantRegistration = null;
- private ClusterSingletonServiceRegistration getSingletonConstantRegistration;
+ private Registration globalGetConstantRegistration = null;
+ private Registration getSingletonConstantRegistration;
private FlappingSingletonService flappingSingletonService;
- private ListenerRegistration<DOMDataTreeChangeListener> dtclReg;
+ private Registration dtclReg;
private IdIntsListener idIntsListener;
- private final Map<String, PublishNotificationsTask> publishNotificationsTasks = new HashMap<>();
@Inject
@Activate
this.domDataBroker = domDataBroker;
this.configDataStore = configDataStore;
- domDataTreeChangeService = domDataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class);
-
- registration = rpcRegistry.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>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
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();
.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();
}
final UnregisterBoundConstantInput input) {
LOG.info("In unregisterBoundConstant - {}", input);
- final DOMRpcImplementationRegistration<RoutedGetConstantService> rpcRegistration =
- routedRegistrations.remove(input.getContext());
-
+ final var rpcRegistration = routedRegistrations.remove(input.getContext());
if (rpcRegistration == null) {
return RpcResultBuilder.<UnregisterBoundConstantOutput>failed()
.withError(ErrorType.RPC, ErrorTag.DATA_MISSING,
.buildFuture();
}
- final DOMRpcImplementationRegistration<RoutedGetConstantService> 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();
.buildFuture();
}
- final ListenerRegistration<YnlListener> reg = ynlRegistrations.remove(input.getId());
- final UnsubscribeYnlOutput output = reg.getInstance().getOutput();
-
- reg.close();
-
- return RpcResultBuilder.<UnsubscribeYnlOutput>success().withResult(output).buildFuture();
+ try (var reg = ynlRegistrations.remove(input.getId())) {
+ return RpcResultBuilder.<UnsubscribeYnlOutput>success()
+ .withResult(reg.getInstance().getOutput())
+ .buildFuture();
+ }
}
private ListenableFuture<RpcResult<CheckPublishNotificationsOutput>> checkPublishNotifications(