FileDocCategorySizeDatePackage
InstanceSupport.javaAPI DocGlassfish v2 API17229Fri May 04 22:32:30 BST 2007org.apache.catalina.util

InstanceSupport

public final class InstanceSupport extends Object
Support class to assist in firing InstanceEvent notifications to registered InstanceListeners.
author
Craig R. McClanahan
version
$Id: InstanceSupport.java,v 1.4 2007/05/05 05:32:30 tcfujii Exp $

Fields Summary
private ReadWriteLock
listenersLock
private Lock
listenersReadLock
private Lock
listenersWriteLock
private org.apache.catalina.InstanceListener[]
listeners
The set of registered InstanceListeners for event notifications.
private org.apache.catalina.Wrapper
wrapper
The source component for instance events that we will fire.
Constructors Summary
public InstanceSupport(org.apache.catalina.Wrapper wrapper)
Construct a new InstanceSupport object associated with the specified Instance component.

param
lifecycle The Instance component that will be the source of events that we fire


        super();
        this.wrapper = wrapper;

    
Methods Summary
public voidaddInstanceListener(org.apache.catalina.InstanceListener listener)
Add a lifecycle event listener to this component.

param
listener The listener to add

        /* SJSAS 6374619
        synchronized (listeners) {
          InstanceListener results[] =
            new InstanceListener[listeners.length + 1];
          for (int i = 0; i < listeners.length; i++)
              results[i] = listeners[i];
          results[listeners.length] = listener;
          listeners = results;
        }
        */
        // START SJSAS 6374619
        listenersWriteLock.lock();
        try {
            InstanceListener results[] =
                new InstanceListener[listeners.length + 1];
            for (int i = 0; i < listeners.length; i++)
              results[i] = listeners[i];
            results[listeners.length] = listener;
            listeners = results;
        } finally {
            listenersWriteLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
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.

param
type Event type
param
servlet The relevant Servlet for this event
param
request The servlet request we are processing
param
response The servlet response we are processing


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, servlet, type,
                                                request, response);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.Throwable exception)
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.

param
type Event type
param
servlet The relevant Servlet for this event
param
request The servlet request we are processing
param
response The servlet response we are processing
param
exception Exception that occurred


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, servlet, type,
                                                request, response, exception);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Filter filter)
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.

param
type Event type
param
filter The relevant Filter for this event


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, filter, type);
        InstanceListener interested[] = null;
        /* SJSAS XXX
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS XXX
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Filter filter, java.lang.Throwable exception)
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.

param
type Event type
param
filter The relevant Filter for this event
param
exception Exception that occurred


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, filter, type,
                                                exception);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619

    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Filter filter, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
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.

param
type Event type
param
filter The relevant Filter for this event
param
request The servlet request we are processing
param
response The servlet response we are processing


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, filter, type,
                                                request, response);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Filter filter, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.Throwable exception)
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.

param
type Event type
param
filter The relevant Filter for this event
param
request The servlet request we are processing
param
response The servlet response we are processing
param
exception Exception that occurred


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, filter, type,
                                                request, response, exception);
        /* SJSAS 6374619        
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Servlet servlet)
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.

param
type Event type
param
servlet The relevant Servlet for this event


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, servlet, type);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public voidfireInstanceEvent(java.lang.String type, javax.servlet.Servlet servlet, java.lang.Throwable exception)
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.

param
type Event type
param
servlet The relevant Servlet for this event
param
exception Exception that occurred


        if (listeners.length == 0)
            return;

        InstanceEvent event = new InstanceEvent(wrapper, servlet, type,
                                                exception);
        /* SJSAS 6374619
        InstanceListener interested[] = null;
        synchronized (listeners) {
            interested = (InstanceListener[]) listeners.clone();
        }
        for (int i = 0; i < interested.length; i++)
            interested[i].instanceEvent(event);
        */
        // START SJSAS 6374619
        listenersReadLock.lock();
        try {
            for (int i = 0; i < listeners.length; i++)
                listeners[i].instanceEvent(event);
        } finally {
            listenersReadLock.unlock();
        }
        // END SJSAS 6374619
    
public org.apache.catalina.WrappergetWrapper()
Return the Wrapper with which we are associated.



    // ------------------------------------------------------------- Properties


                 
       

        return (this.wrapper);

    
public voidremoveInstanceListener(org.apache.catalina.InstanceListener listener)
Remove a lifecycle event listener from this component.

param
listener The listener to remove


        /* SJSAS 6374619
        synchronized (listeners) {
            int n = -1;
            for (int i = 0; i < listeners.length; i++) {
                if (listeners[i] == listener) {
                    n = i;
                    break;
                }
            }
            if (n < 0)
                return;
            InstanceListener results[] =
              new InstanceListener[listeners.length - 1];
            int j = 0;
            for (int i = 0; i < listeners.length; i++) {
                if (i != n)
                    results[j++] = listeners[i];
            }
            listeners = results;
        }
        */
        // START SJSAS 6374619
        listenersWriteLock.lock();
        try {
            int n = -1;
            for (int i = 0; i < listeners.length; i++) {
                if (listeners[i] == listener) {
                    n = i;
                    break;
                }
            }
            if (n < 0)
                return;
            InstanceListener results[] =
              new InstanceListener[listeners.length - 1];
            int j = 0;
            for (int i = 0; i < listeners.length; i++) {
                if (i != n)
                    results[j++] = listeners[i];
            }
            listeners = results;
        } finally {
            listenersWriteLock.unlock();
        }
        // END SJSAS 6374619