001/* 002 * (C) Copyright 2006-2011 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 * Florent Guillaume 018 */ 019 020package org.nuxeo.ecm.core.blob.binary; 021 022import java.io.IOException; 023import java.util.Collection; 024import java.util.Map; 025 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.impl.blob.FileBlob; 028 029/** 030 * A binary manager stores binaries according to their digest. 031 */ 032public interface BinaryManager { 033 034 /** In the initialization properties, the property for the store path. */ 035 String PROP_PATH = "path"; 036 037 /** In the initialization properties, the property for a generic key. */ 038 String PROP_KEY = "key"; 039 040 /** 041 * Initializes the binary manager. 042 * 043 * @param blobProviderId the blob provider id for this binary manager 044 * @param properties initialization properties 045 * @since 7.3 046 */ 047 void initialize(String blobProviderId, Map<String, String> properties) throws IOException; 048 049 /** 050 * Saves the given blob into a {@link Binary}. 051 * <p> 052 * Returns a {@link Binary} representing the stream. The {@link Binary} includes a digest that is a sufficient 053 * representation to persist it. 054 * <p> 055 * If the blob is a temporary {@link FileBlob}, then the temporary file may be reused as the final storage location 056 * after being moved. 057 * 058 * @param blob the blob 059 * @return the corresponding binary 060 * @since 7.2 061 */ 062 Binary getBinary(Blob blob) throws IOException; 063 064 /** 065 * Returns a {@link Binary} corresponding to the given digest. 066 * <p> 067 * A {@code null} is returned if the digest could not be found. 068 * 069 * @param digest the digest, or {@code null} 070 * @return the corresponding binary 071 */ 072 Binary getBinary(String digest); 073 074 /** 075 * Remove definitively a set of binaries 076 * 077 * @since 7.10 078 * @param digests a set of digests, must not be {@code null}. 079 */ 080 void removeBinaries(Collection<String> digests); 081 082 /** 083 * Returns the Binary Garbage Collector that can be used for this binary manager. 084 * <p> 085 * Several calls to this method will return the same GC, so that its status can be monitored using 086 * {@link BinaryGarbageCollector#isInProgress}. 087 * 088 * @return the binary GC 089 */ 090 BinaryGarbageCollector getGarbageCollector(); 091 092 /** 093 * Closes the binary manager and releases all resources and temporary objects held by it. 094 */ 095 void close(); 096 097 /** 098 * Returns the digest algorithm used to store and digest binaries. 099 * 100 * @since 7.4 101 */ 102 String getDigestAlgorithm(); 103 104}