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.kaha;
018
019import java.io.IOException;
020import java.util.Set;
021
022/**
023 * A Store is holds persistent containers
024 * 
025 * 
026 */
027public interface Store {
028    /**
029     * Defauly container name
030     */
031    String DEFAULT_CONTAINER_NAME = "kaha";
032
033    /**
034     * Byte Marshaller
035     */
036    Marshaller BYTES_MARSHALLER = new BytesMarshaller();
037
038    /**
039     * Object Marshaller
040     */
041    Marshaller OBJECT_MARSHALLER = new ObjectMarshaller();
042
043    /**
044     * String Marshaller
045     */
046    Marshaller STRING_MARSHALLER = new StringMarshaller();
047
048    /**
049     * Command Marshaller
050     */
051    Marshaller COMMAND_MARSHALLER = new CommandMarshaller();
052    
053    /**
054     * MessageId marshaller
055     */
056    Marshaller MESSAGEID_MARSHALLER = new MessageIdMarshaller();
057
058    /**
059     * close the store
060     * 
061     * @throws IOException
062     */
063    void close() throws IOException;
064
065    /**
066     * Force all writes to disk
067     * 
068     * @throws IOException
069     */
070    void force() throws IOException;
071
072    /**
073     * empty all the contents of the store
074     * 
075     * @throws IOException
076     */
077    void clear() throws IOException;
078
079    /**
080     * delete the store
081     * 
082     * @return true if the delete was successful
083     * @throws IOException
084     */
085    boolean delete() throws IOException;
086
087    /**
088     * Checks if a MapContainer exists in the default container
089     * 
090     * @param id
091     * @return new MapContainer
092     * @throws IOException
093     */
094    boolean doesMapContainerExist(Object id) throws IOException;
095
096    /**
097     * Checks if a MapContainer exists in the named container
098     * 
099     * @param id
100     * @param containerName
101     * @return new MapContainer
102     * @throws IOException
103     */
104    boolean doesMapContainerExist(Object id, String containerName) throws IOException;
105
106    /**
107     * Get a MapContainer with the given id - the MapContainer is created if
108     * needed
109     * 
110     * @param id
111     * @return container for the associated id or null if it doesn't exist
112     * @throws IOException
113     */
114    MapContainer getMapContainer(Object id) throws IOException;
115
116    /**
117     * Get a MapContainer with the given id - the MapContainer is created if
118     * needed
119     * 
120     * @param id
121     * @param containerName
122     * @return container for the associated id or null if it doesn't exist
123     * @throws IOException
124     */
125    MapContainer getMapContainer(Object id, String containerName) throws IOException;
126
127    /**
128     * Get a MapContainer with the given id - the MapContainer is created if
129     * needed
130     * 
131     * @param id
132     * @param containerName
133     * @param persistentIndex
134     * @return container for the associated id or null if it doesn't exist
135     * @throws IOException
136     */
137    MapContainer getMapContainer(Object id, String containerName, boolean persistentIndex) throws IOException;
138
139    /**
140     * delete a container from the default container
141     * 
142     * @param id
143     * @throws IOException
144     */
145    void deleteMapContainer(Object id) throws IOException;
146
147    /**
148     * delete a MapContainer from the name container
149     * 
150     * @param id
151     * @param containerName
152     * @throws IOException
153     */
154    void deleteMapContainer(Object id, String containerName) throws IOException;
155
156    /**
157     * Delete Map container
158     * 
159     * @param id
160     * @throws IOException
161     */
162    void deleteMapContainer(ContainerId id) throws IOException;
163
164    /**
165     * Get a Set of call MapContainer Ids
166     * 
167     * @return the set of ids
168     * @throws IOException
169     */
170    Set<ContainerId> getMapContainerIds() throws IOException;
171
172    /**
173     * Checks if a ListContainer exists in the default container
174     * 
175     * @param id
176     * @return new MapContainer
177     * @throws IOException
178     */
179    boolean doesListContainerExist(Object id) throws IOException;
180
181    /**
182     * Checks if a ListContainer exists in the named container
183     * 
184     * @param id
185     * @param containerName
186     * @return new MapContainer
187     * @throws IOException
188     */
189    boolean doesListContainerExist(Object id, String containerName) throws IOException;
190
191    /**
192     * Get a ListContainer with the given id and creates it if it doesn't exist
193     * 
194     * @param id
195     * @return container for the associated id or null if it doesn't exist
196     * @throws IOException
197     */
198    ListContainer getListContainer(Object id) throws IOException;
199
200    /**
201     * Get a ListContainer with the given id and creates it if it doesn't exist
202     * 
203     * @param id
204     * @param containerName
205     * @return container for the associated id or null if it doesn't exist
206     * @throws IOException
207     */
208    ListContainer getListContainer(Object id, String containerName) throws IOException;
209
210    /**
211     * Get a ListContainer with the given id and creates it if it doesn't exist
212     * 
213     * @param id
214     * @param containerName
215     * @param persistentIndex
216     * @return container for the associated id or null if it doesn't exist
217     * @throws IOException
218     */
219    ListContainer getListContainer(Object id, String containerName, boolean persistentIndex) throws IOException;
220
221    /**
222     * delete a ListContainer from the default container
223     * 
224     * @param id
225     * @throws IOException
226     */
227    void deleteListContainer(Object id) throws IOException;
228
229    /**
230     * delete a ListContainer from the named container
231     * 
232     * @param id
233     * @param containerName
234     * @throws IOException
235     */
236    void deleteListContainer(Object id, String containerName) throws IOException;
237
238    /**
239     * delete a list container
240     * 
241     * @param id
242     * @throws IOException
243     */
244    void deleteListContainer(ContainerId id) throws IOException;
245
246    /**
247     * Get a Set of call ListContainer Ids
248     * 
249     * @return the set of ids
250     * @throws IOException
251     */
252    Set<ContainerId> getListContainerIds() throws IOException;
253
254    /**
255     * @return the maxDataFileLength
256     */
257    long getMaxDataFileLength();
258
259    /**
260     * @param maxDataFileLength the maxDataFileLength to set
261     */
262    void setMaxDataFileLength(long maxDataFileLength);
263
264
265    /**
266     * @return true if the store has been initialized
267     */
268    boolean isInitialized();
269    
270    /**
271     * @return the amount of disk space the store is occupying
272     */
273    long size();
274    
275    /**
276     * @return true if persistent indexes are used by default
277     */
278    public boolean isPersistentIndex();
279    
280        /**
281         * Set a persistent index as the default if the parameter is true
282         * @param persistentIndex
283         */
284        public void setPersistentIndex(boolean persistentIndex);
285        
286        /**
287         * @return the default container name
288         */
289        public String getDefaultContainerName();
290
291        /**
292         * set the default container name
293         * @param defaultContainerName
294         */
295    public void setDefaultContainerName(String defaultContainerName);
296
297        
298        /**
299         * An explict call to initialize - this will also be called
300         * implicitly for any other operation on the store.
301         * @throws IOException
302         */
303        public void initialize() throws IOException;
304        
305}