1 /* 2 * Copyright (C) The Apache Software Foundation. All rights reserved. 3 * 4 * This software is published under the terms of the Apache Software License 5 * version 1.1, a copy of which has been included with this distribution in 6 * the LICENSE.txt file. 7 */ 8 package org.apache.avalon.excalibur.event; 9 10 /** 11 * A Sink implements the side of an event queue where QueueElements are 12 * dequeued operations only. 13 * 14 * @author <a HREF="mailto:bloritsch@apache.org">Berin Loritsch</a> 15 */ 16 public interface Sink { 17 /** 18 * Sets the timeout on a blocking Sink. Values above <code>1</code> will 19 * force all <code>dequeue</code> operations to block for up to that number 20 * of milliseconds waiting for new elements. Values below <code>1</code> 21 * will turn off blocking for Sink. This is intentional because a Sink should 22 * never block indefinitely. 23 */ 24 void setTimeout( long millis ); 25 26 /** 27 * Dequeues the next element, or returns <code>null</code> if there is 28 * nothing left on the queue. 29 * 30 * @return the next <code>QueueElement</code> on the queue 31 */ 32 QueueElement dequeue(); 33 34 /** 35 * Dequeues all available elements, or returns <code>null</code> if there is 36 * nothing left on the queue. 37 * 38 * @return all pending <code>QueueElement</code>s on the queue 39 */ 40 QueueElement[] dequeueAll(); 41 42 /** 43 * Dequeues at most <code>num</code> available elements, or returns 44 * <code>null</code> if there is nothing left on the queue. 45 * 46 * @return At most <code>num</code> <code>QueueElement</code>s on the queue 47 */ 48 QueueElement[] dequeue(int num); 49 50 /** 51 * Returns the number of elements waiting in this queue. 52 */ 53 int size(); 54 55 } 56