tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util LifecycleSupport.java
Date Tue, 01 Aug 2000 20:55:49 GMT
craigmcc    00/08/01 13:55:48

  Modified:    proposals/catalina/src/share/org/apache/tomcat/util
                        LifecycleSupport.java
  Log:
  Tune behavior of lifecycle event support by eliminating the need for any
  collection classes.
  
  Revision  Changes    Path
  1.2       +37 -13    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/LifecycleSupport.java
  
  Index: LifecycleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/LifecycleSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LifecycleSupport.java	2000/04/10 20:01:40	1.1
  +++ LifecycleSupport.java	2000/08/01 20:55:46	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/LifecycleSupport.java,v
1.1 2000/04/10 20:01:40 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/04/10 20:01:40 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/util/LifecycleSupport.java,v
1.2 2000/08/01 20:55:46 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/01 20:55:46 $
    *
    * ====================================================================
    *
  @@ -65,7 +65,6 @@
   package org.apache.tomcat.util;
   
   
  -import java.util.Vector;
   import org.apache.tomcat.Lifecycle;
   import org.apache.tomcat.LifecycleEvent;
   import org.apache.tomcat.LifecycleListener;
  @@ -76,7 +75,7 @@
    * registered LifecycleListeners.
    *
    * @author Craig R. McClanahan
  - * @version $Id: LifecycleSupport.java,v 1.1 2000/04/10 20:01:40 craigmcc Exp $
  + * @version $Id: LifecycleSupport.java,v 1.2 2000/08/01 20:55:46 craigmcc Exp $
    */
   
   public final class LifecycleSupport {
  @@ -112,7 +111,7 @@
       /**
        * The set of registered LifecycleListeners for event notifications.
        */
  -    private Vector listeners = new Vector();
  +    private LifecycleListener listeners[] = new LifecycleListener[0];
   
   
       // --------------------------------------------------------- Public Methods
  @@ -125,7 +124,14 @@
        */
       public void addLifecycleListener(LifecycleListener listener) {
   
  -	listeners.addElement(listener);
  +      synchronized (listeners) {
  +	  LifecycleListener results[] =
  +	    new LifecycleListener[listeners.length + 1];
  +	  for (int i = 0; i < listeners.length; i++)
  +	      results[i] = listeners[i];
  +	  results[listeners.length] = listener;
  +	  listeners = results;
  +      }
   
       }
   
  @@ -141,12 +147,12 @@
       public void fireLifecycleEvent(String type, Object data) {
   
   	LifecycleEvent event = new LifecycleEvent(lifecycle, type, data);
  -	Vector list = null;
  -	synchronized (this) {
  -	    list = (Vector) listeners.clone();
  +	LifecycleListener interested[] = null;
  +	synchronized (listeners) {
  +	    interested = (LifecycleListener[]) listeners.clone();
   	}
  -	for (int i = 0; i < list.size(); i++)
  -	    ((LifecycleListener) list.elementAt(i)).lifecycleEvent(event);
  +	for (int i = 0; i < interested.length; i++)
  +	    interested[i].lifecycleEvent(event);
   
       }
   
  @@ -158,7 +164,25 @@
        */
       public void removeLifecycleListener(LifecycleListener listener) {
   
  -	listeners.removeElement(listener);
  +        synchronized (listeners) {
  +	    int n = -1;
  +	    for (int i = 0; i < listeners.length; i++) {
  +	        if (listeners[i] == listener) {
  +		    n = i;
  +		    break;
  +		}
  +	    }
  +	    if (n < 0)
  +	        return;
  +	    LifecycleListener results[] =
  +	      new LifecycleListener[listeners.length - 1];
  +	    int j = 0;
  +	    for (int i = 0; i < listeners.length; i++) {
  +	        if (i != n)
  +		    results[j++] = listeners[i];
  +	    }
  +	    listeners = results;
  +	}
   
       }
   
  
  
  

Mime
View raw message