Class ManagedNewTransactionRunnerImpl
- java.lang.Object
-
- org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl
-
- All Implemented Interfaces:
ManagedNewTransactionRunner
,ManagedTransactionFactory
@Beta public class ManagedNewTransactionRunnerImpl extends Object implements ManagedNewTransactionRunner
Implementation ofManagedNewTransactionRunner
. This is based onManagedTransactionFactoryImpl
but re-implements operations based on read-write transactions to cancel transactions which don't end up making any changes to the datastore.
-
-
Constructor Summary
Constructors Constructor Description ManagedNewTransactionRunnerImpl(DataBroker broker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <D extends Datastore,E extends Exception,R>
RapplyInterruptiblyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, InterruptibleCheckedFunction<TypedReadTransaction<D>,R,E> txFunction)
Invokes a function with a NEWTypedReadTransaction
, and ensures that that transaction is closed.<D extends Datastore,E extends Exception,R>
RapplyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, CheckedFunction<TypedReadTransaction<D>,R,E> txFunction)
Invokes a function with a NEWTypedReadTransaction
, and ensures that that transaction is closed.<D extends Datastore,E extends Exception,R>
FluentFuture<R>applyWithNewReadWriteTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedFunction<TypedReadWriteTransaction<D>,R,E> txFunction)
Invokes a function with a NEWReadWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception.protected <D extends Datastore,X extends WriteTransaction,W,R,E extends Exception>
FluentFuture<R>applyWithNewTransactionAndSubmit(Class<D> datastoreType, Supplier<X> txSupplier, BiFunction<Class<D>,X,W> txWrapper, InterruptibleCheckedFunction<W,R,E> txFunction, BiFunction<X,W,FluentFuture<?>> txSubmitter)
<R> R
applyWithNewTransactionChainAndClose(Function<ManagedTransactionChain,R> chainConsumer)
Invokes a function with a newManagedTransactionChain
, which is a wrapper around standard transaction chains providing managed semantics.<D extends Datastore,E extends Exception>
voidcallInterruptiblyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedReadTransaction<D>,E> txConsumer)
Invokes a function with a NEWReadTransaction
, and ensures that that transaction is closed.<D extends Datastore,E extends Exception>
voidcallWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, CheckedConsumer<TypedReadTransaction<D>,E> txConsumer)
Invokes a function with a NEWReadTransaction
, and ensures that that transaction is closed.<D extends Datastore,E extends Exception>
FluentFuture<? extends Object>callWithNewReadWriteTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedReadWriteTransaction<D>,E> txConsumer)
Invokes a consumer with a NEWReadWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception.protected <D extends Datastore,X extends WriteTransaction,W,E extends Exception>
FluentFuture<? extends Object>callWithNewTransactionAndSubmit(Class<D> datastoreType, Supplier<X> txSupplier, BiFunction<Class<D>,X,W> txWrapper, InterruptibleCheckedConsumer<W,E> txConsumer, BiFunction<X,W,FluentFuture<?>> txSubmitter)
<D extends Datastore,E extends Exception>
FluentFuture<? extends Object>callWithNewWriteOnlyTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedWriteTransaction<D>,E> txConsumer)
Invokes a consumer with a NEWWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception.protected T
getTransactionFactory()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opendaylight.mdsal.binding.util.ManagedTransactionFactory
applyInterruptiblyWithNewReadOnlyTransactionAndClose, applyWithNewReadOnlyTransactionAndClose, callInterruptiblyWithNewReadOnlyTransactionAndClose, callWithNewReadOnlyTransactionAndClose
-
-
-
-
Constructor Detail
-
ManagedNewTransactionRunnerImpl
@Inject public ManagedNewTransactionRunnerImpl(DataBroker broker)
-
-
Method Detail
-
applyWithNewReadWriteTransactionAndSubmit
@CheckReturnValue public <D extends Datastore,E extends Exception,R> FluentFuture<R> applyWithNewReadWriteTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedFunction<TypedReadWriteTransaction<D>,R,E> txFunction)
Description copied from interface:ManagedTransactionFactory
Invokes a function with a NEWReadWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception. Thus when this method returns, that transaction is guaranteed to have been either submitted or cancelled, and will never "leak" and waste memory.The function must not itself use
WriteTransaction.cancel()
, orWriteTransaction.commit()
(it will throw anUnsupportedOperationException
).The provided transaction is specific to the given logical datastore type and cannot be used for any other.
This is an asynchronous API, like
DataBroker
's own; when returning from this method, the operation of the Transaction may well still be ongoing in the background, or pending; calling code therefore must handle the returned future, e.g. by passing it onwards (return), or by itself adding callback listeners to it usingFutures
' methods, or by transforming it into aCompletionStage
(but better NOT by using the blockingFuture.get()
on it).- Specified by:
applyWithNewReadWriteTransactionAndSubmit
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxFunction
- theInterruptibleCheckedFunction
that needs a new read-write transaction- Returns:
- the
FluentFuture
returned byWriteTransaction.commit()
, or a failed future with an application specific exception (not from submit())
-
applyWithNewTransactionChainAndClose
public <R> R applyWithNewTransactionChainAndClose(Function<ManagedTransactionChain,R> chainConsumer)
Description copied from interface:ManagedNewTransactionRunner
Invokes a function with a newManagedTransactionChain
, which is a wrapper around standard transaction chains providing managed semantics. The transaction chain will be closed when the function returns.This is an asynchronous API, like
DataBroker
's own; when this method returns, the transactions in the chain may well still be ongoing in the background, or pending. It is up to the consumer and caller to agree on how failure will be handled; for example, the return type can include the futures corresponding to the transactions in the chain. The implementation uses a default transaction chain listener which logs an error if any of the transactions fail.The MD-SAL transaction chain semantics are preserved: each transaction in the chain will see the results of the previous transactions in the chain, even if they haven't been fully committed yet; and any error will result in subsequent transactions in the chain not being submitted.
- Specified by:
applyWithNewTransactionChainAndClose
in interfaceManagedNewTransactionRunner
- Type Parameters:
R
- The type of result returned by the function.- Parameters:
chainConsumer
- TheFunction
that will build transactions in the transaction chain.- Returns:
- The result of the function call.
-
callWithNewReadWriteTransactionAndSubmit
@CheckReturnValue public <D extends Datastore,E extends Exception> FluentFuture<? extends Object> callWithNewReadWriteTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedReadWriteTransaction<D>,E> txConsumer)
Description copied from interface:ManagedTransactionFactory
Invokes a consumer with a NEWReadWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception. Thus when this method returns, that transaction is guaranteed to have been either submitted or cancelled, and will never "leak" and waste memory.The consumer should not (cannot) itself use
WriteTransaction.cancel()
, orWriteTransaction.commit()
(it will throw anUnsupportedOperationException
).The provided transaction is specific to the given logical datastore type and cannot be used for any other.
This is an asynchronous API, like
DataBroker
's own; when returning from this method, the operation of the Transaction may well still be ongoing in the background, or pending; calling code therefore must handle the returned future, e.g. by passing it onwards (return), or by itself adding callback listeners to it usingFutures
' methods, or by transforming it into aCompletionStage
(but better NOT by using the blockingFuture.get()
on it).- Specified by:
callWithNewReadWriteTransactionAndSubmit
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxConsumer
- theInterruptibleCheckedConsumer
that needs a new read-write transaction- Returns:
- the
FluentFuture
returned byWriteTransaction.commit()
, or a failed future with an application specific exception (not from submit())
-
callWithNewWriteOnlyTransactionAndSubmit
@CheckReturnValue public <D extends Datastore,E extends Exception> FluentFuture<? extends Object> callWithNewWriteOnlyTransactionAndSubmit(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedWriteTransaction<D>,E> txConsumer)
Description copied from interface:ManagedTransactionFactory
Invokes a consumer with a NEWWriteTransaction
, and then submits that transaction and returns the Future from that submission, or cancels it if an exception was thrown and returns a failed future with that exception. Thus when this method returns, that transaction is guaranteed to have been either submitted or cancelled, and will never "leak" and waste memory.The consumer should not (cannot) itself use
WriteTransaction.cancel()
, orWriteTransaction.commit()
(it will throw anUnsupportedOperationException
).The provided transaction is specific to the given logical datastore type and cannot be used for any other.
This is an asynchronous API, like
DataBroker
's own; when returning from this method, the operation of the Transaction may well still be ongoing in the background, or pending; calling code therefore must handle the returned future, e.g. by passing it onwards (return), or by itself adding callback listeners to it usingFutures
' methods, or by transforming it into aCompletionStage
(but better NOT by using the blockingFuture.get()
on it).- Specified by:
callWithNewWriteOnlyTransactionAndSubmit
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxConsumer
- theInterruptibleCheckedConsumer
that needs a new write only transaction- Returns:
- the
FluentFuture
returned byWriteTransaction.commit()
, or a failed future with an application specific exception (not from submit())
-
applyInterruptiblyWithNewReadOnlyTransactionAndClose
public <D extends Datastore,E extends Exception,R> R applyInterruptiblyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, InterruptibleCheckedFunction<TypedReadTransaction<D>,R,E> txFunction) throws E extends Exception, InterruptedException
Description copied from interface:ManagedTransactionFactory
Invokes a function with a NEWTypedReadTransaction
, and ensures that that transaction is closed. Thus when this method returns, that transaction is guaranteed to have been closed, and will never "leak" and waste memory.The function must not itself attempt to close the transaction. (It can't directly, since
TypedReadTransaction
doesn't expose aclose()
method.)The provided transaction is specific to the given logical datastore type and cannot be used for any other.
- Specified by:
applyInterruptiblyWithNewReadOnlyTransactionAndClose
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxFunction
- theInterruptibleCheckedFunction
that needs a new read transaction- Returns:
- the result of the function.
- Throws:
E
- if an error occurs.InterruptedException
- if the function is interrupted (this is passed through from the provided function).E extends Exception
-
applyWithNewReadOnlyTransactionAndClose
public <D extends Datastore,E extends Exception,R> R applyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, CheckedFunction<TypedReadTransaction<D>,R,E> txFunction) throws E extends Exception
Description copied from interface:ManagedTransactionFactory
Invokes a function with a NEWTypedReadTransaction
, and ensures that that transaction is closed. Thus when this method returns, that transaction is guaranteed to have been closed, and will never "leak" and waste memory.The function must not itself attempt to close the transaction. (It can't directly, since
TypedReadTransaction
doesn't expose aclose()
method.)The provided transaction is specific to the given logical datastore type and cannot be used for any other.
- Specified by:
applyWithNewReadOnlyTransactionAndClose
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxFunction
- theInterruptibleCheckedFunction
that needs a new read transaction- Returns:
- the result of the function.
- Throws:
E
- if an error occurs.E extends Exception
-
callInterruptiblyWithNewReadOnlyTransactionAndClose
public <D extends Datastore,E extends Exception> void callInterruptiblyWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, InterruptibleCheckedConsumer<TypedReadTransaction<D>,E> txConsumer) throws E extends Exception, InterruptedException
Description copied from interface:ManagedTransactionFactory
Invokes a function with a NEWReadTransaction
, and ensures that that transaction is closed. Thus when this method returns, that transaction is guaranteed to have been closed, and will never "leak" and waste memory.The function must not itself attempt to close the transaction. (It can't directly, since
ReadTransaction
doesn't expose aclose()
method.)The provided transaction is specific to the given logical datastore type and cannot be used for any other.
- Specified by:
callInterruptiblyWithNewReadOnlyTransactionAndClose
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxConsumer
- theInterruptibleCheckedFunction
that needs a new read transaction- Throws:
E
- if an error occurs.InterruptedException
- if the function is interrupted (this is passed through from the provided function).E extends Exception
-
callWithNewReadOnlyTransactionAndClose
public <D extends Datastore,E extends Exception> void callWithNewReadOnlyTransactionAndClose(Class<D> datastoreType, CheckedConsumer<TypedReadTransaction<D>,E> txConsumer) throws E extends Exception
Description copied from interface:ManagedTransactionFactory
Invokes a function with a NEWReadTransaction
, and ensures that that transaction is closed. Thus when this method returns, that transaction is guaranteed to have been closed, and will never "leak" and waste memory.The function must not itself attempt to close the transaction. (It can't directly, since
ReadTransaction
doesn't expose aclose()
method.)The provided transaction is specific to the given logical datastore type and cannot be used for any other.
- Specified by:
callWithNewReadOnlyTransactionAndClose
in interfaceManagedTransactionFactory
- Parameters:
datastoreType
- theDatastore
type that will be accessedtxConsumer
- theInterruptibleCheckedFunction
that needs a new read transaction- Throws:
E
- if an error occurs.E extends Exception
-
callWithNewTransactionAndSubmit
@CheckReturnValue protected <D extends Datastore,X extends WriteTransaction,W,E extends Exception> FluentFuture<? extends Object> callWithNewTransactionAndSubmit(Class<D> datastoreType, Supplier<X> txSupplier, BiFunction<Class<D>,X,W> txWrapper, InterruptibleCheckedConsumer<W,E> txConsumer, BiFunction<X,W,FluentFuture<?>> txSubmitter)
-
applyWithNewTransactionAndSubmit
@CheckReturnValue protected <D extends Datastore,X extends WriteTransaction,W,R,E extends Exception> FluentFuture<R> applyWithNewTransactionAndSubmit(Class<D> datastoreType, Supplier<X> txSupplier, BiFunction<Class<D>,X,W> txWrapper, InterruptibleCheckedFunction<W,R,E> txFunction, BiFunction<X,W,FluentFuture<?>> txSubmitter)
-
getTransactionFactory
protected T getTransactionFactory()
-
-