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

org.neo4j.configuration.LocalConfig Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [https://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.neo4j.configuration;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.logging.InternalLog;

/**
 * Config that delegates everything but also keeps track of any registered listeners through it
 * to be able to remove all the listeners belonging to this local config.
 */
public class LocalConfig extends Config {

    private final Config config;
    private Map, Collection>> registeredListeners =
            new ConcurrentHashMap<>();

    public LocalConfig(Config config) {
        this.config = config;
    }

    @Override
    public  void addListener(Setting setting, SettingChangeListener listener) {
        registeredListeners
                .computeIfAbsent((SettingImpl) setting, v -> new ConcurrentLinkedQueue<>())
                .add((SettingChangeListener) listener);
        config.addListener(setting, listener);
    }

    @Override
    public  void removeListener(Setting setting, SettingChangeListener listener) {
        Collection> listeners = registeredListeners.get(setting);
        if (listeners != null) {
            listeners.remove(listener);
        }
        config.removeListener(setting, listener);
    }

    public void removeAllLocalListeners() {
        for (var settingListeners : registeredListeners.entrySet()) {
            Setting setting = settingListeners.getKey();
            Collection> listeners = settingListeners.getValue();
            for (SettingChangeListener listener : listeners) {
                config.removeListener(setting, listener);
            }
        }
        registeredListeners = new ConcurrentHashMap<>();
    }

    @Override
    public  Map getGroups(Class group) {
        return config.getGroups(group);
    }

    @Override
    public  Map, Map> getGroupsFromInheritance(
            Class parentClass) {
        return config.getGroupsFromInheritance(parentClass);
    }

    @Override
    public  T get(Setting setting) {
        return config.get(setting);
    }

    @Override
    public  T getDefault(Setting setting) {
        return config.getDefault(setting);
    }

    @Override
    public  T getStartupValue(Setting setting) {
        return config.getStartupValue(setting);
    }

    @Override
    public  ValueSource getValueSource(Setting setting) {
        return config.getValueSource(setting);
    }

    @Override
    public  SettingObserver getObserver(Setting setting) {
        return config.getObserver(setting);
    }

    @Override
    public  void setDynamic(Setting setting, T value, String scope) {
        config.setDynamic(setting, value, scope);
    }

    @Override
    public  void setDynamicByUser(Setting setting, T value, String scope) {
        config.setDynamicByUser(setting, value, scope);
    }

    @Override
    public  void set(Setting setting, T value) {
        config.set(setting, value);
    }

    @Override
    public  void setIfNotSet(Setting setting, T value) {
        config.setIfNotSet(setting, value);
    }

    @Override
    public boolean isExplicitlySet(Setting setting) {
        return config.isExplicitlySet(setting);
    }

    @Override
    public String toString() {
        return config.toString();
    }

    @Override
    public String toString(boolean includeNullValues) {
        return config.toString(includeNullValues);
    }

    @Override
    public void setLogger(InternalLog log) {
        config.setLogger(log);
    }

    @Override
    public Setting getSetting(String name) {
        return config.getSetting(name);
    }

    @Override
    public Map> getDeclaredSettings() {
        return config.getDeclaredSettings();
    }

    @Override
    public Object configStringLookup(String setting) {
        return config.configStringLookup(setting);
    }
}