001/*
002 * (C) Copyright 2015 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 * Nuxeo - initial API and implementation
016 */
017
018package org.nuxeo.ecm.core.transientstore.api;
019
020import java.io.File;
021import java.io.Serializable;
022import java.util.List;
023import java.util.Map;
024
025import org.nuxeo.common.annotation.Experimental;
026import org.nuxeo.ecm.core.api.Blob;
027
028/**
029 * Represents an entry that can be stored inside a {@link TransientStore}. The entry is will be stored in 2 sub parts :
030 * the Blobs that will be stored in file system, and the java attributes that will be kept in memory
031 *
032 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
033 * @since 7.2
034 */
035@Experimental(comment = "https://jira.nuxeo.com/browse/NXP-16577")
036public interface StorageEntry extends Serializable {
037
038    /**
039     * Returns the id associated with an entry In the default implementation this id must an ascii alphanumeric string
040     *
041     * @return the id of the entry
042     */
043    String getId();
044
045    /**
046     * Set the Blobs that must be associated with the entry
047     */
048    void setBlobs(List<Blob> blobs);
049
050    /**
051     * @return the Blobs that are associated to the entry
052     */
053    List<Blob> getBlobs();
054
055    /**
056     * Add a named parameter to the entry
057     *
058     * @param key the name of the parameter
059     * @param value the {@link Serializable} value
060     */
061    void put(String key, Serializable value);
062
063    /**
064     * Reads the value of named parameters.
065     */
066    Serializable get(String key);
067
068    /**
069     * Put multiple named parameters.
070     */
071    void putAll(Map<String, Serializable> params);
072
073    /**
074     * Returns the named parameters.
075     *
076     * @since 7.4
077     */
078    Map<String, Serializable> getParameters();
079
080    /**
081     * Callback to do some cleanup before entry is removed from the {@link TransientStore}.
082     */
083    void beforeRemove();
084
085    /**
086     * Called by {@link TransientStore} to persist the Blobs to disk and then be sure that the entry can be Serialized
087     * without loosing any data.
088     */
089    void persist(File directory);
090
091    /**
092     * Called by {@link TransientStore} to load Blobs from disk.
093     */
094    void load(File directory);
095
096    /**
097     * Returns the size of the persisted Blobs
098     */
099    long getSize();
100
101    /**
102     * Returns the size of the persisted Blobs. long getSize(); /** Returns the size last time the entry was stored.
103     */
104    long getLastStorageSize();
105
106    /**
107     * flag to indicate if result is ready.
108     *
109     * @since 7.3
110     */
111    boolean isCompleted();
112
113    /**
114     * Mark the storage entry as ready.
115     *
116     * @since 7.3
117     */
118    void setCompleted(boolean completed);
119
120}