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     * @throws IOException
061     * @since 7.2
062     */
063    Binary getBinary(Blob blob) throws IOException;
064
065    /**
066     * Returns a {@link Binary} corresponding to the given digest.
067     * <p>
068     * A {@code null} is returned if the digest could not be found.
069     *
070     * @param digest the digest, or {@code null}
071     * @return the corresponding binary
072     */
073    Binary getBinary(String digest);
074
075    /**
076     * Remove definitively a set of binaries
077     *
078     * @since 7.10
079     * @param digests a set of digests, must not be {@code null}.
080     */
081    void removeBinaries(Collection<String> digests);
082
083    /**
084     * Returns the Binary Garbage Collector that can be used for this binary manager.
085     * <p>
086     * Several calls to this method will return the same GC, so that its status can be monitored using
087     * {@link BinaryGarbageCollector#isInProgress}.
088     *
089     * @return the binary GC
090     */
091    BinaryGarbageCollector getGarbageCollector();
092
093    /**
094     * Closes the binary manager and releases all resources and temporary objects held by it.
095     */
096    void close();
097
098    /**
099     * Returns the digest algorithm used to store and digest binaries.
100     *
101     * @since 7.4
102     */
103    String getDigestAlgorithm();
104
105}