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

com.maxifier.mxcache.impl.caches.def.ObjectByteWeakTroveStorage 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.*;

/**
 * THIS IS GENERATED CLASS! DON'T EDIT IT MANUALLY!
 *
 * GENERATED FROM O2PWeakTroveStorage.template
 *
 * @author Andrey Yakoushin ([email protected])
 * @author Alexander Kochurov ([email protected])
 */
public class ObjectByteWeakTroveStorage extends ObjectByteTroveStorage {
    private final List removed = Collections.synchronizedList(new ArrayList());

    public ObjectByteWeakTroveStorage() {
    }

    public ObjectByteWeakTroveStorage(gnu.trove.strategy.HashingStrategy strategy) {
        super(strategy);
    }

    private void cleanup() {
        for(T t: removed) {
            remove(t);
        }
        removed.clear();
    }

    @Override
    public byte load(T o) {
        cleanup();
        return super.load(o);
    }

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

    private class Callback implements Runnable {
        private final T o;

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy