use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class ManagedNewTransactionRunnerImpl method callWithNewReadWriteTransactionAndSubmit.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public <E extends Exception> ListenableFuture<Void> callWithNewReadWriteTransactionAndSubmit(CheckedConsumer<ReadWriteTransaction, E> txRunner) {
ReadWriteTransaction realTx = broker.newReadWriteTransaction();
ReadWriteTransaction wrappedTx = new NonSubmitCancelableReadWriteTransaction(realTx);
try {
txRunner.accept(wrappedTx);
return realTx.submit();
// catch Exception for both the <E extends Exception> thrown by accept() as well as any RuntimeException
} catch (Exception e) {
if (!realTx.cancel()) {
LOG.error("Transaction.cancel() returned false, which should never happen here");
}
return immediateFailedFuture(e);
}
}
use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project genius by opendaylight.
the class TransportZoneListener method initializeTZNode.
@SuppressWarnings("checkstyle:IllegalCatch")
private void initializeTZNode(DataBroker db) {
ReadWriteTransaction transaction = db.newReadWriteTransaction();
InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class);
CheckedFuture<Optional<TransportZones>, ReadFailedException> tzones = transaction.read(LogicalDatastoreType.CONFIGURATION, path);
try {
if (!tzones.get().isPresent()) {
TransportZonesBuilder tzb = new TransportZonesBuilder();
transaction.put(LogicalDatastoreType.CONFIGURATION, path, tzb.build());
transaction.submit();
} else {
transaction.cancel();
}
} catch (Exception e) {
LOG.error("Error initializing TransportZones {}", e);
}
}
Aggregations