All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atomikos.recovery.xa.InMemoryPreviousXidRepository Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * 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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy