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 */ 017 package org.apache.activemq.store; 018 019 import java.io.File; 020 import java.io.IOException; 021 import java.util.Set; 022 023 import org.apache.activemq.Service; 024 import org.apache.activemq.broker.ConnectionContext; 025 import org.apache.activemq.broker.region.Destination; 026 import org.apache.activemq.command.ActiveMQDestination; 027 import org.apache.activemq.command.ActiveMQQueue; 028 import org.apache.activemq.command.ActiveMQTopic; 029 import org.apache.activemq.command.ProducerId; 030 import org.apache.activemq.usage.SystemUsage; 031 032 /** 033 * Adapter to the actual persistence mechanism used with ActiveMQ 034 * 035 * 036 */ 037 public interface PersistenceAdapter extends Service { 038 039 /** 040 * Returns a set of all the {@link org.apache.activemq.command.ActiveMQDestination} 041 * objects that the persistence store is aware exist. 042 * 043 * @return active destinations 044 */ 045 Set<ActiveMQDestination> getDestinations(); 046 047 /** 048 * Factory method to create a new queue message store with the given destination name 049 * @param destination 050 * @return the message store 051 * @throws IOException 052 */ 053 MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException; 054 055 /** 056 * Factory method to create a new topic message store with the given destination name 057 * @param destination 058 * @return the topic message store 059 * @throws IOException 060 */ 061 TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException; 062 063 /** 064 * Cleanup method to remove any state associated with the given destination. 065 * This method does not stop the message store (it might not be cached). 066 * @param destination Destination to forget 067 */ 068 void removeQueueMessageStore(ActiveMQQueue destination); 069 070 /** 071 * Cleanup method to remove any state associated with the given destination 072 * This method does not stop the message store (it might not be cached). 073 * @param destination Destination to forget 074 */ 075 void removeTopicMessageStore(ActiveMQTopic destination); 076 077 /** 078 * Factory method to create a new persistent prepared transaction store for XA recovery 079 * @return transaction store 080 * @throws IOException 081 */ 082 TransactionStore createTransactionStore() throws IOException; 083 084 /** 085 * This method starts a transaction on the persistent storage - which is nothing to 086 * do with JMS or XA transactions - its purely a mechanism to perform multiple writes 087 * to a persistent store in 1 transaction as a performance optimization. 088 * <p/> 089 * Typically one transaction will require one disk synchronization point and so for 090 * real high performance its usually faster to perform many writes within the same 091 * transaction to minimize latency caused by disk synchronization. This is especially 092 * true when using tools like Berkeley Db or embedded JDBC servers. 093 * @param context 094 * @throws IOException 095 */ 096 void beginTransaction(ConnectionContext context) throws IOException; 097 098 099 /** 100 * Commit a persistence transaction 101 * @param context 102 * @throws IOException 103 * 104 * @see PersistenceAdapter#beginTransaction(ConnectionContext context) 105 */ 106 void commitTransaction(ConnectionContext context) throws IOException; 107 108 /** 109 * Rollback a persistence transaction 110 * @param context 111 * @throws IOException 112 * 113 * @see PersistenceAdapter#beginTransaction(ConnectionContext context) 114 */ 115 void rollbackTransaction(ConnectionContext context) throws IOException; 116 117 /** 118 * 119 * @return last broker sequence 120 * @throws IOException 121 */ 122 long getLastMessageBrokerSequenceId() throws IOException; 123 124 /** 125 * Delete's all the messages in the persistent store. 126 * 127 * @throws IOException 128 */ 129 void deleteAllMessages() throws IOException; 130 131 /** 132 * @param usageManager The UsageManager that is controlling the broker's memory usage. 133 */ 134 void setUsageManager(SystemUsage usageManager); 135 136 /** 137 * Set the name of the broker using the adapter 138 * @param brokerName 139 */ 140 void setBrokerName(String brokerName); 141 142 /** 143 * Set the directory where any data files should be created 144 * @param dir 145 */ 146 void setDirectory(File dir); 147 148 /** 149 * checkpoint any 150 * @param sync 151 * @throws IOException 152 * 153 */ 154 void checkpoint(boolean sync) throws IOException; 155 156 /** 157 * A hint to return the size of the store on disk 158 * @return disk space used in bytes of 0 if not implemented 159 */ 160 long size(); 161 162 /** 163 * return the last stored producer sequenceId for this producer Id 164 * used to suppress duplicate sends on failover reconnect at the transport 165 * when a reconnect occurs 166 * @param id the producerId to find a sequenceId for 167 * @return the last stored sequence id or -1 if no suppression needed 168 */ 169 long getLastProducerSequenceId(ProducerId id) throws IOException; 170 }