com.atomikos.recovery.xa.InMemoryPreviousXidRepository Maven / Gradle / Ivy
/**
* Copyright (C) 2000-2020 Atomikos
*
* LICENSE CONDITIONS
*
* See http://www.atomikos.com/Main/WhichLicenseApplies for details.
*/
package com.atomikos.recovery.xa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.atomikos.datasource.xa.XID;
public class InMemoryPreviousXidRepository implements PreviousXidRepository {
private Map> cache = new HashMap<>();
@Override
public synchronized List findXidsExpiredAt(long startOfRecoveryScan) {
List xids = new ArrayList<>();
for (Long expiration : cache.keySet()) {
if(expiration it = cache.keySet().iterator();
while (it.hasNext()) {
Long expiration = it.next();
if(expiration<=startOfRecoveryScan) {
it.remove();
}
}
}
@Override
public synchronized boolean isEmpty() {
return cache.isEmpty();
}
@Override
public synchronized void remember(XID xidToStoreForNextScan, long expiration) {
List xids = cache.get(expiration);
if (xids == null) {
xids = new ArrayList<>();
}
xids.add(xidToStoreForNextScan);
cache.put(expiration, xids);
}
}