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