- public Future<RpcResult<UnsubscribeDdtlOutput>> unsubscribeDdtl() {
- LOG.debug("Received unsubscribe-ddtl.");
-
- if (idIntsDdtl == null || ddtlReg == null) {
- final RpcError error = RpcResultBuilder.newError(
- ErrorType.RPC, "Ddtl missing.", "No DOMDataTreeListener registered.");
- return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
- }
-
- ddtlReg.close();
- ddtlReg = null;
-
- final ReadListener readListener = new ReadListener();
- try {
- final ListenerRegistration<ReadListener> registration = domDataTreeService.registerListener(readListener,
- Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
- ProduceTransactionsHandler.ID_INT_YID))
- , true, Collections.emptyList());
-
- final DataTreeCandidate dataTreeCandidate = readListener.getFirstNotif().get();
- registration.close();
-
- if (!dataTreeCandidate.getRootNode().getDataAfter().isPresent()) {
- final RpcError error = RpcResultBuilder.newError(
- ErrorType.APPLICATION, "Final read empty.", "No data read from id-ints list.");
- return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
- .withRpcError(error).build());
- }
-
- final NormalizedNode<?, ?> lastRead = dataTreeCandidate.getRootNode().getDataAfter().get();
-
- return Futures.immediateFuture(
- RpcResultBuilder.success(new UnsubscribeDdtlOutputBuilder()
- .setCopyMatches(idIntsDdtl.checkEqual(lastRead))).build());
-
- } catch (final DOMDataTreeLoopException | InterruptedException | ExecutionException e) {
- LOG.error("Unable to read data to verify ddtl data.", e);
- final RpcError error = RpcResultBuilder.newError(
- ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed.");
- return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
- .withRpcError(error).build());
- }
- }
-
- private static class ReadListener implements DOMDataTreeListener {
-
- private Collection<DataTreeCandidate> changes = null;
- private SettableFuture<DataTreeCandidate> readFuture;
-
- @Override
- public synchronized void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes,
- @Nonnull final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtrees) {
- Preconditions.checkArgument(changes.size() == 1);
-
- if (this.changes == null) {
- this.changes = changes;
-
- readFuture.set(changes.iterator().next());
- }
- }
-
- @Override
- public void onDataTreeFailed(@Nonnull final Collection<DOMDataTreeListeningException> causes) {
- LOG.error("Read Listener failed. {}", causes);
- }
-
- public synchronized ListenableFuture<DataTreeCandidate> getFirstNotif() {
- if (changes != null) {
- return Futures.immediateFuture(changes.iterator().next());
- }
-
- readFuture = SettableFuture.create();
- return readFuture;
- }