+
+ public void recordExpectedTransaction(TransactionId id) {
+ TxIdEntry entry = new TxIdEntry(Preconditions.checkNotNull(id));
+ txIdToRequestTypeMap.put(entry, getExpiryTime());
+ }
+
+ private boolean isExpectedTransaction(TransactionAware transaction, Boolean more) {
+ final TxIdEntry entry = new TxIdEntry(transaction.getTransactionId());
+ if (more != null && more.booleanValue()) {
+ return txIdToRequestTypeMap.containsKey(entry);
+ } else {
+ return txIdToRequestTypeMap.remove(entry) != null;
+ }
+ }
+
+ public boolean isExpectedTransaction(TransactionAware transaction) {
+ Boolean more = null;
+ if (transaction instanceof MultipartTransactionAware) {
+ more = ((MultipartTransactionAware)transaction).isMoreReplies();
+ }
+
+ return isExpectedTransaction(transaction, more);
+ }
+
+ private Long getExpiryTime() {
+ return System.nanoTime() + lifetimeNanos;
+ }
+
+ public void cleanStaleTransactionIds() {
+ final long now = System.nanoTime();
+
+ for (Iterator<TxIdEntry> it = txIdToRequestTypeMap.keySet().iterator();it.hasNext();){
+ TxIdEntry txIdEntry = it.next();
+
+ Long expiryTime = txIdToRequestTypeMap.get(txIdEntry);
+ if(now > expiryTime){
+ it.remove();
+ txIdTotableIdMap.remove(txIdEntry);
+ }
+ }