QueueEntry.java
001 package org.apache.qpid.server.queue;
002 
003 import org.apache.qpid.AMQException;
004 import org.apache.qpid.server.store.StoreContext;
005 import org.apache.qpid.server.subscription.Subscription;
006 
007 /*
008 *
009 * Licensed to the Apache Software Foundation (ASF) under one
010 * or more contributor license agreements.  See the NOTICE file
011 * distributed with this work for additional information
012 * regarding copyright ownership.  The ASF licenses this file
013 * to you under the Apache License, Version 2.0 (the
014 * "License"); you may not use this file except in compliance
015 * with the License.  You may obtain a copy of the License at
016 *
017 *   http://www.apache.org/licenses/LICENSE-2.0
018 *
019 * Unless required by applicable law or agreed to in writing,
020 * software distributed under the License is distributed on an
021 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
022 * KIND, either express or implied.  See the License for the
023 * specific language governing permissions and limitations
024 * under the License.
025 *
026 */
027 public interface QueueEntry extends Comparable<QueueEntry>, Filterable<AMQException>
028 {
029     public static enum State
030     {
031         AVAILABLE,
032         ACQUIRED,
033         EXPIRED,
034         DEQUEUED,
035         DELETED
036     }
037 
038     public static interface StateChangeListener
039     {
040         public void stateChanged(QueueEntry entry, State oldSate, State newState);
041     }
042 
043     public abstract class EntryState
044     {
045         private EntryState()
046         {
047         }
048 
049         public abstract State getState();
050     }
051 
052     public final class AvailableState extends EntryState
053     {
054 
055         public State getState()
056         {
057             return State.AVAILABLE;
058         }
059     }
060 
061     public final class DequeuedState extends EntryState
062     {
063 
064         public State getState()
065         {
066             return State.DEQUEUED;
067         }
068     }
069 
070     public final class DeletedState extends EntryState
071     {
072 
073         public State getState()
074         {
075             return State.DELETED;
076         }
077     }
078 
079     public final class ExpiredState extends EntryState
080     {
081 
082         public State getState()
083         {
084             return State.EXPIRED;
085         }
086     }
087 
088     public final class NonSubscriptionAcquiredState extends EntryState
089     {
090         public State getState()
091         {
092             return State.ACQUIRED;
093         }
094     }
095 
096     public final class SubscriptionAcquiredState extends EntryState
097     {
098         private final Subscription _subscription;
099 
100         public SubscriptionAcquiredState(Subscription subscription)
101         {
102             _subscription = subscription;
103         }
104 
105         public State getState()
106         {
107             return State.ACQUIRED;
108         }
109 
110         public Subscription getSubscription()
111         {
112             return _subscription;
113         }
114     }
115 
116     final static EntryState AVAILABLE_STATE = new AvailableState();
117     final static EntryState DELETED_STATE = new DeletedState();
118     final static EntryState DEQUEUED_STATE = new DequeuedState();
119     final static EntryState EXPIRED_STATE = new ExpiredState();
120     final static EntryState NON_SUBSCRIPTION_ACQUIRED_STATE = new NonSubscriptionAcquiredState();
121 
122     AMQQueue getQueue();
123 
124     AMQMessage getMessage();
125 
126     long getSize();
127 
128     boolean getDeliveredToConsumer();
129 
130     boolean expired() throws AMQException;
131 
132     boolean isAcquired();
133 
134     boolean acquire();
135 
136     boolean acquire(Subscription sub);
137 
138     boolean delete();
139 
140     boolean isDeleted();
141 
142     boolean acquiredBySubscription();
143 
144     void setDeliveredToSubscription();
145 
146     void release();
147 
148     String debugIdentity();
149 
150     boolean immediateAndNotDelivered();
151 
152     void setRedelivered(boolean b);
153 
154     Subscription getDeliveredSubscription();
155 
156     void reject();
157 
158     void reject(Subscription subscription);
159 
160     boolean isRejectedBy(Subscription subscription);
161 
162     void requeue(StoreContext storeContextthrows AMQException;
163 
164     void dequeue(final StoreContext storeContextthrows FailedDequeueException;
165 
166     /**
167      * Message has been ack so dequeueAndDelete it.
168      * If the message is persistent and this is the last QueueEntry that uses it then the data will be removed
169      * from the transaciton log
170      *
171      @param storeContext the transactional Context in which to perform the deletion
172      *
173      @throws FailedDequeueException
174      @throws MessageCleanupException
175      */
176     void dequeueAndDelete(StoreContext storeContextthrows FailedDequeueException;
177 
178     boolean isQueueDeleted();
179 
180     void addStateChangeListener(StateChangeListener listener);
181 
182     boolean removeStateChangeListener(StateChangeListener listener);
183 }