You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/01/29 22:01:11 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core ContainerBase.java

craigmcc    00/01/29 13:01:11

  Modified:    proposals/catalina/src/share/org/apache/tomcat
                        Container.java
               proposals/catalina/src/share/org/apache/tomcat/core
                        ContainerBase.java
  Added:       proposals/catalina/src/share/org/apache/tomcat
                        ContainerEvent.java ContainerEventListener.java
  Log:
  Add support for significant Container-related events, following the usual
  JavaBeans event listener design pattern.  Add a removeChild() method to
  the Container interface, and a corresponding implementation in the
  ContainerBase class.
  
  Revision  Changes    Path
  1.4       +29 -4     jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Container.java
  
  Index: Container.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Container.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Container.java	2000/01/29 07:46:32	1.3
  +++ Container.java	2000/01/29 21:01:10	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Container.java,v 1.3 2000/01/29 07:46:32 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/01/29 07:46:32 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Container.java,v 1.4 2000/01/29 21:01:10 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/01/29 21:01:10 $
    *
    * ====================================================================
    *
  @@ -119,7 +119,7 @@
    * </ul>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2000/01/29 07:46:32 $
  + * @version $Revision: 1.4 $ $Date: 2000/01/29 21:01:10 $
    */
   
   public interface Container {
  @@ -263,6 +263,14 @@
   
   
       /**
  +     * Add a container event listener to this component.
  +     *
  +     * @param listener The listener to add
  +     */
  +    public void addContainerEventListener(ContainerEventListener listener);
  +
  +
  +    /**
        * Add a property change listener to this component.
        *
        * @param listener The listener to add
  @@ -320,6 +328,23 @@
        */
       public void invoke(Request request, Response response)
   	throws IOException, ServletException;
  +
  +
  +    /**
  +     * Remove an existing child Container from association with this parent
  +     * Container.
  +     *
  +     * @param child Existing child Container to be removed
  +     */
  +    public void removeChild(Container child);
  +
  +
  +    /**
  +     * Remove a container event listener from this component.
  +     *
  +     * @param listener The listener to remove
  +     */
  +    public void removeContainerEventListener(ContainerEventListener listener);
   
   
       /**
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/ContainerEvent.java
  
  Index: ContainerEvent.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/ContainerEvent.java,v 1.1 2000/01/29 21:01:10 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/29 21:01:10 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat;
  
  
  import java.util.EventObject;
  
  
  /**
   * General event for notifying listeners of significant changes on a Container.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/29 21:01:10 $
   */
  
  public final class ContainerEvent
      extends EventObject {
  
  
      /**
       * The Container on which this event occurred.
       */
      private Container container = null;
  
  
      /**
       * The event data associated with this event.
       */
      private Object data = null;
  
  
      /**
       * The event type this instance represents.
       */
      private String type = null;
  
  
      /**
       * Construct a new ContainerEvent with the specified parameters.
       *
       * @param container Container on which this event occurred
       * @param type Event type
       * @param data Event data
       */
      public ContainerEvent(Container container, String type, Object data) {
  
  	super(container);
  	this.container = container;
  	this.type = type;
  	this.data = data;
  
      }
  
  
      /**
       * Return the event data of this event.
       */
      public Object getData() {
  
  	return (this.data);
  
      }
  
  
      /**
       * Return the Container on which this event occurred.
       */
      public Container getContainer() {
  
  	return (this.container);
  
      }
  
  
      /**
       * Return the event type of this event.
       */
      public String getType() {
  
  	return (this.type);
  
      }
  
  
      /**
       * Return a string representation of this event.
       */
      public String toString() {
  
  	return ("ContainerEvent['" + getContainer().getName() + "','" +
  		getType() + "']");
  
      }
  
  
  }
  
  
  
  1.1                  jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/ContainerEventListener.java
  
  Index: ContainerEventListener.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/ContainerEventListener.java,v 1.1 2000/01/29 21:01:10 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2000/01/29 21:01:10 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.tomcat;
  
  
  import java.util.EventObject;
  
  
  /**
   * Interface defining a listener for significant Container generated events.
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2000/01/29 21:01:10 $
   */
  
  public interface ContainerEventListener {
  
  
      /**
       * Acknowledge the occurrence of the specified event.
       *
       * @param event ContainerEvent that has occurred
       */
      public void eventOccurred(ContainerEvent event);
  
  
  }
  
  
  
  1.6       +129 -4    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java
  
  Index: ContainerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ContainerBase.java	2000/01/29 07:46:33	1.5
  +++ ContainerBase.java	2000/01/29 21:01:10	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.5 2000/01/29 07:46:33 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/01/29 07:46:33 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.6 2000/01/29 21:01:10 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/01/29 21:01:10 $
    *
    * ====================================================================
    *
  @@ -70,8 +70,11 @@
   import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Hashtable;
  +import java.util.Vector;
   import javax.servlet.ServletException;
   import org.apache.tomcat.Container;
  +import org.apache.tomcat.ContainerEvent;
  +import org.apache.tomcat.ContainerEventListener;
   import org.apache.tomcat.Lifecycle;
   import org.apache.tomcat.LifecycleException;
   import org.apache.tomcat.Loader;
  @@ -97,9 +100,53 @@
    * the default behavior desired, and assign it with <code>setBasic()</code>
    * in a constructor.  In that way, any and all configured Valves added to the
    * pipeline will preceed the basic Valve.
  + * <p>
  + * This implementation fires property change events, per the JavaBeans design
  + * pattern, for changes in singleton properties.  In addition, it fires the
  + * following <code>ContainerEvent</code> events to listeners who register
  + * themselves with <code>addContainerEventListener()</code>:
  + * <table border=1>
  + *   <tr>
  + *     <th>Type</th>
  + *     <th>Data</th>
  + *     <th>Description</th>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>addChild</code></td>
  + *     <td align=center><code>Container</code></td>
  + *     <td>Child container added to this Container.</td>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>addValve</code></td>
  + *     <td align=center><code>Valve</code></td>
  + *     <td>Valve added to this Container.</td>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>removeChild</code></td>
  + *     <td align=center><code>Container</code></td>
  + *     <td>Child container removed from this Container.</td>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>removeValve</code></td>
  + *     <td align=center><code>Valve</code></td>
  + *     <td>Valve removed from this Container.</td>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>start</code></td>
  + *     <td align=center><code>null</code></td>
  + *     <td>Container was started.</td>
  + *   </tr>
  + *   <tr>
  + *     <td align=center><code>stop</code></td>
  + *     <td align=center><code>null</code></td>
  + *     <td>Container was stopped.</td>
  + *   </tr>
  + * </table>
  + * Subclasses that fire additional events should document them in the
  + * class comments of the implementation class.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2000/01/29 07:46:33 $
  + * @version $Revision: 1.6 $ $Date: 2000/01/29 21:01:10 $
    */
   
   public abstract class ContainerBase
  @@ -128,6 +175,12 @@
   
   
       /**
  +     * The container event listeners for this Container.
  +     */
  +    protected Vector listeners = new Vector();
  +
  +
  +    /**
        * The Loader implementation with which this Container is associated.
        */
       protected Loader loader = null;
  @@ -480,6 +533,18 @@
   
   
       /**
  +     * Add a container event listener to this component.
  +     *
  +     * @param listener The listener to add
  +     */
  +    public void addContainerEventListener(ContainerEventListener listener) {
  +
  +	listeners.addElement(listener);
  +
  +    }
  +
  +
  +    /**
        * Add a property change listener to this component.
        *
        * @param listener The listener to add
  @@ -517,6 +582,7 @@
   						   "' is not unique");
   	    child.setParent((Container) this);	// May throw IAE
   	    children.put(child.getName(), child);
  +	    fireContainerEvent("addChild", child);
   	}
   
       }
  @@ -583,6 +649,37 @@
   
   
       /**
  +     * Remove an existing child Container from association with this parent
  +     * Container.
  +     *
  +     * @param child Existing child Container to be removed
  +     */
  +    public void removeChild(Container child) {
  +
  +	synchronized(children) {
  +	    if (children.get(child.getName()) == null)
  +		return;
  +	    children.remove(child.getName());
  +	    child.setParent(null);
  +	    fireContainerEvent("removeChild", child);
  +	}
  +
  +    }
  +
  +
  +    /**
  +     * Remove a container event listener from this component.
  +     *
  +     * @param listener The listener to remove
  +     */
  +    public void removeContainerEventListener(ContainerEventListener listener) {
  +
  +	listeners.removeElement(listener);
  +
  +    }
  +
  +
  +    /**
        * Remove a property change listener from this component.
        *
        * @param listener The listener to remove
  @@ -612,6 +709,7 @@
   	    throw new LifecycleException
   		(sm.getString("containerBase.alreadyStarted"));
   	started = true;
  +	fireContainerEvent("start", null);
   
   	// Start our subordinate components, if any
   	if ((loader != null) && (loader instanceof Lifecycle))
  @@ -650,6 +748,7 @@
   	    throw new LifecycleException
   		(sm.getString("containerBase.notStarted"));
   	started = false;
  +	fireContainerEvent("stop", null);
   
   	// Stop the Valves in our pipeline (including the basic), if any
   	Valve current = basic;
  @@ -726,6 +825,8 @@
   	    }
   	}
   
  +	fireContainerEvent("addValve", valve);
  +
       }
   
   
  @@ -772,8 +873,32 @@
   		if (next != null)
   		    next.setPrevious(previous);
   	    }
  +	    fireContainerEvent("removeValve", valve);
   	    break;
   	}
  +
  +    }
  +
  +
  +    // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Notify all container event listeners that a particular event has
  +     * occurred for this Container.
  +     *
  +     * @param type Event type
  +     * @param data Event data
  +     */
  +    protected void fireContainerEvent(String type, Object data) {
  +
  +	ContainerEvent event = new ContainerEvent(this, type, data);
  +	Vector list = null;
  +	synchronized (this) {
  +	    list = (Vector) listeners.clone();
  +	}
  +	for (int i = 0; i < list.size(); i++)
  +	    ((ContainerEventListener) list.elementAt(i)).eventOccurred(event);
   
       }