001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.broker.region.cursors;
018
019import java.util.Collection;
020import java.util.Iterator;
021import java.util.List;
022
023import org.apache.activemq.broker.region.MessageReference;
024import org.apache.activemq.command.MessageId;
025
026public interface PendingList extends Iterable<MessageReference> {
027
028    /**
029     * Returns true if there are no Messages in the PendingList currently.
030     * @return true if the PendingList is currently empty.
031     */
032    public boolean isEmpty();
033
034    /**
035     * Discards all Messages currently held in the PendingList.
036     */
037    public void clear();
038
039    /**
040     * Adds the given message to the head of the list.
041     *
042     * @param message
043     *      The MessageReference that is to be added to this list.
044     *
045     * @return the PendingNode that contains the newly added message.
046     */
047    public PendingNode addMessageFirst(MessageReference message);
048
049    /**
050     * Adds the given message to the tail of the list.
051     *
052     * @param message
053     *      The MessageReference that is to be added to this list.
054     *
055     * @return the PendingNode that contains the newly added message.
056     */
057    public PendingNode addMessageLast(MessageReference message);
058
059    /**
060     * Removes the given MessageReference from the PendingList if it is
061     * contained within.
062     *
063     * @param message
064     *      The MessageReference that is to be removed to this list.
065     *
066     * @return the PendingNode that contains the removed message or null if the
067     *         message was not present in this list.
068     */
069    public PendingNode remove(MessageReference message);
070
071    /**
072     * Returns the number of MessageReferences that are awaiting dispatch.
073     * @return current count of the pending messages.
074     */
075    public int size();
076
077    /**
078     * Returns an iterator over the pending Messages.  The subclass controls how
079     * the returned iterator actually traverses the list of pending messages allowing
080     * for the order to vary based on factors like Message priority or some other
081     * mechanism.
082     *
083     * @return an Iterator that returns MessageReferences contained in this list.
084     */
085    public Iterator<MessageReference> iterator();
086
087    /**
088     * Query the PendingList to determine if the given message is contained within.
089     *
090     * @param message
091     *      The Message that is the target of this query.
092     *
093     * @return true if the MessageReference is contained in this list.
094     */
095    public boolean contains(MessageReference message);
096
097    /**
098     * Returns a new Collection that contains all the MessageReferences currently
099     * held in this PendingList.  The elements of the list are ordered using the
100     * same rules as the subclass uses for iteration.
101     *
102     * @return a new Collection containing this lists MessageReferences.
103     */
104    public Collection<MessageReference> values();
105
106    /**
107     * Adds all the elements of the given PendingList to this PendingList.
108     *
109     * @param pendingList
110     *      The PendingList that is to be added to this collection.
111     */
112    public void addAll(PendingList pendingList);
113
114    public MessageReference get(MessageId messageId);
115
116}