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; 021 022import org.apache.activemq.broker.region.MessageReference; 023import org.apache.activemq.command.MessageId; 024 025public interface PendingList extends Iterable<MessageReference> { 026 027 /** 028 * Returns true if there are no Messages in the PendingList currently. 029 * @return true if the PendingList is currently empty. 030 */ 031 public boolean isEmpty(); 032 033 /** 034 * Discards all Messages currently held in the PendingList. 035 */ 036 public void clear(); 037 038 /** 039 * Adds the given message to the head of the list. 040 * 041 * @param message 042 * The MessageReference that is to be added to this list. 043 * 044 * @return the PendingNode that contains the newly added message. 045 */ 046 public PendingNode addMessageFirst(MessageReference message); 047 048 /** 049 * Adds the given message to the tail of the list. 050 * 051 * @param message 052 * The MessageReference that is to be added to this list. 053 * 054 * @return the PendingNode that contains the newly added message. 055 */ 056 public PendingNode addMessageLast(MessageReference message); 057 058 /** 059 * Removes the given MessageReference from the PendingList if it is 060 * contained within. 061 * 062 * @param message 063 * The MessageReference that is to be removed to this list. 064 * 065 * @return the PendingNode that contains the removed message or null if the 066 * message was not present in this list. 067 */ 068 public PendingNode remove(MessageReference message); 069 070 /** 071 * Returns the number of MessageReferences that are awaiting dispatch. 072 * @return current count of the pending messages. 073 */ 074 public int size(); 075 076 public long messageSize(); 077 078 /** 079 * Returns an iterator over the pending Messages. The subclass controls how 080 * the returned iterator actually traverses the list of pending messages allowing 081 * for the order to vary based on factors like Message priority or some other 082 * mechanism. 083 * 084 * @return an Iterator that returns MessageReferences contained in this list. 085 */ 086 @Override 087 public Iterator<MessageReference> iterator(); 088 089 /** 090 * Query the PendingList to determine if the given message is contained within. 091 * 092 * @param message 093 * The Message that is the target of this query. 094 * 095 * @return true if the MessageReference is contained in this list. 096 */ 097 public boolean contains(MessageReference message); 098 099 /** 100 * Returns a new Collection that contains all the MessageReferences currently 101 * held in this PendingList. The elements of the list are ordered using the 102 * same rules as the subclass uses for iteration. 103 * 104 * @return a new Collection containing this lists MessageReferences. 105 */ 106 public Collection<MessageReference> values(); 107 108 /** 109 * Adds all the elements of the given PendingList to this PendingList. 110 * 111 * @param pendingList 112 * The PendingList that is to be added to this collection. 113 */ 114 public void addAll(PendingList pendingList); 115 116 public MessageReference get(MessageId messageId); 117}