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

com.maxifier.mxcache.impl.caches.def.ObjectObjectWeakTroveStorage Maven / Gradle / Ivy

Go to download

Constains all classes necessary for launching a MxCache-instrumentated application

There is a newer version: 2.6.9
Show newest version
/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.impl.caches.def;

import com.maxifier.mxcache.transform.SmartReference;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ObjectObjectWeakTroveStorage
 *
 * @author Andrey Yakoushin ([email protected])
 * @author Alexander Kochurov ([email protected])
 */
public class ObjectObjectWeakTroveStorage extends ObjectObjectTroveStorage {
    private final List removed = Collections.synchronizedList(new ArrayList());

    public ObjectObjectWeakTroveStorage() {
    }

    private void cleanup() {
        for(K k : removed) {
            remove(k);
        }
        removed.clear();
    }

    @Override
    public Object load(K o) {
        cleanup();
        return super.load(o);
    }

    @Override
    public void save(final K o, V t) {
        cleanup();
        o.setCallback(new Callback(o));
        super.save(o, t);
    }

    private class Callback implements Runnable {
        private final K o;

        public Callback(K o) {
            this.o = o;
        }

        @Override
        public void run() {
            removed.add(o);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy