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.servicemix.store;
018    
019    import java.io.IOException;
020    
021    /**
022     * A Store is an interface representing a storage where objects can be
023     * put and retrieved.  A store can support different features, mainly
024     * persistence, clustered or transactional.
025     * 
026     *  A store is not designed to be a thread-safe map.  If a user tries to
027     *  store an object with an existing id, the behavior is undefined.
028     *  
029     * @author gnodet
030     */
031    public interface Store {
032    
033        String PERSISTENT = "Persistent";
034        
035        String CLUSTERED = "Clustered";
036        
037        String TRANSACTIONAL = "Transactional";
038        
039        /**
040         * Returns true if the store implementation supports the given feature.
041         * @param name the feature to check
042         * @return <code>true</code> if the feature is supported
043         */
044        boolean hasFeature(String name);
045        
046        /**
047         * Put an object in the store under the given id.
048         * This method must be used with caution and the behavior is
049         * unspecified if an object already exist for the same id.
050         *  
051         * @param id the id of the object to store
052         * @param data the object to store
053         * @throws IOException if an error occurs
054         */
055        void store(String id, Object data) throws IOException;
056        
057        /**
058         * Put an object into the store and return the unique id that
059         * may be used at a later time to retrieve the object.
060         * 
061         * @param data the object to store
062         * @return the id of the object stored
063         * @throws IOException if an error occurs
064         */
065        String store(Object data) throws IOException;
066        
067        /**
068         * Loads an object that has been previously stored under the specified key.
069         * The object is removed from the store.
070         * 
071         * @param id the id of the object
072         * @return the object, or <code>null></code> if the object could not be found
073         * @throws IOException if an error occurs
074         */
075        Object load(String id) throws IOException;
076        
077    }