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.store;
018
019import java.io.IOException;
020import java.util.concurrent.Callable;
021import java.util.concurrent.Future;
022import java.util.concurrent.FutureTask;
023
024import org.apache.activemq.broker.ConnectionContext;
025import org.apache.activemq.command.ActiveMQDestination;
026import org.apache.activemq.command.Message;
027import org.apache.activemq.command.MessageAck;
028import org.apache.activemq.command.MessageId;
029import org.apache.activemq.usage.MemoryUsage;
030
031abstract public class AbstractMessageStore implements MessageStore {
032    public static final FutureTask<Object> FUTURE;
033    protected final ActiveMQDestination destination;
034    protected boolean prioritizedMessages;
035
036    public AbstractMessageStore(ActiveMQDestination destination) {
037        this.destination = destination;
038    }
039
040    @Override
041    public void dispose(ConnectionContext context) {
042    }
043
044    @Override
045    public void start() throws Exception {
046    }
047
048    @Override
049    public void stop() throws Exception {
050    }
051
052    @Override
053    public ActiveMQDestination getDestination() {
054        return destination;
055    }
056
057    @Override
058    public void setMemoryUsage(MemoryUsage memoryUsage) {
059    }
060
061    @Override
062    public void setBatch(MessageId messageId) throws IOException, Exception {
063    }
064
065    /**
066     * flag to indicate if the store is empty
067     *
068     * @return true if the message count is 0
069     * @throws Exception
070     */
071    @Override
072    public boolean isEmpty() throws Exception {
073        return getMessageCount() == 0;
074    }
075
076    @Override
077    public void setPrioritizedMessages(boolean prioritizedMessages) {
078        this.prioritizedMessages = prioritizedMessages;
079    }
080
081    @Override
082    public boolean isPrioritizedMessages() {
083        return this.prioritizedMessages;
084    }
085
086    @Override
087    public void addMessage(final ConnectionContext context, final Message message, final boolean canOptimizeHint) throws IOException{
088        addMessage(context, message);
089    }
090
091    @Override
092    public Future<Object> asyncAddQueueMessage(final ConnectionContext context, final Message message) throws IOException {
093        addMessage(context, message);
094        return FUTURE;
095    }
096
097    @Override
098    public Future<Object> asyncAddQueueMessage(final ConnectionContext context, final Message message,final boolean canOptimizeHint) throws IOException {
099        addMessage(context, message, canOptimizeHint);
100        return FUTURE;
101    }
102
103    @Override
104    public Future<Object> asyncAddTopicMessage(final ConnectionContext context, final Message message,final boolean canOptimizeHint) throws IOException {
105        addMessage(context, message, canOptimizeHint);
106        return FUTURE;
107    }
108
109    @Override
110    public Future<Object> asyncAddTopicMessage(final ConnectionContext context, final Message message) throws IOException {
111        addMessage(context, message);
112        return FUTURE;
113    }
114
115    @Override
116    public void removeAsyncMessage(ConnectionContext context, MessageAck ack) throws IOException {
117        removeMessage(context, ack);
118    }
119
120    static class CallableImplementation implements Callable<Object> {
121        public Object call() throws Exception {
122            return null;
123        }
124    }
125
126    static {
127       FUTURE = new FutureTask<Object>(new CallableImplementation());
128       FUTURE.run();
129    }
130}