1 package org.apache.archiva.repository.storage;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.net.URI;
26 import java.nio.channels.ReadableByteChannel;
27 import java.nio.channels.WritableByteChannel;
28 import java.nio.file.CopyOption;
29 import java.util.function.Consumer;
30
31 /**
32 *
33 * This is the low level API to access artifacts in a repository. Each artifact is represented
34 * by one storage asset. Each asset can be accessed by a path that is independent on the underlying storage
35 * implementation. Paths always use '/' as path separator. The path is local to the repository and
36 * is unique for each asset.
37 * The storage API knows nothing about the repository layout or repository specific metadata.
38 * If you use this API you must either have knowledge about the specific repository layout or use the structure
39 * as it is, e.g. for browsing.
40 *
41 * The base implementation for the storage uses a directory structure on the local filesystem.
42 *
43 *
44 * It is the decision of the repository type specific implementation, if this API provides access to all elements, that
45 * is really stored or just a selected view.
46 *
47 * Checking access is not part of this API.
48 */
49 public interface RepositoryStorage {
50
51 /**
52 * Returns a URI representation of the storage location.
53 *
54 * @return The URI that is pointing to the storage.
55 */
56 URI getLocation();
57
58 /**
59 * Updates the base location of the repository storage. The method does not move any data.
60 * It just points to the new location. Artifacts may not be accessible anymore if the data has
61 * not been moved or copied. Assets retrieved before the relocation may still be pointing to the
62 * old location.
63 *
64 * @param newLocation The URI to the new location
65 *
66 * @throws IOException If the repository cannot be relocated
67 */
68 void updateLocation(URI newLocation) throws IOException;
69
70 /**
71 * Returns information about a specific storage asset.
72 * @param path
73 * @return
74 */
75 StorageAsset getAsset(String path);
76
77 /**
78 * Consumes the data and sets a lock for the file during the operation.
79 *
80 * @param asset The asset from which the data is consumed.
81 * @param consumerFunction The consumer that reads the data
82 * @param readLock If true, a read lock is acquired on the asset.
83 * @throws IOException
84 */
85 void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException;
86
87 /**
88 * Consumes the data and sets a lock for the file during the operation.
89 *
90 * @param asset The asset from which the data is consumed.
91 * @param consumerFunction The consumer that reads the data
92 * @param readLock If true, a read lock is acquired on the asset.
93 * @throws IOException
94 */
95 void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException;
96
97 /**
98 * Writes data to the asset using a write lock.
99 *
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../../../org/apache/archiva/repository/storage/StorageAsset.html#StorageAsset">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./../../../org/apache/archiva/repository/storage/StorageAsset.html#StorageAsset">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../../../org/apache/archiva/repository/storage/StorageAsset.html#StorageAsset">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./../../../org/apache/archiva/repository/storage/StorageAsset.html#StorageAsset">StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
178
179
180 }