This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.repository.storage;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.IOException;
023import java.io.InputStream;
024import java.io.OutputStream;
025import java.net.URI;
026import java.nio.channels.ReadableByteChannel;
027import java.nio.channels.WritableByteChannel;
028import java.nio.file.CopyOption;
029import java.util.function.Consumer;
030
031/**
032 *
033 * This is the low level API to access artifacts in a repository. Each artifact is represented
034 * by one storage asset. Each asset can be accessed by a path that is independent on the underlying storage
035 * implementation. Paths always use '/' as path separator. The path is local to the repository and
036 * is unique for each asset.
037 * The storage API knows nothing about the repository layout or repository specific metadata.
038 * If you use this API you must either have knowledge about the specific repository layout or use the structure
039 * as it is, e.g. for browsing.
040 *
041 * The base implementation for the storage uses a directory structure on the local filesystem.
042 *
043 *
044 * It is the decision of the repository type specific implementation, if this API provides access to all elements, that
045 * is really stored or just a selected view.
046 *
047 * Checking access is not part of this API.
048 */
049public interface RepositoryStorage {
050
051    /**
052     * Returns a URI representation of the storage location.
053     *
054     * @return The URI that is pointing to the storage.
055     */
056    URI getLocation();
057
058    /**
059     * Updates the base location of the repository storage. The method does not move any data.
060     * It just points to the new location. Artifacts may not be accessible anymore if the data has
061     * not been moved or copied. Assets retrieved before the relocation may still be pointing to the
062     * old location.
063     *
064     * @param newLocation The URI to the new location
065     *
066     * @throws IOException If the repository cannot be relocated
067     */
068    void updateLocation(URI newLocation) throws IOException;
069
070    /**
071     * Returns information about a specific storage asset.
072     * @param path
073     * @return
074     */
075    StorageAsset getAsset(String path);
076
077    /**
078     * Consumes the data and sets a lock for the file during the operation.
079     *
080     * @param asset The asset from which the data is consumed.
081     * @param consumerFunction The consumer that reads the data
082     * @param readLock If true, a read lock is acquired on the asset.
083     * @throws IOException
084     */
085    void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException;
086
087    /**
088     * Consumes the data and sets a lock for the file during the operation.
089     *
090     * @param asset The asset from which the data is consumed.
091     * @param consumerFunction The consumer that reads the data
092     * @param readLock If true, a read lock is acquired on the asset.
093     * @throws IOException
094     */
095    void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException;
096
097    /**
098     * Writes data to the asset using a write lock.
099     *
100     * @param asset The asset to which the data is written.
101     * @param consumerFunction The function that provides the data.
102     * @param writeLock If true, a write lock is acquired on the destination.
103     */
104    void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock) throws IOException;;
105
106    /**
107     * Writes data and sets a lock during the operation.
108     *
109     * @param asset The asset to which the data is written.
110     * @param consumerFunction The function that provides the data.
111     * @param writeLock If true, a write lock is acquired on the destination.
112     * @throws IOException
113     */
114    void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock) throws IOException;
115
116    /**
117     * Adds a new asset to the underlying storage.
118     * @param path The path to the asset.
119     * @param container True, if the asset should be a container, false, if it is a file.
120     * @return
121     */
122    StorageAsset addAsset(String path, boolean container);
123
124    /**
125     * Removes the given asset from the storage.
126     *
127     * @param asset
128     * @throws IOException
129     */
130    void removeAsset(StorageAsset asset) throws IOException;
131
132    /**
133     * Moves the asset to the given location and returns the asset object for the destination. Moves only assets that
134     * belong to the same storage instance. It will throw a IOException if the assets are from differents storage
135     * instances.
136     *
137     * @param origin The original asset
138     * @param destination The destination path pointing to the new asset.
139     * @param copyOptions The copy options.
140     * @return The asset representation of the moved object.
141     */
142    StorageAsset moveAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
143
144    /**
145     * Moves the asset to the given location and returns the asset object for the destination. Moves only assets that
146     * belong to the same storage instance. It will throw a IOException if the assets are from differents storage
147     * instances.
148     * *
149     * @param origin The original asset
150     * @param destination The destination path.
151     * @param copyOptions The copy options (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
152     * @throws IOException If it was not possible to copy the asset.
153     */
154    void moveAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
155
156    /**
157     * Copies the given asset to the new destination. Copies only assets that belong to the same storage instance.
158     * It will throw a IOException if the assets are from differents storage instances.
159     *
160     * @param origin The original asset
161     * @param destination The path to the new asset
162     * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
163     * @return The asset representation of the copied object
164     * @throws IOException If it was not possible to copy the asset
165     */
166    StorageAsset copyAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
167
168    /**
169     * Copies the given asset to the new destination. Copies only assets that belong to the same storage instance.
170     * It will throw a IOException if the assets are from differents storage instances.
171     *
172     * @param origin The original asset
173     * @param destination The path to the new asset
174     * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
175     * @throws IOException If it was not possible to copy the asset
176     */
177    void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
178
179
180}