/** 
 * 
 * Copyright 2004 Protique Ltd
 * 
 * Licensed 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.codehaus.activemq.message.util;
import java.util.List;
import javax.jms.JMSException;
import org.codehaus.activemq.message.Packet;

/**
 * BoundedPacketQueue
 * 
 * @version $Revision: 1.1 $
 */
public interface BoundedPacketQueue {
    /**
     * @return the name of this queue
     */
    public abstract String getName();

    /**
     * @return the number of items held by this queue
     */
    public abstract int size();

    /**
     * close and remove this queue
     */
    public abstract void close();

    /**
     * Enqueue a Packet without checking usage limits
     * 
     * @param packet
     * @throws JMSException
     */
    public void enqueueNoBlock(Packet packet) throws JMSException;

    /**
     * Enqueue a Packet to this queue
     * 
     * @param packet
     * @throws InterruptedException
     * @throws JMSException
     */
    public void enqueue(Packet packet) throws InterruptedException, JMSException;

    /**
     * @return the first dequeued Packet or blocks until one is available
     * @throws InterruptedException
     * @throws JMSException
     */
    public Packet dequeue() throws InterruptedException, JMSException;

    /**
     * Dequeues a Packet from the head of the queue
     * 
     * @param timeInMillis time to wait for a Packet to be available
     * @return the first Packet or null if none available within <I>timeInMillis </I>
     * @throws InterruptedException
     * @throws JMSException
     */
    public Packet dequeue(long timeInMillis) throws InterruptedException, JMSException;

    /**
     * dequeues a Packet from the head of the queue
     * 
     * @return the Packet at the head of the queue or null, if none is available
     * @throws InterruptedException
     * @throws JMSException
     */
    public Packet dequeueNoWait() throws InterruptedException, JMSException;

    /**
     * @return true if the queue is enabled for dequeing (default = true)
     */
    public boolean isStarted();

    /**
     * disable dequeueing
     */
    public void stop();

    /**
     * enable dequeueing
     */
    public void start();

    /**
     * @return true if the queue is empty
     */
    public boolean isEmpty();
    
    /**
     * clear the contents from the Queue
     *
     */
    public void clear();
    
    /**
     * Retrieve a shallow copy of the contents as a list
     * @return a list containing the bounded queue contents
     */
    public List getContents();
    
    
    
}