diff --git a/community/jmx/src/main/java/org/neo4j/jmx/impl/ConfigurationBean.java b/community/jmx/src/main/java/org/neo4j/jmx/impl/ConfigurationBean.java index a4479c11c8b3f..e6374070be19c 100644 --- a/community/jmx/src/main/java/org/neo4j/jmx/impl/ConfigurationBean.java +++ b/community/jmx/src/main/java/org/neo4j/jmx/impl/ConfigurationBean.java @@ -39,10 +39,8 @@ import org.neo4j.graphdb.config.Setting; import org.neo4j.jmx.Description; -import org.neo4j.kernel.internal.KernelData; import org.neo4j.kernel.configuration.Config; -import org.neo4j.kernel.configuration.ConfigurationChange; -import org.neo4j.kernel.configuration.ConfigurationChangeListener; +import org.neo4j.kernel.internal.KernelData; @Description( "The configuration parameters used to configure Neo4j" ) public final class ConfigurationBean extends Neo4jMBean @@ -57,7 +55,6 @@ public final class ConfigurationBean extends Neo4jMBean super( CONFIGURATION_MBEAN_NAME, kernel, support ); this.config = new HashMap<>( kernel.getConfig().getParams() ); Config configuration = kernel.getConfig(); - configuration.addConfigurationChangeListener( new UpdatedConfigurationListener() ); Map descriptions = new HashMap<>(); @@ -172,17 +169,4 @@ public Object invoke( String s, Object[] objects, String[] strings ) throw new MBeanException( e ); } } - - private class UpdatedConfigurationListener - implements ConfigurationChangeListener - { - @Override - public void notifyConfigurationChanges( Iterable change ) - { - for( ConfigurationChange configurationChange : change ) - { - config.put( configurationChange.getName(), configurationChange.getNewValue() ); - } - } - } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java index 8a2893855b9ca..17292f2a2a7f4 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java @@ -25,9 +25,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; import org.neo4j.graphdb.config.Configuration; @@ -39,21 +37,17 @@ import org.neo4j.logging.Logger; import static java.util.Arrays.asList; - import static org.neo4j.helpers.collection.Iterables.concat; /** * This class holds the overall configuration of a Neo4j database instance. Use the accessors to convert the internal * key-value settings to other types. - *

- * Users can assume that old settings have been migrated to their new counterparts, and that defaults have been applied. - *

- * UI's can change configuration by calling augment(). Any listener, such as services that use this configuration, can - * be notified of changes by implementing the {@link ConfigurationChangeListener} interface. + *

+ * Users can assume that old settings have been migrated to their new counterparts, and that defaults have been + * applied. */ public class Config implements DiagnosticsProvider, Configuration { - private final List listeners = new CopyOnWriteArrayList<>(); private final Map params = new ConcurrentHashMap<>(); private final Iterable> settingsClasses; private final ConfigurationMigrator migrator; @@ -165,16 +159,6 @@ public void setLogger( Log log ) this.log = log; } - public void addConfigurationChangeListener( ConfigurationChangeListener listener ) - { - listeners.add( listener ); - } - - public void removeConfigurationChangeListener( ConfigurationChangeListener listener ) - { - listeners.remove( listener ); - } - @Override public String getDiagnosticsIdentifier() { @@ -216,36 +200,10 @@ public String toString() private synchronized void replaceSettings( Map newSettings ) { - HashMap oldSettings = new HashMap<>( params ); - - newSettings = migrator.apply( newSettings, log ); - validator.validate( newSettings ); + Map migratedSettings = migrator.apply( newSettings, log ); + validator.validate( migratedSettings ); params.clear(); - params.putAll( newSettings ); + params.putAll( migratedSettings ); settingsFunction = new ConfigValues( params ); - - notifyListeners( newSettings, oldSettings ); - } - - private void notifyListeners( Map newSettings, HashMap oldSettings ) - { - List configurationChanges = new ArrayList<>(); - for ( Map.Entry setting : newSettings.entrySet() ) - { - String oldValue = oldSettings.get( setting.getKey() ); - String newValue = setting.getValue(); - if ( !Objects.equals( oldValue, newValue ) ) - { - configurationChanges.add( new ConfigurationChange( setting.getKey(), oldValue, newValue ) ); - } - } - - if ( !configurationChanges.isEmpty() ) - { - for ( ConfigurationChangeListener listener : listeners ) - { - listener.notifyConfigurationChanges( configurationChanges ); - } - } } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/ConfigurationChangeListener.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/ConfigurationChangeListener.java deleted file mode 100644 index 933ad26c0fb10..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/ConfigurationChangeListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.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.kernel.configuration; - -/** -* TODO -*/ -public interface ConfigurationChangeListener -{ - void notifyConfigurationChanges( Iterable change ); -} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/RestartOnChange.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/RestartOnChange.java deleted file mode 100644 index 6d7d65f90c7ea..0000000000000 --- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/RestartOnChange.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.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.kernel.configuration; - -import java.util.function.Predicate; - -import org.neo4j.kernel.lifecycle.Lifecycle; - -/** - * When a specified change happens, restart the given LifeSupport instance. - *

- * Typically, provide a specification for the settings that a service uses, and then set it to restart - * an internal LifeSupport instance when any of those settings change. - */ -public class RestartOnChange - implements ConfigurationChangeListener -{ - private final Predicate restartSpecification; - private final Lifecycle life; - - public RestartOnChange( final String configurationNamePrefix, Lifecycle life ) - { - this( item -> { - return item.startsWith( configurationNamePrefix ); - }, life ); - } - - public RestartOnChange( Predicate restartSpecification, Lifecycle life ) - { - this.restartSpecification = restartSpecification; - this.life = life; - } - - @Override - public void notifyConfigurationChanges( Iterable change ) - { - boolean restart = false; - for ( ConfigurationChange configurationChange : change ) - { - restart |= restartSpecification.test( configurationChange.getName() ); - } - - if ( restart ) - { - try - { - life.stop(); - life.start(); - } - catch ( Throwable throwable ) - { - throwable.printStackTrace(); - } - } - } -} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/configuration/ConfigTest.java b/community/kernel/src/test/java/org/neo4j/kernel/configuration/ConfigTest.java index b906cbbd59461..b770a262e2719 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/configuration/ConfigTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/configuration/ConfigTest.java @@ -19,26 +19,21 @@ */ package org.neo4j.kernel.configuration; -import java.util.Collections; +import org.junit.Test; + import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; - -import org.junit.Test; import org.neo4j.graphdb.config.Configuration; import org.neo4j.graphdb.config.InvalidSettingException; import org.neo4j.graphdb.config.Setting; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; - import static org.neo4j.helpers.collection.MapUtil.stringMap; import static org.neo4j.kernel.configuration.Settings.BOOLEAN; import static org.neo4j.kernel.configuration.Settings.INTEGER; @@ -77,28 +72,6 @@ public static class MySettingsWithDefaults } - private class ChangeCaptureListener implements ConfigurationChangeListener - { - private Set lastChangeSet; - - @Override - public void notifyConfigurationChanges( Iterable change ) - { - lastChangeSet = new HashSet<>(); - for ( ConfigurationChange ch : change ) - { - lastChangeSet.add( ch ); - } - } - } - - private Set setOf( T... objs ) - { - Set set = new HashSet<>(); - Collections.addAll( set, objs ); - return set; - } - @Test public void shouldApplyDefaults() { @@ -139,37 +112,6 @@ public void shouldBeAbleToAugmentConfig() throws Exception assertThat( config.get( setting( "unrelated", STRING, "" ) ), equalTo( "hello" ) ); } - @Test - public void shouldNotifyChangeListenersWhenNewSettingsAreApplied() - { - // Given - Config config = new Config( stringMap( "setting", "old" ), MyMigratingSettings.class ); - ChangeCaptureListener listener = new ChangeCaptureListener(); - config.addConfigurationChangeListener( listener ); - - // When - config.augment( stringMap( "setting", "new" ) ); - - // Then - assertThat( listener.lastChangeSet, - is( setOf( new ConfigurationChange( "setting", "old", "new" ) ) ) ); - } - - @Test - public void shouldNotNotifyChangeListenerWhenNothingChanged() - { - // Given - Config config = new Config( stringMap( "setting", "old" ), MyMigratingSettings.class ); - ChangeCaptureListener listener = new ChangeCaptureListener(); - config.addConfigurationChangeListener( listener ); - - // When - config.augment( stringMap( "setting", "old" ) ); // nothing really changed here - - // Then - assertThat( listener.lastChangeSet, nullValue() ); - } - @Test public void shouldProvideViewOfGroups() throws Throwable { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/configuration/TestConfigConcurrency.java b/community/kernel/src/test/java/org/neo4j/kernel/configuration/TestConfigConcurrency.java deleted file mode 100644 index 3434e99c879e0..0000000000000 --- a/community/kernel/src/test/java/org/neo4j/kernel/configuration/TestConfigConcurrency.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.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.kernel.configuration; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import org.junit.Test; - -import static org.neo4j.helpers.collection.MapUtil.stringMap; - -public class TestConfigConcurrency -{ - - /** - * Hammers config with read/write load on both properties and the listener - * interface it provides. - */ - class ConfigHammer implements Runnable, ConfigurationChangeListener - { - private final Config config; - private final Random rand; - protected Throwable failure; - - public ConfigHammer(Config config) - { - this.config = config; - this.rand = new Random( ); - } - - @Override - public void run() - { - try - { - int times = 500; - while ( times --> 0 ) - { - config.addConfigurationChangeListener( this ); - - // Edit config a bit - config.augment( stringMap( "asd" + rand.nextInt( 10 ), "dsa" + rand.nextInt( 100000 ) ) ); - - // Unregister listener - config.removeConfigurationChangeListener( this ); - } - } catch(Throwable e) - { - this.failure = e; - } - } - - @Override - public void notifyConfigurationChanges( Iterable change ) - { - } - } - - @Test(timeout = 10000l) - public void shouldHandleConcurrentLoad() throws Throwable - { - // Given - Config config = Config.empty(); - - List threads = new ArrayList<>( ); - List hammers = new ArrayList<>( ); - - // When - int numThreads = 10; - while( numThreads --> 0) - { - ConfigHammer configHammer = new ConfigHammer( config ); - Thread thread = new Thread( configHammer ); - thread.start(); - - threads.add( thread ); - hammers.add( configHammer ); - } - - // Then - for ( Thread thread : threads ) - thread.join(); - - // And no hammer has broken - for ( ConfigHammer hammer : hammers ) - if(hammer.failure != null) - throw hammer.failure; - } -}