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