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

com.maxifier.mxcache.impl.resource.nodes.SingletonDependencyNode Maven / Gradle / Ivy

/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.impl.resource.nodes;

import com.maxifier.mxcache.caches.CleaningNode;
import com.maxifier.mxcache.impl.resource.AbstractDependencyNode;
import com.maxifier.mxcache.util.TIdentityHashSet;

import javax.annotation.Nonnull;

/**
 * @author Alexander Kochurov ([email protected])
 */
public class SingletonDependencyNode extends AbstractDependencyNode {
    // we don't need to store reference here cause this node exists only if object itself is not gc'ed
    protected CleaningNode instance;

    public SingletonDependencyNode() {
        // do nothing - instance is set by addNode.
    }

    public SingletonDependencyNode(CleaningNode instance) {
        this.instance = instance;
    }

    @Override
    public synchronized void addNode(@Nonnull CleaningNode cache) {
        if (instance != null) {
            throw new UnsupportedOperationException("Singleton dependency node should has only one cache");
        }
        instance = cache;
    }

    @Override
    public synchronized void appendNodes(TIdentityHashSet elements) {
        elements.add(instance);
    }

    @Override
    public String toString() {
        return "DependencyNode<" + instance + ">";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy