Class TransactionResourceManager
- java.lang.Object
-
- cz.o2.proxima.direct.core.transaction.TransactionResourceManager
-
- All Implemented Interfaces:
ClientTransactionManager,ServerTransactionManager,TransactionManager,java.lang.AutoCloseable
@Internal @ThreadSafe public class TransactionResourceManager extends java.lang.Object implements ClientTransactionManager, ServerTransactionManager
Manager of open transactional resources - e.g. writers, commit-log readers, etc.The implementation is thread-safe in the sense it is okay to access this class from multiple threads, with different transactions. The same transaction must be processed from single thread only, otherwise the behavior is undefined.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cz.o2.proxima.direct.core.transaction.ServerTransactionManager
ServerTransactionManager.InitialSequenceIdPolicy, ServerTransactionManager.ServerTransactionConfig
-
-
Constructor Summary
Constructors Constructor Description TransactionResourceManager(DirectDataOperator direct, java.util.Map<java.lang.String,java.lang.Object> cfg)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<Response>begin(java.lang.String transactionId, java.util.List<KeyAttribute> attributes)Initialize new transaction.voidclose()java.util.concurrent.CompletableFuture<Response>commit(java.lang.String transactionId, java.util.Collection<StreamElement> outputs)Commit the transaction with given output KeyAttributes being written.voidensureTransactionOpen(java.lang.String transactionId, State state)Ensure that the given transaction ID is initialized.StategetCurrentState(java.lang.String transactionId)Retrieve current state of the transaction.voidhouseKeeping()Called by the server to signal that the manager should reclaim any resources that are not needed anymore.voidrelease(java.lang.String transactionId)Release resources associated with given transaction.java.util.concurrent.CompletableFuture<Response>rollback(java.lang.String transactionId)Rollback transaction with given ID.voidrunObservations(java.lang.String name, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateConsumer, CommitLogObserver requestObserver)Observe all transactional families with given observer.voidsetTransactionTimeoutMs(long timeoutMs)java.util.concurrent.CompletableFuture<Response>updateTransaction(java.lang.String transactionId, java.util.List<KeyAttribute> newAttributes)Update the transaction with additional attributes related to the transaction.voidwriteResponseAndUpdateState(java.lang.String transactionId, State updateState, java.lang.String responseId, Response response, CommitCallback callback)Atomically write response and update state of a transaction-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cz.o2.proxima.direct.core.transaction.ServerTransactionManager
getCfg
-
Methods inherited from interface cz.o2.proxima.direct.core.transaction.TransactionManager
getCommitDesc, getRequestDesc, getResponseDesc, getStateDesc, getTransaction
-
-
-
-
Constructor Detail
-
TransactionResourceManager
public TransactionResourceManager(DirectDataOperator direct, java.util.Map<java.lang.String,java.lang.Object> cfg)
-
-
Method Detail
-
setTransactionTimeoutMs
public void setTransactionTimeoutMs(long timeoutMs)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceClientTransactionManager- Specified by:
closein interfaceServerTransactionManager
-
houseKeeping
public void houseKeeping()
Description copied from interface:ServerTransactionManagerCalled by the server to signal that the manager should reclaim any resources that are not needed anymore.- Specified by:
houseKeepingin interfaceServerTransactionManager
-
runObservations
public void runObservations(java.lang.String name, BiConsumer<StreamElement,Pair<java.lang.Long,java.lang.Object>> updateConsumer, CommitLogObserver requestObserver)Observe all transactional families with given observer.- Specified by:
runObservationsin interfaceServerTransactionManager- Parameters:
name- name of the observer (will be appended with name of the family)requestObserver- the observer (need not be synchronized)updateConsumer- consumer of updates to the view of transaction states
-
begin
public java.util.concurrent.CompletableFuture<Response> begin(java.lang.String transactionId, java.util.List<KeyAttribute> attributes)
Initialize new transaction. If the transaction already existed prior to this call, the state is updated accordingly.- Specified by:
beginin interfaceClientTransactionManager- Parameters:
transactionId- ID of transactionattributes- attributes affected by this transaction (both input and output)- Returns:
- asynchronous response
-
updateTransaction
public java.util.concurrent.CompletableFuture<Response> updateTransaction(java.lang.String transactionId, java.util.List<KeyAttribute> newAttributes)
Update the transaction with additional attributes related to the transaction.- Specified by:
updateTransactionin interfaceClientTransactionManager- Parameters:
transactionId- ID of transactionnewAttributes- attributes to be added to the transaction- Returns:
- asynchronous response
-
commit
public java.util.concurrent.CompletableFuture<Response> commit(java.lang.String transactionId, java.util.Collection<StreamElement> outputs)
Description copied from interface:ClientTransactionManagerCommit the transaction with given output KeyAttributes being written.- Specified by:
commitin interfaceClientTransactionManager- Parameters:
transactionId- ID of the transactionoutputs- elements to be written to the output- Returns:
- asynchronous response
-
rollback
public java.util.concurrent.CompletableFuture<Response> rollback(java.lang.String transactionId)
Description copied from interface:ClientTransactionManagerRollback transaction with given ID.- Specified by:
rollbackin interfaceClientTransactionManager- Parameters:
transactionId- ID of the transaction to rollback.- Returns:
- asynchronous response
-
release
public void release(java.lang.String transactionId)
Description copied from interface:ClientTransactionManagerRelease resources associated with given transaction.- Specified by:
releasein interfaceClientTransactionManager- Parameters:
transactionId- ID of the transaction
-
getCurrentState
public State getCurrentState(java.lang.String transactionId)
Retrieve current state of the transaction.- Specified by:
getCurrentStatein interfaceServerTransactionManager- Parameters:
transactionId- ID of the transaction- Returns:
- the
Stateassociated with the transaction on server
-
ensureTransactionOpen
public void ensureTransactionOpen(java.lang.String transactionId, State state)Description copied from interface:ServerTransactionManagerEnsure that the given transaction ID is initialized.- Specified by:
ensureTransactionOpenin interfaceServerTransactionManager- Parameters:
transactionId- ID of the transactionstate- the state that the transaction is supposed to have
-
writeResponseAndUpdateState
public void writeResponseAndUpdateState(java.lang.String transactionId, State updateState, java.lang.String responseId, Response response, CommitCallback callback)Description copied from interface:ServerTransactionManagerAtomically write response and update state of a transaction- Specified by:
writeResponseAndUpdateStatein interfaceServerTransactionManager- Parameters:
transactionId- ID of transactionupdateState- the state to update the transaction toresponseId- ID of responseresponse- the responsecallback- callback for commit after write
-
-