logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/log4j/plugins PluginRegistry.java
Date Tue, 25 May 2004 04:45:22 GMT
psmith      2004/05/24 21:45:22

  Modified:    src/java/org/apache/log4j/net SocketHubReceiver.java
                        SocketNode.java SocketReceiver.java
               src/java/org/apache/log4j/plugins PluginRegistry.java
  Log:
  [Please review this change, particularly the synchronization semantics]
  
  This set of changes removes the dependancy on the EventListenerList
  class which seems to be JDK1.3.
  
  This should allow the non-chainsaw areas of log4j to be compiled under JDK 1.2,
  although I do not have this installed, and cannot verify.
  
  All the test cases (bar the Scheduler one, but I don't believe
  that is related to this change) pass after this change.
  
  Revision  Changes    Path
  1.11      +17 -15    logging-log4j/src/java/org/apache/log4j/net/SocketHubReceiver.java
  
  Index: SocketHubReceiver.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/SocketHubReceiver.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SocketHubReceiver.java	25 May 2004 01:01:01 -0000	1.10
  +++ SocketHubReceiver.java	25 May 2004 04:45:21 -0000	1.11
  @@ -9,13 +9,15 @@
   
   import java.io.IOException;
   import java.net.Socket;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.Iterator;
  +import java.util.List;
   
  -import javax.swing.event.EventListenerList;
  -
  -import org.apache.log4j.spi.LoggerRepository;
  -import org.apache.log4j.plugins.Receiver;
  -import org.apache.log4j.plugins.Plugin;
   import org.apache.log4j.helpers.LogLog;
  +import org.apache.log4j.plugins.Plugin;
  +import org.apache.log4j.plugins.Receiver;
  +import org.apache.log4j.spi.LoggerRepository;
   
   /**
     SocketHubReceiver receives a remote logging event on a configured
  @@ -44,7 +46,7 @@
     
     protected Socket socket;
     
  -  private EventListenerList listenerList = new EventListenerList();
  +  private List listenerList = Collections.synchronizedList(new ArrayList());
       
     public SocketHubReceiver() { }
     
  @@ -65,7 +67,7 @@
      * @param l
      */
     public void addSocketNodeEventListener(SocketNodeEventListener l){
  -  	listenerList.add(SocketNodeEventListener.class, l);
  +  	listenerList.add(l);
     }
     
     /**
  @@ -74,7 +76,7 @@
      * @param l
      */
     public void removeSocketNodeEventListener(SocketNodeEventListener l){
  -  	listenerList.remove(SocketNodeEventListener.class, l);
  +  	listenerList.remove(l);
     }
     
     /**
  @@ -221,13 +223,13 @@
       socket = _socket;
       SocketNode node = new SocketNode(socket, this);
       node.addSocketNodeEventListener(this);
  -	SocketNodeEventListener[] listeners =
  -	  (SocketNodeEventListener[]) listenerList.getListeners(
  -		SocketNodeEventListener.class);
  -
  -	for (int i = 0; i < listeners.length; i++) {
  -	  node.addSocketNodeEventListener(listeners[i]);
  -	}
  +
  +    synchronized(listenerList){
  +    	for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
  +    		SocketNodeEventListener listener = (SocketNodeEventListener) iter.next();
  +    		node.addSocketNodeEventListener(listener);
  +    	}
  +    }
       new Thread(node).start();
     }
     
  
  
  
  1.31      +29 -34    logging-log4j/src/java/org/apache/log4j/net/SocketNode.java
  
  Index: SocketNode.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/SocketNode.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- SocketNode.java	25 May 2004 01:01:01 -0000	1.30
  +++ SocketNode.java	25 May 2004 04:45:21 -0000	1.31
  @@ -16,21 +16,20 @@
   
   package org.apache.log4j.net;
   
  -import org.apache.log4j.Logger;
  -import org.apache.log4j.plugins.Pauseable;
  -import org.apache.log4j.plugins.Receiver;
  -import org.apache.log4j.spi.LoggerRepository;
  -import org.apache.log4j.spi.LoggingEvent;
  -
   import java.io.BufferedInputStream;
   import java.io.IOException;
   import java.io.ObjectInputStream;
  -
   import java.net.Socket;
  +import java.util.ArrayList;
  +import java.util.Collections;
  +import java.util.Iterator;
  +import java.util.List;
   
  -import java.util.EventListener;
  -
  -import javax.swing.event.EventListenerList;
  +import org.apache.log4j.Logger;
  +import org.apache.log4j.plugins.Pauseable;
  +import org.apache.log4j.plugins.Receiver;
  +import org.apache.log4j.spi.LoggerRepository;
  +import org.apache.log4j.spi.LoggingEvent;
   
   
   // Contributors:  Moses Hohman <mmhohman@rainbow.uchicago.edu>
  @@ -55,7 +54,7 @@
     private LoggerRepository hierarchy;
     private Receiver receiver;
     private SocketNodeEventListener listener;
  -  private EventListenerList listenerList = new EventListenerList();
  +  private List listenerList = Collections.synchronizedList(new ArrayList());
   
     /**
       Constructor for socket and logger repository. */
  @@ -89,7 +88,7 @@
      * @param listener the listener to add to the list
      */
     public void addSocketNodeEventListener(SocketNodeEventListener listener) {
  -    listenerList.add(SocketNodeEventListener.class, listener);
  +    listenerList.add(listener);
     }
   
     /**
  @@ -100,7 +99,7 @@
      * @param listener the SocketNodeEventListener to remove
      */
     public void removeSocketNodeEventListener(SocketNodeEventListener listener) {
  -    listenerList.remove(SocketNodeEventListener.class, listener);
  +    listenerList.remove(listener);
     }
   
     public void run() {
  @@ -187,7 +186,7 @@
       }
   
       // send event to listener, if configured
  -    if (listener != null || listenerList.getListenerCount()>0) {
  +    if (listener != null || listenerList.size()>0) {
         fireSocketClosedEvent(listenerException);
       }
     }
  @@ -197,16 +196,14 @@
      * @param listenerException
      */
     private void fireSocketClosedEvent(Exception listenerException) {
  -    EventListener[] listeners =
  -      listenerList.getListeners(SocketNodeEventListener.class);
  -
  -    for (int i = 0; i < listeners.length; i++) {
  -      SocketNodeEventListener snel = (SocketNodeEventListener) listeners[i];
  -
  -      if (snel != null) {
  -        snel.socketClosedEvent(listenerException);
  -      }
  -    }
  +  	synchronized(listenerList){
  +  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
  +  			SocketNodeEventListener snel = (SocketNodeEventListener) iter.next();
  +  			if (snel != null) {
  +  				snel.socketClosedEvent(listenerException);
  +  			}
  +  		}
  +  	}
     }
   
     /**
  @@ -214,16 +211,14 @@
      * @param remoteInfo
      */
     private void fireSocketOpened(String remoteInfo) {
  -    EventListener[] listeners =
  -      listenerList.getListeners(SocketNodeEventListener.class);
  -
  -    for (int i = 0; i < listeners.length; i++) {
  -      SocketNodeEventListener snel = (SocketNodeEventListener) listeners[i];
  -
  -      if (snel != null) {
  -        snel.socketOpened(remoteInfo);
  -      }
  -    }
  +  	synchronized(listenerList){
  +  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
  +  			SocketNodeEventListener snel = (SocketNodeEventListener) iter.next();
  +  			if (snel != null) {
  +  				snel.socketOpened(remoteInfo);
  +  			}
  +  		}
  +  	}
     }
   
     public void setPaused(boolean paused) {
  
  
  
  1.9       +20 -20    logging-log4j/src/java/org/apache/log4j/net/SocketReceiver.java
  
  Index: SocketReceiver.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/net/SocketReceiver.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SocketReceiver.java	27 Feb 2004 16:47:32 -0000	1.8
  +++ SocketReceiver.java	25 May 2004 04:45:22 -0000	1.9
  @@ -16,24 +16,24 @@
   
   package org.apache.log4j.net;
   
  -import org.apache.log4j.helpers.LogLog;
  -import org.apache.log4j.plugins.Pauseable;
  -import org.apache.log4j.plugins.Receiver;
  -import org.apache.log4j.plugins.Plugin;
  -import org.apache.log4j.spi.LoggerRepository;
  -import org.apache.log4j.spi.LoggingEvent;
  -
   import java.io.IOException;
  -
   import java.net.ServerSocket;
   import java.net.Socket;
  -
  +import java.util.ArrayList;
  +import java.util.Collections;
   import java.util.Enumeration;
   import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   import java.util.Vector;
   
  -import javax.swing.event.EventListenerList;
  +import org.apache.log4j.helpers.LogLog;
  +import org.apache.log4j.plugins.Pauseable;
  +import org.apache.log4j.plugins.Plugin;
  +import org.apache.log4j.plugins.Receiver;
  +import org.apache.log4j.spi.LoggerRepository;
  +import org.apache.log4j.spi.LoggingEvent;
   
   
   /**
  @@ -60,7 +60,7 @@
     private ServerSocket serverSocket;
     private Vector socketList = new Vector();
     private SocketNodeEventListener listener = null;
  -  private EventListenerList listenerList = new EventListenerList();
  +  private List listenerList = Collections.synchronizedList(new ArrayList());
   
     public SocketReceiver() {
     }
  @@ -224,14 +224,14 @@
             socketList.add(socket);
   
             SocketNode node = new SocketNode(socket, this);
  -          SocketNodeEventListener[] listeners =
  -            (SocketNodeEventListener[]) listenerList.getListeners(
  -              SocketNodeEventListener.class);
  -
  -          for (int i = 0; i < listeners.length; i++) {
  -            node.addSocketNodeEventListener(listeners[i]);
  +          synchronized(listenerList){
  +          	for (Iterator iter = listenerList.iterator(); iter
  +          	.hasNext();) {
  +          		SocketNodeEventListener listener = (SocketNodeEventListener) iter.next();
  +          		node.addSocketNodeEventListener(listener);
  +          		
  +          	}
             }
  -
             socketMap.put(socket, node);
             new Thread(node).start();
             socket = null;
  @@ -299,7 +299,7 @@
      * @param listener the listener to add to the list
      */
     public void addSocketNodeEventListener(SocketNodeEventListener listener) {
  -    listenerList.add(SocketNodeEventListener.class, listener);
  +    listenerList.add(listener);
     }
   
     /**
  @@ -310,7 +310,7 @@
      * @param listener the SocketNodeEventListener to remove
      */
     public void removeSocketNodeEventListener(SocketNodeEventListener listener) {
  -    listenerList.remove(SocketNodeEventListener.class, listener);
  +    listenerList.remove(listener);
     }
   
     /**
  
  
  
  1.13      +24 -27    logging-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java
  
  Index: PluginRegistry.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/plugins/PluginRegistry.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PluginRegistry.java	12 May 2004 15:39:03 -0000	1.12
  +++ PluginRegistry.java	25 May 2004 04:45:22 -0000	1.13
  @@ -16,13 +16,12 @@
   package org.apache.log4j.plugins;
   
   import java.util.ArrayList;
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   
  -import javax.swing.event.EventListenerList;
  -
   import org.apache.log4j.spi.LoggerRepository;
   import org.apache.log4j.spi.LoggerRepositoryEventListener;
   
  @@ -48,7 +47,7 @@
      * the listener used to listen for repository events.
      */
     private final RepositoryListener listener = new RepositoryListener();
  -  private final EventListenerList listenerList = new EventListenerList();
  +  private final List listenerList = Collections.synchronizedList(new ArrayList());
   
     public PluginRegistry(LoggerRepository loggerRepository) {
       pluginMap = new HashMap();
  @@ -108,17 +107,16 @@
      * @param plugin The plugin that has been started.
      */
     private void firePluginStarted(Plugin plugin) {
  -    PluginListener[] listeners = (PluginListener[])listenerList.getListeners(PluginListener.class);
  -
  -    PluginEvent e = null;
  -
  -    for (int i = 0; i < listeners.length; i++) {
  -      if (e == null) {
  -        e = new PluginEvent(plugin);
  -      }
  -
  -      listeners[i].pluginStarted(e);
  -    }
  +  	PluginEvent e = null;
  +  	synchronized(listenerList){
  +  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
  +  			PluginListener listener = (PluginListener) iter.next();
  +  			if (e == null) {
  +  				e = new PluginEvent(plugin);
  +  			}
  +  			listener.pluginStarted(e);
  +  		}
  +  	}
     }
   
   
  @@ -128,17 +126,16 @@
      * @param plugin The plugin that has been stopped.
      */
     private void firePluginStopped(Plugin plugin) {
  -    PluginListener[] listeners = (PluginListener[])listenerList.getListeners(PluginListener.class);
  -
  -    PluginEvent e = null;
  -
  -    for (int i = 0; i < listeners.length; i++) {
  -      if (e == null) {
  -        e = new PluginEvent(plugin);
  -      }
  -
  -      listeners[i].pluginStopped(e);
  -    }
  +  	PluginEvent e = null;
  +  	synchronized(listenerList){
  +  		for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
  +  			PluginListener listener = (PluginListener) iter.next();
  +  			if (e == null) {
  +  				e = new PluginEvent(plugin);
  +  			}
  +  			listener.pluginStopped(e);
  +  		}
  +  	}
     }
   
   
  @@ -239,7 +236,7 @@
      * @param l PluginListener to add to this registry
      */
     public final void addPluginListener(PluginListener l) {
  -    listenerList.add(PluginListener.class, l);
  +    listenerList.add(l);
     }
   
   
  @@ -250,7 +247,7 @@
      * @param l PluginListener to remove
      */
     public final void removePluginListener(PluginListener l) {
  -    listenerList.remove(PluginListener.class, l);
  +    listenerList.remove(l);
     }
   
     /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message