[logback-dev] svn commit: r947 - in logback/trunk/logback-classic/src: main/java/ch/qos/logback/classic main/java/ch/qos/logback/classic/spi test/java/ch/qos/logback/classic/spi

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Nov 17 16:20:44 CET 2006


Author: seb
Date: Fri Nov 17 16:20:44 2006
New Revision: 947

Removed:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/EventType.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/LogbackEvent.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java

Log:
Removed LogbackEvent, simplified process of notifying to listeners
LoggerContext now implements LifeCycle


Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java	Fri Nov 17 16:20:44 2006
@@ -19,8 +19,6 @@
 import org.slf4j.Marker;
 
 import ch.qos.logback.classic.spi.ContextListener;
-import ch.qos.logback.classic.spi.EventType;
-import ch.qos.logback.classic.spi.LogbackEvent;
 import ch.qos.logback.classic.spi.LoggerContextRemoteView;
 import ch.qos.logback.classic.spi.TurboFilterAttachable;
 import ch.qos.logback.classic.spi.TurboFilterAttachableImpl;
@@ -28,13 +26,14 @@
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.CoreGlobal;
 import ch.qos.logback.core.spi.FilterReply;
+import ch.qos.logback.core.spi.LifeCycle;
 import ch.qos.logback.core.status.ErrorStatus;
 
 /**
  * @author ceki
  */
 public class LoggerContext extends ContextBase implements ILoggerFactory,
-    TurboFilterAttachable {
+    TurboFilterAttachable, LifeCycle {
 
   public static final String ROOT_NAME = "root";
 
@@ -53,6 +52,8 @@
   LoggerContextRemoteView loggerContextRemoteView;
 
   TurboFilterAttachableImpl cfai = null;
+  
+  boolean started = false;
 
   public LoggerContext() {
     super();
@@ -171,7 +172,7 @@
 
   public void shutdownAndReset() {
     root.recursiveReset();
-    notifyListeners(EventType.CONTEXT_RESTART);
+    fireOnReset();
   }
 
   public void addTurboFilter(TurboFilter newFilter) {
@@ -219,12 +220,32 @@
     }
   }
   
-  private void notifyListeners(EventType eventType) {
-    LogbackEvent event = new LogbackEvent(this, eventType);
+  private void fireOnReset() {
+    if (listenerList != null) {
+      for (ContextListener listener: listenerList) {
+        listener.onReset(this);
+      }
+    }
+  }
+  
+  private void fireOnStart() {
     if (listenerList != null) {
       for (ContextListener listener: listenerList) {
-        listener.update(event);
+        listener.onStart(this);
       }
     }
   }
+
+  public boolean isStarted() {
+    return started;
+  }
+
+  public void start() {
+    started = true;
+    fireOnStart();
+  }
+
+  public void stop() {
+    started = false;
+  }
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/spi/ContextListener.java	Fri Nov 17 16:20:44 2006
@@ -1,9 +1,10 @@
 package ch.qos.logback.classic.spi;
 
-import java.util.EventListener;
+import ch.qos.logback.classic.LoggerContext;
 
-public interface ContextListener extends EventListener {
+public interface ContextListener {
   
-  public void update(LogbackEvent logbackEvent);
+  public void onReset(LoggerContext context);
+  public void onStart(LoggerContext contest);
 
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/BasicContextListener.java	Fri Nov 17 16:20:44 2006
@@ -1,12 +1,19 @@
 package ch.qos.logback.classic.spi;
 
+import ch.qos.logback.classic.LoggerContext;
+
 public class BasicContextListener implements ContextListener {
 
   boolean updated = false;
-  LogbackEvent lastEvent;
+  LoggerContext context;
   
-  public void update(LogbackEvent logbackEvent) {
+  public void onReset(LoggerContext context) {
+    updated = true;
+    this.context = context;
+    
+  }
+  public void onStart(LoggerContext context) {
     updated = true;
-    lastEvent = logbackEvent;
+    this.context = context;
   }
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java	Fri Nov 17 16:20:44 2006
@@ -15,11 +15,15 @@
     super.setUp();
   }
   
-  public void testNotify() {
+  public void testNotifyOnReset() {
     context.shutdownAndReset();
     assertTrue(listener.updated);
-    assertEquals(EventType.CONTEXT_RESTART, listener.lastEvent.getType());
-    assertEquals(context, listener.lastEvent.getSource());
+    assertEquals(listener.context, context);
+  }
+  
+  public void testNotifyOnStart() {
+    context.start();
+    assertTrue(listener.updated);
+    assertEquals(listener.context, context);
   }
-
 }



More information about the logback-dev mailing list