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.void
close()
java.util.concurrent.CompletableFuture<Response>
commit(java.lang.String transactionId, java.util.Collection<StreamElement> outputs)
Commit the transaction with given output KeyAttributes being written.void
ensureTransactionOpen(java.lang.String transactionId, State state)
Ensure that the given transaction ID is initialized.State
getCurrentState(java.lang.String transactionId)
Retrieve current state of the transaction.void
houseKeeping()
Called by the server to signal that the manager should reclaim any resources that are not needed anymore.void
release(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.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.void
setTransactionTimeoutMs(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.void
writeResponseAndUpdateState(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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceClientTransactionManager
- Specified by:
close
in interfaceServerTransactionManager
-
houseKeeping
public void houseKeeping()
Description copied from interface:ServerTransactionManager
Called by the server to signal that the manager should reclaim any resources that are not needed anymore.- Specified by:
houseKeeping
in 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:
runObservations
in 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:
begin
in 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:
updateTransaction
in 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:ClientTransactionManager
Commit the transaction with given output KeyAttributes being written.- Specified by:
commit
in 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:ClientTransactionManager
Rollback transaction with given ID.- Specified by:
rollback
in interfaceClientTransactionManager
- Parameters:
transactionId
- ID of the transaction to rollback.- Returns:
- asynchronous response
-
release
public void release(java.lang.String transactionId)
Description copied from interface:ClientTransactionManager
Release resources associated with given transaction.- Specified by:
release
in interfaceClientTransactionManager
- Parameters:
transactionId
- ID of the transaction
-
getCurrentState
public State getCurrentState(java.lang.String transactionId)
Retrieve current state of the transaction.- Specified by:
getCurrentState
in interfaceServerTransactionManager
- Parameters:
transactionId
- ID of the transaction- Returns:
- the
State
associated with the transaction on server
-
ensureTransactionOpen
public void ensureTransactionOpen(java.lang.String transactionId, State state)
Description copied from interface:ServerTransactionManager
Ensure that the given transaction ID is initialized.- Specified by:
ensureTransactionOpen
in 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:ServerTransactionManager
Atomically write response and update state of a transaction- Specified by:
writeResponseAndUpdateState
in interfaceServerTransactionManager
- Parameters:
transactionId
- ID of transactionupdateState
- the state to update the transaction toresponseId
- ID of responseresponse
- the responsecallback
- callback for commit after write
-
-