Skip to content

Commit

Permalink
Removed configuration change listeners
Browse files Browse the repository at this point in the history
They were used to change database configuration on the fly without restart.
This functionality was removed long ago. Listeners are now used only from tests.
  • Loading branch information
lutovich committed Feb 29, 2016
1 parent 7ffd0f0 commit d3fdae8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 333 deletions.
Expand Up @@ -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
Expand All @@ -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<String, String> descriptions = new HashMap<>();

Expand Down Expand Up @@ -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<ConfigurationChange> change )
{
for( ConfigurationChange configurationChange : change )
{
config.put( configurationChange.getName(), configurationChange.getNewValue() );
}
}
}
}
Expand Up @@ -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;
Expand All @@ -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.
* <p/>
* Users can assume that old settings have been migrated to their new counterparts, and that defaults have been applied.
* <p/>
* 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.
* <p>
* 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<ConfigurationChangeListener> listeners = new CopyOnWriteArrayList<>();
private final Map<String, String> params = new ConcurrentHashMap<>();
private final Iterable<Class<?>> settingsClasses;
private final ConfigurationMigrator migrator;
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -216,36 +200,10 @@ public String toString()

private synchronized void replaceSettings( Map<String, String> newSettings )
{
HashMap<String, String> oldSettings = new HashMap<>( params );

newSettings = migrator.apply( newSettings, log );
validator.validate( newSettings );
Map<String,String> 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<String, String> newSettings, HashMap<String, String> oldSettings )
{
List<ConfigurationChange> configurationChanges = new ArrayList<>();
for ( Map.Entry<String, String> 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 );
}
}
}
}

This file was deleted.

This file was deleted.

Expand Up @@ -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;
Expand Down Expand Up @@ -77,28 +72,6 @@ public static class MySettingsWithDefaults

}

private class ChangeCaptureListener implements ConfigurationChangeListener
{
private Set<ConfigurationChange> lastChangeSet;

@Override
public void notifyConfigurationChanges( Iterable<ConfigurationChange> change )
{
lastChangeSet = new HashSet<>();
for ( ConfigurationChange ch : change )
{
lastChangeSet.add( ch );
}
}
}

private <T> Set<T> setOf( T... objs )
{
Set<T> set = new HashSet<>();
Collections.addAll( set, objs );
return set;
}

@Test
public void shouldApplyDefaults()
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit d3fdae8

Please sign in to comment.