Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.apache.catalina.util;
Support class to assist in firing LifecycleEvent notifications to registered LifecycleListeners.

Craig R. McClanahan
$Id: 1003 2009-04-09 19:25:39Z $
 public final class LifecycleSupport {
     // ----------------------------------------------------------- Constructors

Construct a new LifecycleSupport object associated with the specified Lifecycle component.

lifecycle The Lifecycle component that will be the source of events that we fire
     public LifecycleSupport(Lifecycle lifecycle) {
         this. = lifecycle;
     // ----------------------------------------------------- Instance Variables

The source component for lifecycle events that we will fire.
     private Lifecycle lifecycle = null;

The set of registered LifecycleListeners for event notifications.
     private LifecycleListener listeners[] = new LifecycleListener[0];
     // --------------------------------------------------------- Public Methods

Add a lifecycle event listener to this component.

listener The listener to add
     public synchronized void addLifecycleListener(LifecycleListener listener) {
         LifecycleListener results[] =
             new LifecycleListener[. + 1];
         for (int i = 0; i < .i++)
             results[i] = [i];
         results[.] = listener;
          = results;

Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
         return ;

Notify all lifecycle event listeners that a particular event has occurred for this Container. The default implementation performs this notification synchronously using the calling thread.

type Event type
data Event data
    public void fireLifecycleEvent(String typeObject data) {
        LifecycleEvent event = new LifecycleEvent(typedata);
        LifecycleListener interested[] = ;
        for (int i = 0; i < interested.lengthi++)

Remove a lifecycle event listener from this component.

listener The listener to remove
    public synchronized void removeLifecycleListener(LifecycleListener listener) {
        int n = -1;
        for (int i = 0; i < .i++) {
            if ([i] == listener) {
                n = i;
        if (n < 0)
        LifecycleListener results[] =
            new LifecycleListener[. - 1];
        int j = 0;
        for (int i = 0; i < .i++) {
            if (i != n)
                results[j++] = [i];
         = results;
New to GrepCode? Check out our FAQ X