001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.ioc.services; 014 015import org.slf4j.Logger; 016 017import java.util.Collections; 018import java.util.List; 019 020/** 021 * Creates a pipeline from a service interface and an ordered list of filters. Each filter is defined in terms of a 022 * filter interface: the filter interface is a variant of the service interface, where each method has an additional 023 * parameter that is an instance of the service interface. Typically, this service parameter (often named "delegate") is 024 * either the first or the last parameter of each method. 025 * 026 * The implementation of a filter method is expected to pass all of its parameters to the service instance passed into 027 * it. 028 * 029 * The interesting thing is that there may be multiple filters in the pipeline. A fabricated "bridge" object (that 030 * implements the service interface) is created to let each filter invoke methods on the next filter down the pipeline. 031 * This simplifies the model for creating pipelines, as each filter is coded as if it was directly "in front of" the 032 * terminator. In fact, it may be indirectly invoking methods on the next filter in the pipeline via a bridge instance. 033 * 034 * The builder is fairly smart about matching up service interface methods to filter interface methods, but keeping it 035 * simple is also a good idea. By convention, the final parameter of each filter method is the delegate object (the bridge or terminator). 036 */ 037public interface PipelineBuilder 038{ 039 /** 040 * Creates a pipeline from the filters and a terminator. 041 * 042 * @param <S> service type 043 * @param <F> filter type 044 * @param logger logs any warnings generated when constructing the pipeline 045 * @param serviceInterface defines the interface for the pipeline 046 * @param filterInterface the filter interface, contributed into the pipeline 047 * @param filters sorted list of filters 048 * @param terminator end of the pipeline 049 * @return an object that encapsulates the filters and the terminator 050 */ 051 <S, F> S build(Logger logger, Class<S> serviceInterface, Class<F> filterInterface, List<F> filters, S terminator); 052 053 /** 054 * Creates a pipeline from just the filters. A {@link DefaultImplementationBuilder default implementation} is 055 * created as the terminator. 056 * 057 * @param <S> service type 058 * @param <F> filter type 059 * @param logger logs any warnings generated when constructing the pipeline 060 * @param serviceInterface defines the interface for the pipeline 061 * @param filterInterface the filter interface, contributed into the pipeline 062 * @param filters sorted list of filters 063 * @return an object that encapsulates the filters and the default implementation 064 */ 065 <S, F> S build(Logger logger, Class<S> serviceInterface, Class<F> filterInterface, List<F> filters); 066 067 /** 068 * The pipelines assembled so far, in the order they were assembled. 069 * 070 * <p>A pipeline is assembled when the service it implements is first realized, so the list grows as the application runs. 071 * 072 * @return the assembled pipelines, or an empty list for an implementation that does not keep track of them 073 * @since 5.9.2 074 */ 075 default List<AssembledPipeline> getAssembledPipelines() 076 { 077 return Collections.emptyList(); 078 } 079 080}