1 /* 2 * Copyright 1999-2004 The Apache Software Foundation 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 * implied. 13 * 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.excalibur.event; 18 19 20 /** 21 * Enqueue predicates allow users to specify a method that 22 * will 'screen' elements being enqueued onto a sink, either 23 * accepting or rejecting them. This mechanism can be used 24 * to implement many interesting load-conditioning policies, 25 * for example, simple thresholding, rate control, credit-based 26 * flow control, and so forth. Note that the enqueue predicate 27 * runs in the context of the <b>caller of enqueue()</b>, which 28 * means it must be simple and fast. 29 * 30 * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a> 31 * @version $Revision: 1.4 $ 32 */ 33 public interface EnqueuePredicate 34 { 35 /** 36 * Tests the given element for acceptance onto the m_sink. 37 * @since Feb 10, 2003 38 * 39 * @param element The element to enqueue 40 * @param modifyingSink The sink that is used for this predicate 41 * @return 42 * <code>true</code> if the sink accepts the element; 43 * <code>false</code> otherwise. 44 */ 45 boolean accept(Object element, Sink modifyingSink); 46 47 /** 48 * Tests the given element for acceptance onto the m_sink. 49 * @since Feb 10, 2003 50 * 51 * @param elements The array of elements to enqueue 52 * @param modifyingSink The sink that is used for this predicate 53 * @return 54 * <code>true</code> if the sink accepts all the elements; 55 * <code>false</code> otherwise. 56 */ 57 boolean accept(Object elements[], Sink modifyingSink); 58 } 59