001/*
002 * (C) Copyright 2015 Nuxeo SA (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 *     Thierry Delprat <tdelprat@nuxeo.com>
018 *     Antoine Taillefer <ataillefer@nuxeo.com>
019 */
020
021package org.nuxeo.ecm.core.transientstore.api;
022
023import java.io.Serializable;
024import java.util.List;
025import java.util.Map;
026import java.util.Set;
027
028import org.nuxeo.ecm.core.api.Blob;
029
030/**
031 * Service Interface for managing a transient store.
032 * <p>
033 * Allows to store entries in 2 sub parts: a list of blobs stored on a file system along with a map of parameters.
034 *
035 * @since 7.2
036 */
037public interface TransientStore {
038
039    /**
040     * Initializes the store from the given {@code config}.
041     */
042    void init(TransientStoreConfig config);
043
044    /**
045     * Shuts down the store.
046     */
047    void shutdown();
048
049    /**
050     * Returns {@code true} if an entry exists with the given {@code key}.
051     *
052     * @since 7.10
053     */
054    boolean exists(String key);
055
056    /**
057     * Returns the set of keys for all entries.
058     *
059     * @since 8.3
060     */
061    Set<String> keySet();
062
063    /**
064     * Sets {@code parameter} to {@code value} in the entry with the given {@code key}.
065     * <p>
066     * If entry does not exist a new entry is created. If {@code parameter} already exists in the entry it is
067     * overwritten.
068     *
069     * @since 7.10
070     */
071    void putParameter(String key, String parameter, Serializable value);
072
073    /**
074     * Gets the value of {@code parameter} in the entry with the given {@code key}.
075     * <p>
076     * Returns {@code null} if entry or parameter does not exist.
077     *
078     * @since 7.10
079     */
080    Serializable getParameter(String key, String parameter);
081
082    /**
083     * Puts {@code parameters} in the entry with the given {@code key}. Overwrites any existing parameter in the entry.
084     * <p>
085     * If entry does not exist a new entry is created.
086     *
087     * @since 7.10
088     */
089    void putParameters(String key, Map<String, Serializable> parameters);
090
091    /**
092     * Gets values of the parameters in the entry with the given {@code key}.
093     * <p>
094     * Returns {@code null} if entry does not exist.
095     *
096     * @since 7.10
097     */
098    Map<String, Serializable> getParameters(String key);
099
100    /**
101     * Associates the given {@code blobs} with the entry with the given {@code key}.
102     * <p>
103     * If entry does not exist a new entry is created.
104     *
105     * @since 7.10
106     */
107    void putBlobs(String key, List<Blob> blobs);
108
109    /**
110     * Gets the blobs associated with the entry with the given {@code key}.
111     * <p>
112     * Returns {@code null} if entry does not exist.
113     *
114     * @since 7.10
115     */
116    List<Blob> getBlobs(String key);
117
118    /**
119     * Returns the size of the blobs associated with the entry with the given {@code key} or {@code -1} if entry does
120     * not exist.
121     *
122     * @since 7.10
123     */
124    long getSize(String key);
125
126    /**
127     * Returns {@code true} if the entry with the given {@code key} is ready.
128     *
129     * @since 7.10
130     */
131    boolean isCompleted(String key);
132
133    /**
134     * Marks the entry with the given {@code key} as ready.
135     * <p>
136     * If entry does not exist a new entry is created.
137     *
138     * @since 7.10
139     */
140    void setCompleted(String key, boolean completed);
141
142    /**
143     * Removes entry with the given {@code key}.
144     * <p>
145     * Has no effect if entry does not exist.
146     */
147    void remove(String key);
148
149    /**
150     * Informs the store that the entry with the given {@code key} can be released if TTL or GC parameters require to do
151     * some cleanup.
152     * <p>
153     * Has no effect if entry does not exist.
154     */
155    void release(String key);
156
157    /**
158     * Returns the size of the used disk storage in MB.
159     */
160    int getStorageSizeMB();
161
162    /**
163     * Runs garbage collecting to delete the file system resources that are associated with entries that were removed.
164     */
165    void doGC();
166
167    /**
168     * Removes all entries from the store.
169     */
170    void removeAll();
171
172}