+
+ @Override
+ public Future<RpcResult<java.lang.Void>> registerLoggingDcl() {
+ LOG.info("Registering a new CarDataChangeListener");
+ final ListenerRegistration carsDclRegistration = dataProvider.registerDataChangeListener(
+ LogicalDatastoreType.CONFIGURATION, CARS_IID, new CarDataChangeListener(),
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+
+ if (carsDclRegistration != null) {
+ carsDclRegistrations.add(carsDclRegistration);
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+ return RpcResultBuilder.<Void>failed().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> registerLoggingDtcl() {
+ LOG.info("Registering a new CarDataTreeChangeListener");
+ final ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration =
+ dataProvider.registerDataTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener());
+
+ if (carsDtclRegistration != null) {
+ carsDtclRegistrations.add(carsDtclRegistration);
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+ return RpcResultBuilder.<Void>failed().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> unregisterLoggingDcls() {
+ LOG.info("Unregistering the CarDataChangeListener(s)");
+ synchronized (carsDclRegistrations) {
+ int numListeners = 0;
+ for (ListenerRegistration<DataChangeListener> carsDclRegistration : carsDclRegistrations) {
+ carsDclRegistration.close();
+ numListeners++;
+ }
+ carsDclRegistrations.clear();
+ LOG.info("Unregistered {} CarDataChangeListener(s)", numListeners);
+ }
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> unregisterLoggingDtcls() {
+ LOG.info("Unregistering the CarDataTreeChangeListener(s)");
+ synchronized (carsDtclRegistrations) {
+ int numListeners = 0;
+ for (ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration : carsDtclRegistrations) {
+ carsDtclRegistration.close();
+ numListeners++;
+ }
+ carsDtclRegistrations.clear();
+ LOG.info("Unregistered {} CaraDataTreeChangeListener(s)", numListeners);
+ }
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ @Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public Future<RpcResult<Void>> unregisterCommitCohort() {
+ final DOMDataTreeCommitCohortRegistration<CarEntryDataTreeCommitCohort> reg = commitCohortReg.getAndSet(null);
+ if (reg != null) {
+ try {
+ reg.close();
+ LOG.info("Unregistered commit cohort");
+ } catch (Exception e) {
+ return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
+ "Error closing commit cohort registration", e).buildFuture();
+ }
+ }
+
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ @Override
+ public synchronized Future<RpcResult<Void>> registerCommitCohort() {
+ if (commitCohortReg.get() != null) {
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ final DOMDataTreeCommitCohortRegistry commitCohortRegistry = (DOMDataTreeCommitCohortRegistry)
+ domDataBroker.getSupportedExtensions().get(DOMDataTreeCommitCohortRegistry.class);
+
+ if (commitCohortRegistry == null) {
+ // Shouldn't happen
+ return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
+ "DOMDataTreeCommitCohortRegistry not found").buildFuture();
+ }
+
+ // Note: it may look strange that we specify the CarEntry.QNAME twice in the path below. This must be done in
+ // order to register the commit cohort for CarEntry instances. In the underlying data tree, a yang list is
+ // represented as a MapNode with MapEntryNodes representing the child list entries. Therefore, in order to
+ // address a list entry, you must specify the path argument for the MapNode and the path argument for the
+ // MapEntryNode. In the path below, the first CarEntry.QNAME argument addresses the MapNode and, since we want
+ // to address all list entries, the second path argument is wild-carded by specifying just the CarEntry.QNAME.
+ final YangInstanceIdentifier carEntryPath = YangInstanceIdentifier.builder(
+ YangInstanceIdentifier.of(Cars.QNAME)).node(CarEntry.QNAME).node(CarEntry.QNAME).build();
+ commitCohortReg.set(commitCohortRegistry.registerCommitCohort(
+ new org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier(
+ org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION,
+ carEntryPath), new CarEntryDataTreeCommitCohort()));
+
+ LOG.info("Registered commit cohort");
+
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }