@Override public WriteTransaction newWriteOnlyTransaction() { return new ForwardingWriteTransaction(delegate.newWriteOnlyTransaction()) { @Override public FluentFuture<? extends CommitInfo> commit() { return handleCommit(super::commit); } }; }
@Override public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener(final DataTreeIdentifier<T> treeId, final L listener) { return delegate().registerDataTreeChangeListener(treeId, listener); }
@Override public ReadTransaction newReadOnlyTransaction() { return delegate().newReadOnlyTransaction(); }
@Override public TransactionChain createTransactionChain(final TransactionChainListener listener) { return delegate().createTransactionChain(listener); } }
@Override public ReadWriteTransaction newReadWriteTransaction() { return new ForwardingReadWriteTransaction(delegate.newReadWriteTransaction()) { @Override public <T extends DataObject> FluentFuture<Optional<T>> read(LogicalDatastoreType store, InstanceIdentifier<T> path) { return handleRead(super::read, store, path); } @Override public FluentFuture<? extends CommitInfo> commit() { return handleCommit(super::commit); } }; }
@Override @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE") public <R> R applyWithNewTransactionChainAndClose(final Function<ManagedTransactionChain, R> chainConsumer) { try (TransactionChain realTxChain = getTransactionFactory().createTransactionChain( new TransactionChainListener() { @Override public void onTransactionChainFailed(TransactionChain chain, Transaction transaction, Throwable cause) { LOG.error("Error handling a transaction chain", cause); } @Override public void onTransactionChainSuccessful(TransactionChain chain) { // Nothing to do } })) { return chainConsumer.apply(new ManagedTransactionChainImpl(realTxChain)); } }
@Override public ReadWriteTransaction newReadWriteTransaction() { return delegate().newReadWriteTransaction(); }
@Override public WriteTransaction newWriteOnlyTransaction() { return delegate().newWriteOnlyTransaction(); }
public void createAndRegisterListeners(final int numListeners) { for (int i = 0; i < numListeners; i++) { DsbenchmarkListener listener = new DsbenchmarkListener(); listeners.add(dataBroker.registerDataTreeChangeListener( DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, TEST_EXEC_IID), listener)); listeners.add(dataBroker.registerDataTreeChangeListener( DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, TEST_EXEC_IID), listener)); } LOG.debug("DsbenchmarkListenerProvider created {} listeneres", numListeners); }
private void readInitialAppConfig(final DataBroker dataBroker) { final FluentFuture<Optional<DataObject>> future; try (ReadTransaction readOnlyTx = dataBroker.newReadOnlyTransaction()) { future = readOnlyTx.read(LogicalDatastoreType.CONFIGURATION, bindingContext.appConfigPath); } future.addCallback(new FutureCallback<Optional<DataObject>>() { @Override public void onSuccess(final Optional<DataObject> possibleAppConfig) { LOG.debug("{}: Read of app config {} succeeded: {}", logName(), bindingContext .appConfigBindingClass.getName(), possibleAppConfig); setInitialAppConfig(possibleAppConfig); } @Override public void onFailure(final Throwable failure) { // We may have gotten the app config via the data tree change listener so only retry if not. if (readingInitialAppConfig.get()) { LOG.warn("{}: Read of app config {} failed - retrying", logName(), bindingContext.appConfigBindingClass.getName(), failure); readInitialAppConfig(dataBroker); } } }, MoreExecutors.directExecutor()); }
@Override public void executeList() { final LogicalDatastoreType dsType = getDataStoreType(); final TransactionChain chain = bindingDataBroker.createTransactionChain(this);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); FluentFuture<Optional<Toaster>> readFuture = tx.read(OPERATIONAL, TOASTER_IID);
private void setToasterStatusUp(final Function<Boolean, MakeToastOutput> resultCallback) { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.put(OPERATIONAL,TOASTER_IID, buildToaster(ToasterStatus.Up)); Futures.addCallback(tx.commit(), new FutureCallback<CommitInfo>() { @Override public void onSuccess(final CommitInfo result) { LOG.info("Successfully set ToasterStatus to Up"); notifyCallback(true); } @Override public void onFailure(final Throwable failure) { // We shouldn't get an OptimisticLockFailedException (or any ex) as no // other component should be updating the operational state. LOG.error("Failed to update toaster status", failure); notifyCallback(false); } void notifyCallback(final boolean result) { if (resultCallback != null) { resultCallback.apply(result); } } }, MoreExecutors.directExecutor()); }
public void init() { LOG.info("Initializing..."); Preconditions.checkNotNull(dataBroker, "dataBroker must be set"); dataTreeChangeListenerRegistration = dataBroker.registerDataTreeChangeListener( DataTreeIdentifier.create(CONFIGURATION, TOASTER_IID), this); setToasterStatusUp(null); // Register our MXBean. register(); }
private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) { LOG.debug("Notify existing nodes"); final Pattern nodeRegex = this.nodeIdPattern; final ReadTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction(); final ListenableFuture<Optional<Topology>> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH); Futures.addCallback(future, new FutureCallback<Optional<Topology>>() { @Override public void onSuccess(@Nonnull final Optional<Topology> data) { if (data.isPresent()) { final List<Node> nodes = data.get().getNode(); if (nodes != null) { for (final Node node : nodes) { if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) { notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.key())); } } } } tx.close(); } @Override public void onFailure(final Throwable ex) { LOG.error("Can not notify existing nodes", ex); tx.close(); } }, MoreExecutors.directExecutor()); }
@Override public void executeList() { final TransactionChain chain = bindingDataBroker.createTransactionChain(this); final LogicalDatastoreType dsType = getDataStoreType();
/** * Implemented from the AutoCloseable interface. */ @Override public void close() { LOG.info("Closing..."); // Unregister our MXBean. unregister(); // When we close this service we need to shutdown our executor! executor.shutdown(); if (dataTreeChangeListenerRegistration != null) { dataTreeChangeListenerRegistration.close(); } if (dataBroker != null) { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(OPERATIONAL,TOASTER_IID); Futures.addCallback(tx.commit(), new FutureCallback<CommitInfo>() { @Override public void onSuccess(final CommitInfo result) { LOG.debug("Successfully deleted the operational Toaster"); } @Override public void onFailure(final Throwable failure) { LOG.error("Delete of the operational Toaster failed", failure); } }, MoreExecutors.directExecutor()); } }
private void retrieveInitialAppConfig(final DataBroker dataBroker) { LOG.debug("{}: Got DataBroker instance - reading app config {}", logName(), bindingContext.appConfigPath); setDependencyDesc("Initial app config " + bindingContext.appConfigBindingClass.getSimpleName()); // We register a DTCL to get updates and also read the app config data from the data store. If // the app config data is present then both the read and initial DTCN update will return it. If the // the data isn't present, we won't get an initial DTCN update so the read will indicate the data // isn't present. DataTreeIdentifier<DataObject> dataTreeId = DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, bindingContext.appConfigPath); appConfigChangeListenerReg = dataBroker.registerDataTreeChangeListener(dataTreeId, (ClusteredDataTreeChangeListener<DataObject>) this::onAppConfigChanged); readInitialAppConfig(dataBroker); }
final LogicalDatastoreType dsType = getDataStoreType(); try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) { for (long l = 0; l < outerListElem; l++) {
private void cleanupTestStore() { TestExec data = new TestExecBuilder() .setOuterList(Collections.<OuterList>emptyList()) .build(); WriteTransaction tx = simpleTxDataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.CONFIGURATION, TEST_EXEC_IID, data); try { tx.commit().get(); LOG.debug("DataStore config test data cleaned up"); } catch (final InterruptedException | ExecutionException e) { LOG.info("Failed to cleanup DataStore configtest data"); throw new IllegalStateException(e); } tx = simpleTxDataBroker.newWriteOnlyTransaction(); tx.put(LogicalDatastoreType.OPERATIONAL, TEST_EXEC_IID, data); try { tx.commit().get(); LOG.debug("DataStore operational test data cleaned up"); } catch (final InterruptedException | ExecutionException e) { LOG.info("Failed to cleanup DataStore operational test data"); throw new IllegalStateException(e); } }