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
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * 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.core;
 
 
 
 
Standard implementation of a processing Pipeline that will invoke a series of Valves that have been configured to be called in order. This implementation can be used for any type of Container. IMPLEMENTATION WARNING - This implementation assumes that no calls to addValve() or removeValve are allowed while a request is currently being processed. Otherwise, the mechanism by which per-thread state is maintained will need to be modified.

Author(s):
Craig R. McClanahan
 
 
 public class StandardPipeline
     implements PipelineContainedLifecycle 
  {
 
     // ----------------------------------------------------------- Constructors
 

    
Construct a new StandardPipeline instance with no associated Container.
 
     public StandardPipeline() {
 
         this(null);
 
     }


    
Construct a new StandardPipeline instance that is associated with the specified Container.

Parameters:
container The container we should be associated with
 
     public StandardPipeline(Container container) {
 
         super();
         setContainer(container);
 
     }
 
 
     // ----------------------------------------------------- Instance Variables
 

    
The basic Valve (if any) associated with this Pipeline.
 
     protected Valve basic = null;


    
The Container with which this Pipeline is associated.
 
     protected Container container = null;


    
Descriptive information about this implementation.
    protected String info = "org.apache.catalina.core.StandardPipeline/1.0";


    
The lifecycle event support for this component.
    protected LifecycleSupport lifecycle = new LifecycleSupport(this);


    
Has this component been started yet?
    protected boolean started = false;


    
The first valve associated with this Pipeline.
    protected Valve first = null;
    // --------------------------------------------------------- Public Methods


    
Return descriptive information about this implementation class.
    public String getInfo() {
        return (this.);
    }
    // ------------------------------------------------------ Contained Methods


    
Return the Container with which this Pipeline is associated.
    public Container getContainer() {
        return (this.);
    }


    
Set the Container with which this Pipeline is associated.

Parameters:
container The new associated container
    public void setContainer(Container container) {
        this. = container;
    }
    // ------------------------------------------------------ Lifecycle Methods


    
Add a lifecycle event listener to this component.

Parameters:
listener The listener to add
    public void addLifecycleListener(LifecycleListener listener) {
        .addLifecycleListener(listener);
    }


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


    
Remove a lifecycle event listener from this component.

Parameters:
listener The listener to remove
    public void removeLifecycleListener(LifecycleListener listener) {
        .removeLifecycleListener(listener);
    }

    
Prepare for active use of the public methods of this Component.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that prevents it from being started
    public synchronized void start() throws LifecycleException {
        // Validate and update our current component state
        if () {
            return;
        }
        // Notify our interested LifecycleListeners
         = true;
        // Start the Valves in our pipeline (including the basic), if any
        Valve current = ;
        if (current == null) {
        	current = ;
        }
        while (current != null) {
            if (current instanceof Lifecycle)
                ((Lifecyclecurrent).start();
            if (.....) {
                registerValve(current);
            }
        	current = current.getNext();
        }
        // Notify our interested LifecycleListeners
        // Notify our interested LifecycleListeners
    }


    
Gracefully shut down active use of the public methods of this Component.

Throws:
org.apache.catalina.LifecycleException if this component detects a fatal error that needs to be reported
    public synchronized void stop() throws LifecycleException {
        // Validate and update our current component state
        if (!) {
            return;
        }
        // Notify our interested LifecycleListeners
        // Notify our interested LifecycleListeners
        .fireLifecycleEvent(null);
         = false;
        // Stop the Valves in our pipeline (including the basic), if any
        Valve current = ;
        if (current == null) {
        	current = ;
        }
        while (current != null) {
            if (current instanceof Lifecycle)
                ((Lifecyclecurrent).stop();
            unregisterValve(current);
        	current = current.getNext();
        }
        // Notify our interested LifecycleListeners
    }
    private void registerValve(Valve valve) {
        ifvalve instanceof ValveBase &&
                ((ValveBase)valve).getObjectName()==null ) {
            try {
                
                String domain=((ContainerBase)).getDomain();
                if instanceof StandardContext ) {
                    domain=((StandardContext)).getEngineName();
                }
                if instanceof StandardWrapper) {
                    Container ctx=((StandardWrapper)).getParent();
                    domain=((StandardContext)ctx).getEngineName();
                }
                ObjectName vname=((ValveBase)valve).createObjectName(
                        domain,
                        ((ContainerBase)).getJmxName());
                ifvname != null ) {
                    ((ValveBase)valve).setObjectName(vname);
                    Registry.getRegistry(nullnull).registerComponent
                        (valvevnamevalve.getClass().getName());
                    ((ValveBase)valve).setController
                        (((ContainerBase)).getJmxName());
                }
            } catchThrowable t ) {
                ..failedValveJmxRegistration(valvet);
            }
        }
    }
    
    private void unregisterValve(Valve valve) {
        if (.....) {
            ifvalve instanceof ValveBase ) {
                try {
                    ValveBase vb=(ValveBase)valve;
                    ifvb.getController()!=null &&
                            vb.getController() == 
                                ((ContainerBase)).getJmxName() ) {
                        ObjectName vname=vb.getObjectName();
                        Registry.getRegistry(nullnull).getMBeanServer()
                        .unregisterMBean(vname);
                        ((ValveBase)valve).setObjectName(null);
                    }
                } catchThrowable t ) {
                    ..failedValveJmxUnregistration(valvet);
                }
            }
        }
    }    
    // ------------------------------------------------------- Pipeline Methods


    

Return the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any).

    public Valve getBasic() {
        return (this.);
    }


    

Set the Valve instance that has been distinguished as the basic Valve for this Pipeline (if any). Prioer to setting the basic Valve, the Valve's setContainer() will be called, if it implements Contained, with the owning Container as an argument. The method may throw an IllegalArgumentException if this Valve chooses not to be associated with this Container, or IllegalStateException if it is already associated with a different Container.

Parameters:
valve Valve to be distinguished as the basic Valve
    public void setBasic(Valve valve) {
        // Change components if necessary
        Valve oldBasic = this.;
        if (oldBasic == valve)
            return;
        // Stop the old component if necessary
        if (oldBasic != null) {
            if ( && (oldBasic instanceof Lifecycle)) {
                try {
                    ((LifecycleoldBasic).stop();
                } catch (LifecycleException e) {
                    ..errorStoppingValve(e);
                }
            }
            if (oldBasic instanceof Contained) {
                try {
                    ((ContainedoldBasic).setContainer(null);
                } catch (Throwable t) {
                    ;
                }
            }
        }
        // Start the new component if necessary
        if (valve == null)
            return;
        if (valve instanceof Contained) {
            ((Containedvalve).setContainer(this.);
        }
        if (valve instanceof Lifecycle) {
            try {
                ((Lifecyclevalve).start();
            } catch (LifecycleException e) {
                ..errorStartingValve(e);
                return;
            }
        }
        // Update the pipeline
        Valve current = ;
        while (current != null) {
        	if (current.getNext() == oldBasic) {
        		current.setNext(valve);
        		break;
        	}
        	current = current.getNext();
        }
        
        this. = valve;
    }


    

Add a new Valve to the end of the pipeline associated with this Container. Prior to adding the Valve, the Valve's setContainer() method will be called, if it implements Contained, with the owning Container as an argument. The method may throw an IllegalArgumentException if this Valve chooses not to be associated with this Container, or IllegalStateException if it is already associated with a different Container.

Parameters:
valve Valve to be added
Throws:
java.lang.IllegalArgumentException if this Container refused to accept the specified Valve
java.lang.IllegalArgumentException if the specifie Valve refuses to be associated with this Container
java.lang.IllegalStateException if the specified Valve is already associated with a different Container
    public void addValve(Valve valve) {
    
        // Validate that we can add this Valve
        if (valve instanceof Contained)
            ((Containedvalve).setContainer(this.);
        // Start the new component if necessary
        if () {
            if (valve instanceof Lifecycle) {
                try {
                    ((Lifecyclevalve).start();
                } catch (LifecycleException e) {
                    ..errorStartingValve(e);
                }
            }
            // Register the newly added valve
            if (.....) {
                registerValve(valve);
            }
        }
        // Add this Valve to the set associated with this Pipeline
        if ( == null) {
        	 = valve;
        	valve.setNext();
        } else {
            Valve current = ;
            while (current != null) {
				if (current.getNext() == ) {
					current.setNext(valve);
					valve.setNext();
					break;
				}
				current = current.getNext();
			}
        }
    }


    
Return the set of Valves in the pipeline associated with this Container, including the basic Valve (if any). If there are no such Valves, a zero-length array is returned.
    public Valve[] getValves() {
    	ArrayList valveList = new ArrayList();
        Valve current = ;
        if (current == null) {
        	current = ;
        }
        while (current != null) {
        	valveList.add(current);
        	current = current.getNext();
        }
        return ((Valve[]) valveList.toArray(new Valve[0]));
    }
    public ObjectName[] getValveObjectNames() {
    	ArrayList valveList = new ArrayList();
        Valve current = ;
        if (current == null) {
        	current = ;
        }
        while (current != null) {
        	if (current instanceof ValveBase) {
        		valveList.add(((ValveBasecurrent).getObjectName());
        	}
        	current = current.getNext();
        }
        return ((ObjectName[]) valveList.toArray(new ObjectName[0]));
    }

    
Remove the specified Valve from the pipeline associated with this Container, if it is found; otherwise, do nothing. If the Valve is found and removed, the Valve's setContainer(null) method will be called if it implements Contained.

Parameters:
valve Valve to be removed
    public void removeValve(Valve valve) {
        Valve current;
        if( == valve) {
             = .getNext();
            current = null;
        } else {
            current = ;
        }
        while (current != null) {
            if (current.getNext() == valve) {
                current.setNext(valve.getNext());
                break;
            }
            current = current.getNext();
        }
        if ( ==  = null;
        if (valve instanceof Contained)
            ((Containedvalve).setContainer(null);
        // Stop this valve if necessary
        if () {
            if (valve instanceof Lifecycle) {
                try {
                    ((Lifecyclevalve).stop();
                } catch (LifecycleException e) {
                    ..errorStoppingValve(e);
                }
            }
            // Unregister the removed valave
            unregisterValve(valve);
        }
    
    }
    public Valve getFirst() {
        if ( != null) {
            return ;
        } else {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X