Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add executors to Listeners

Handle shutdown properly in LogbackService
Renamed API for clustering to ClusterEvents
Implemented ClusterEvents
Added ClusterDiscovery API
Updated settings for HA
Change HA to use URI more than URL
  • Loading branch information...
commit 938380aba4ee13970743d7c14662de9fe8d38822 1 parent f06460f
Rickard Öberg authored June 29, 2012
39  kernel/src/main/java/org/neo4j/helpers/Listeners.java
@@ -23,6 +23,7 @@
23 23
 import java.util.Collection;
24 24
 import java.util.LinkedList;
25 25
 import java.util.List;
  26
+import java.util.concurrent.Executor;
26 27
 
27 28
 /**
28 29
  * Helper class for dealing with listeners
@@ -57,14 +58,42 @@
57 58
     {
58 59
         for( T listener : listeners )
59 60
         {
60  
-            try
  61
+            synchronized( listener )
61 62
             {
62  
-                notification.notify( listener );
  63
+                try
  64
+                {
  65
+                    notification.notify( listener );
  66
+                }
  67
+                catch( Throwable e )
  68
+                {
  69
+                    e.printStackTrace();
  70
+                }
63 71
             }
64  
-            catch( Exception e )
  72
+        }
  73
+    }
  74
+
  75
+    public static <T> void notifyListeners(Iterable<T> listeners, Executor executor, final Notification<T> notification)
  76
+    {
  77
+        for( final T listener : listeners )
  78
+        {
  79
+            executor.execute( new Runnable()
65 80
             {
66  
-                // Ignore
67  
-            }
  81
+                @Override
  82
+                public void run()
  83
+                {
  84
+                    synchronized( listener )
  85
+                    {
  86
+                        try
  87
+                        {
  88
+                            notification.notify( listener );
  89
+                        }
  90
+                        catch( Throwable e )
  91
+                        {
  92
+                            e.printStackTrace();
  93
+                        }
  94
+                    }
  95
+                }
  96
+            });
68 97
         }
69 98
     }
70 99
 }
76  kernel/src/main/java/org/neo4j/kernel/logging/LogbackService.java
@@ -59,47 +59,50 @@ public void init()
59 59
         throws Throwable
60 60
     {
61 61
         final String storeDir = config.get( InternalAbstractGraphDatabase.Configuration.store_dir );
62  
-
63  
-        File file = new File( storeDir ).getAbsoluteFile();
64  
-        if (!file.exists())
65  
-            file.mkdirs();
66  
-
67  
-        loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
68  
-
69  
-        // Neo4j specific log config
70  
-        loggingLife.add( new LifecycleAdapter()
  62
+        
  63
+        if (storeDir != null)
71 64
         {
72  
-            @Override
73  
-            public void start()
74  
-                throws Throwable
  65
+            File file = new File( storeDir ).getAbsoluteFile();
  66
+            if (!file.exists())
  67
+                file.mkdirs();
  68
+    
  69
+            loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
  70
+    
  71
+            // Neo4j specific log config
  72
+            loggingLife.add( new LifecycleAdapter()
75 73
             {
76  
-                JoranConfigurator configurator = new JoranConfigurator();
77  
-                configurator.setContext( loggerContext );
78  
-                loggerContext.putProperty( "neo_store", storeDir );
79  
-                loggerContext.putProperty( "remote_logging_enabled", config.get( GraphDatabaseSettings.remote_logging_enabled ).toString() );
80  
-                loggerContext.putProperty( "remote_logging_host", config.get( GraphDatabaseSettings.remote_logging_host ) );
81  
-                loggerContext.putProperty( "remote_logging_port", config.get( GraphDatabaseSettings.remote_logging_port ).toString() );
82  
-                try
  74
+                @Override
  75
+                public void start()
  76
+                    throws Throwable
83 77
                 {
84  
-                    configurator.doConfigure( getClass().getResource( "/neo4j-logback.xml" ) );
  78
+                    JoranConfigurator configurator = new JoranConfigurator();
  79
+                    configurator.setContext( loggerContext );
  80
+                    loggerContext.putProperty( "neo_store", storeDir );
  81
+                    loggerContext.putProperty( "remote_logging_enabled", config.get( GraphDatabaseSettings.remote_logging_enabled ).toString() );
  82
+                    loggerContext.putProperty( "remote_logging_host", config.get( GraphDatabaseSettings.remote_logging_host ) );
  83
+                    loggerContext.putProperty( "remote_logging_port", config.get( GraphDatabaseSettings.remote_logging_port ).toString() );
  84
+                    try
  85
+                    {
  86
+                        configurator.doConfigure( getClass().getResource( "/neo4j-logback.xml" ) );
  87
+                    }
  88
+                    catch( JoranException e )
  89
+                    {
  90
+                        throw new IllegalStateException("Failed to configure logging", e );
  91
+                    }
85 92
                 }
86  
-                catch( JoranException e )
  93
+    
  94
+                @Override
  95
+                public void stop()
  96
+                    throws Throwable
87 97
                 {
88  
-                    throw new IllegalStateException("Failed to configure logging", e );
  98
+                    loggerContext.getLogger( Loggers.NEO4J ).detachAndStopAllAppenders();
89 99
                 }
90  
-            }
91  
-
92  
-            @Override
93  
-            public void stop()
94  
-                throws Throwable
95  
-            {
96  
-                loggerContext.getLogger( Loggers.NEO4J ).detachAndStopAllAppenders();
97  
-            }
98  
-        });
99  
-        loggingLife.start();
100  
-
101  
-        restartOnChange = new RestartOnChange( "remote_logging_", loggingLife );
102  
-        config.addConfigurationChangeListener( restartOnChange );
  100
+            });
  101
+            loggingLife.start();
  102
+    
  103
+            restartOnChange = new RestartOnChange( "remote_logging_", loggingLife );
  104
+            config.addConfigurationChangeListener( restartOnChange );
  105
+        }
103 106
     }
104 107
 
105 108
     @Override
@@ -107,7 +110,8 @@ public void shutdown()
107 110
         throws Throwable
108 111
     {
109 112
         loggingLife.shutdown();
110  
-        config.removeConfigurationChangeListener( restartOnChange );
  113
+        if (restartOnChange != null)
  114
+            config.removeConfigurationChangeListener( restartOnChange );
111 115
     }
112 116
 
113 117
     @Override

0 notes on commit 938380a

Please sign in to comment.
Something went wrong with that request. Please try again.