diff options
Diffstat (limited to 'java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java')
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java | 245 |
1 files changed, 129 insertions, 116 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java b/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java index 8553db3e09..dd967a7cb1 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java +++ b/java/broker/src/main/java/org/apache/qpid/server/queue/QueueEntry.java @@ -1,173 +1,186 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.qpid.server.queue; import org.apache.qpid.AMQException; import org.apache.qpid.server.store.StoreContext; -import org.apache.log4j.Logger; - -import java.util.Set; -import java.util.HashSet; -import java.util.concurrent.atomic.AtomicReference; - +import org.apache.qpid.server.subscription.Subscription; -public class QueueEntry +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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. +* +*/ +public interface QueueEntry extends Comparable<QueueEntry> { - /** - * Used for debugging purposes. - */ - private static final Logger _log = Logger.getLogger(QueueEntry.class); - - private final AMQQueue _queue; - private final AMQMessage _message; - private Set<Subscription> _rejectedBy = null; - private AtomicReference<Object> _owner = new AtomicReference<Object>(); - - - public QueueEntry(AMQQueue queue, AMQMessage message) + public static enum State { - _queue = queue; - _message = message; + AVAILABLE, + ACQUIRED, + EXPIRED, + DEQUEUED, + DELETED } - - public AMQQueue getQueue() + public static interface StateChangeListener { - return _queue; + public void stateChanged(QueueEntry entry, State oldSate, State newState); } - public AMQMessage getMessage() + public abstract class EntryState { - return _message; - } + private EntryState() + { + } - public long getSize() - { - return getMessage().getSize(); + public abstract State getState(); } - public boolean getDeliveredToConsumer() - { - return getMessage().getDeliveredToConsumer(); - } - public boolean expired() throws AMQException + public final class AvailableState extends EntryState { - return getMessage().expired(_queue); - } - public boolean isTaken() - { - return _owner.get() != null; + public State getState() + { + return State.AVAILABLE; + } } - public boolean taken(Subscription sub) - { - return !(_owner.compareAndSet(null, sub == null ? this : sub)); - } - public void setDeliveredToConsumer() + public final class DequeuedState extends EntryState { - getMessage().setDeliveredToConsumer(); - } - public void release() - { - _owner.set(null); + public State getState() + { + return State.DEQUEUED; + } } - public String debugIdentity() - { - return getMessage().debugIdentity(); - } - public void process(StoreContext storeContext, boolean deliverFirst) throws AMQException + public final class DeletedState extends EntryState { - _queue.process(storeContext, this, deliverFirst); - } - public void checkDeliveredToConsumer() throws NoConsumersException - { - _message.checkDeliveredToConsumer(); + public State getState() + { + return State.DELETED; + } } - public void setRedelivered(boolean b) + public final class ExpiredState extends EntryState { - getMessage().setRedelivered(b); - } - public Subscription getDeliveredSubscription() - { - synchronized (this) + public State getState() { - Object owner = _owner.get(); - if (owner instanceof Subscription) - { - return (Subscription) owner; - } - else - { - return null; - } + return State.EXPIRED; } } - public void reject() + + public final class NonSubscriptionAcquiredState extends EntryState { - reject(getDeliveredSubscription()); + public State getState() + { + return State.ACQUIRED; + } } - public void reject(Subscription subscription) + public final class SubscriptionAcquiredState extends EntryState { - if (subscription != null) - { - if (_rejectedBy == null) - { - _rejectedBy = new HashSet<Subscription>(); - } + private final Subscription _subscription; - _rejectedBy.add(subscription); - } - else + public SubscriptionAcquiredState(Subscription subscription) { - _log.warn("Requesting rejection by null subscriber:" + debugIdentity()); + _subscription = subscription; } - } - public boolean isRejectedBy(Subscription subscription) - { - boolean rejected = _rejectedBy != null; - if (rejected) // We have subscriptions that rejected this message + public State getState() { - return _rejectedBy.contains(subscription); + return State.ACQUIRED; } - else // This messasge hasn't been rejected yet. + + public Subscription getSubscription() { - return rejected; + return _subscription; } } + final static EntryState AVAILABLE_STATE = new AvailableState(); + final static EntryState DELETED_STATE = new DeletedState(); + final static EntryState DEQUEUED_STATE = new DequeuedState(); + final static EntryState EXPIRED_STATE = new ExpiredState(); + final static EntryState NON_SUBSCRIPTION_ACQUIRED_STATE = new NonSubscriptionAcquiredState(); + + + + + AMQQueue getQueue(); + + AMQMessage getMessage(); + + long getSize(); + + boolean getDeliveredToConsumer(); + + boolean expired() throws AMQException; + + boolean isAcquired(); + + boolean acquire(); + boolean acquire(Subscription sub); + + boolean delete(); + boolean isDeleted(); + + boolean acquiredBySubscription(); + + void setDeliveredToSubscription(); + + void release(); + + String debugIdentity(); + + boolean immediateAndNotDelivered(); + + void setRedelivered(boolean b); + + Subscription getDeliveredSubscription(); + + void reject(); + + void reject(Subscription subscription); + + boolean isRejectedBy(Subscription subscription); + + void requeue(StoreContext storeContext) throws AMQException; + + void dequeue(final StoreContext storeContext) throws FailedDequeueException; + + void dispose(final StoreContext storeContext) throws MessageCleanupException; + + void restoreCredit(); + + void discard(StoreContext storeContext) throws FailedDequeueException, MessageCleanupException; + + boolean isQueueDeleted(); + + void addStateChangeListener(StateChangeListener listener); + boolean removeStateChangeListener(StateChangeListener listener); } |