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