package org.xbib.logging.configuration;

import java.util.concurrent.atomic.AtomicReference;

class ConstantConfigurationResource<T> implements ConfigurationResource<T> {

    private final AtomicReference<T> instance;

    ConstantConfigurationResource(final T instance) {
        this.instance = new AtomicReference<>(instance);
    }

    @Override
    public T get() {
        return instance.get();
    }

    @Override
    public void close() throws Exception {
        final T instance = this.instance.getAndSet(null);
        if (instance instanceof AutoCloseable) {
            ((AutoCloseable) instance).close();
        }
    }
}
