001/*
002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Florent Guillaume
018 */
019package org.nuxeo.ecm.core.transientstore.api;
020
021import java.util.Set;
022import java.util.stream.Collectors;
023import java.util.stream.Stream;
024
025/**
026 * Transient Store SPI.
027 *
028 * @since 9.3
029 */
030public interface TransientStoreProvider extends TransientStore {
031
032    /**
033     * Initializes the store from the given {@code config}.
034     *
035     * @since 7.2
036     */
037    void init(TransientStoreConfig config);
038
039    /**
040     * Shuts down the store.
041     *
042     * @since 7.2
043     */
044    void shutdown();
045
046    /**
047     * Returns the set of keys for all entries.
048     *
049     * @since 8.3
050     */
051    default Set<String> keySet() {
052        return keyStream().collect(Collectors.toSet());
053    }
054
055    /**
056     * Returns a {@link Stream} of keys for all entries.
057     *
058     * @since 9.3
059     */
060    Stream<String> keyStream();
061
062    /**
063     * Returns the size (in MB) of the disk storage used for blobs.
064     *
065     * @return the number of MB (rounded down) used by stored blobs
066     * @since 7.2
067     * @deprecated since 9.3 because it is imprecise, use {@link #getStorageSize} instead
068     */
069    @Deprecated
070    default int getStorageSizeMB() {
071        return (int) (getStorageSize() / 1024 / 1024);
072    }
073
074    /**
075     * Returns the size (in bytes) of the disk storage used for blobs.
076     *
077     * @return the number of bytes used by stored blobs
078     * @since 9.3
079     */
080    long getStorageSize();
081
082    /**
083     * Runs garbage collecting to delete the file system resources that are associated with entries that were removed.
084     *
085     * @since 7.2
086     */
087    void doGC();
088
089    /**
090     * Removes all entries from the store.
091     *
092     * @since 7.2
093     */
094    void removeAll();
095
096}