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     * Returns {@code true} if an entry exists with the given {@code key}.
041     *
042     * @since 7.10
043     */
044    boolean exists(String key);
045
046    /**
047     * Sets {@code parameter} to {@code value} in the entry with the given {@code key}.
048     * <p>
049     * If entry does not exist a new entry is created. If {@code parameter} already exists in the entry it is
050     * overwritten.
051     *
052     * @since 7.10
053     */
054    void putParameter(String key, String parameter, Serializable value);
055
056    /**
057     * Gets the value of {@code parameter} in the entry with the given {@code key}.
058     * <p>
059     * Returns {@code null} if entry or parameter does not exist.
060     *
061     * @since 7.10
062     */
063    Serializable getParameter(String key, String parameter);
064
065    /**
066     * Puts {@code parameters} in the entry with the given {@code key}. Overwrites any existing parameter in the entry.
067     * <p>
068     * If entry does not exist a new entry is created.
069     *
070     * @since 7.10
071     */
072    void putParameters(String key, Map<String, Serializable> parameters);
073
074    /**
075     * Gets values of the parameters in the entry with the given {@code key}.
076     * <p>
077     * Returns {@code null} if entry does not exist.
078     *
079     * @since 7.10
080     */
081    Map<String, Serializable> getParameters(String key);
082
083    /**
084     * Associates the given {@code blobs} with the entry with the given {@code key}.
085     * <p>
086     * If entry does not exist a new entry is created.
087     *
088     * @since 7.10
089     */
090    void putBlobs(String key, List<Blob> blobs);
091
092    /**
093     * Gets the blobs associated with the entry with the given {@code key}.
094     * <p>
095     * Returns {@code null} if entry does not exist.
096     *
097     * @since 7.10
098     */
099    List<Blob> getBlobs(String key);
100
101    /**
102     * Returns the size of the blobs associated with the entry with the given {@code key} or {@code -1} if entry does
103     * not exist.
104     *
105     * @since 7.10
106     */
107    long getSize(String key);
108
109    /**
110     * Returns {@code true} if the entry with the given {@code key} is ready.
111     *
112     * @since 7.10
113     */
114    boolean isCompleted(String key);
115
116    /**
117     * Marks the entry with the given {@code key} as ready.
118     * <p>
119     * If entry does not exist a new entry is created.
120     *
121     * @since 7.10
122     */
123    void setCompleted(String key, boolean completed);
124
125    /**
126     * Removes entry with the given {@code key}.
127     * <p>
128     * Has no effect if entry does not exist.
129     */
130    void remove(String key);
131
132    /**
133     * Informs the store that the entry with the given {@code key} can be released if TTL or GC parameters require to do
134     * some cleanup.
135     * <p>
136     * Has no effect if entry does not exist.
137     */
138    void release(String key);
139
140}