    001package org.apache.turbine.pipeline;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023
    024import java.io.IOException;
    025
    026import org.apache.turbine.util.TurbineException;
    027
    028/**
    029 * The idea of a pipeline is being taken from Catalina
    030 * in its entirety :-)
    031 *
    032 * I would like to take the idea further and implement
    033 * Valves instead of hardcoding particular methods
    034 * in a pipeline.
    035 *
    036 * It would be more flexible to specify Valves for
    037 * a pipeline in an XML file (we can also rip off the
    038 * digester rules from T4) and have invoke() as part
    039 * of the interface.
    040 *
    041 * So a set of Valves would be added to the pipeline
    042 * and the pipeline would 'invoke' each valve. In the
    043 * case Turbine each Valve would produce some output
    044 * to be sent out the pipe. I think with another days
    045 * work this can be fully working. The first pipeline
    046 * to be fully implemented will the ClassicPipeline
    047 * will emulate the Turbine 2.1 way of doing things.
    048 *
    049 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    050 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    051 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    052 */
    053public interface Pipeline
    054{
    055    /**
    056     * Initializes this instance.  Called once by the Turbine servlet.
    057     * @throws Exception if the initialization fails
    058     */
    059    void initialize()
    060        throws Exception;
    061
    062    /**
    063     * <p>Add a new Valve to the end of the pipeline.</p>
    064     *
    065     * @param valve Valve to be added.
    066     *
    067     * @exception IllegalStateException If the pipeline has not been
    068     * initialized.
    069     */
    070    void addValve(Valve valve);
    071
    072    /**
    073     * Return the set of all Valves in the pipeline.  If there are no
    074     * such Valves, a zero-length array is returned.
    075     *
    076     * @return An array of valves.
    077     */
    078    Valve[] getValves();
    079
    080    /**
    081     * <p>Cause the specified request and response to be processed by
    082     * the sequence of Valves associated with this pipeline, until one
    083     * of these Valves decides to end the processing.</p>
    084     *
    085     * <p>The implementation must ensure that multiple simultaneous
    086     * requests (on different threads) can be processed through the
    087     * same Pipeline without interfering with each other's control
    088     * flow.</p>
    089     *
    090     * @param pipelineData The run-time information, including the servlet
    091     * request and response we are processing.
    092     * @throws TurbineException if the invocation fails
    093     * @throws IOException an input/output error occurred.
    094     */
    095    void invoke(PipelineData pipelineData)
    096        throws TurbineException, IOException;
    097
    098    /**
    099     * Remove the specified Valve from the pipeline, if it is found;
    100     * otherwise, do nothing.
    101     *
    102     * @param valve Valve to be removed.
    103     */
    104    void removeValve(Valve valve);
    105}