You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryStorage.java 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package org.apache.archiva.repository.storage;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.io.OutputStream;
  23. import java.net.URI;
  24. import java.nio.channels.ReadableByteChannel;
  25. import java.nio.channels.WritableByteChannel;
  26. import java.nio.file.CopyOption;
  27. import java.util.function.Consumer;
  28. /**
  29. *
  30. * This is the low level API to access artifacts in a repository. Each artifact is represented
  31. * by one storage asset. Each asset can be accessed by a path that is independent on the underlying storage
  32. * implementation. Paths always use '/' as path separator. The path is local to the repository and
  33. * is unique for each asset.
  34. * The storage API knows nothing about the repository layout or repository specific metadata.
  35. * If you use this API you must either have knowledge about the specific repository layout or use the structure
  36. * as it is, e.g. for browsing.
  37. *
  38. * The base implementation for the storage uses a directory structure on the local filesystem.
  39. *
  40. *
  41. * It is the decision of the repository type specific implementation, if this API provides access to all elements, that
  42. * is really stored or just a selected view.
  43. *
  44. * Checking access is not part of this API.
  45. */
  46. public interface RepositoryStorage {
  47. /**
  48. * Returns a URI representation of the storage location.
  49. *
  50. * @return The URI that is pointing to the storage.
  51. */
  52. URI getLocation();
  53. /**
  54. * Updates the base location of the repository storage. The method does not move any data.
  55. * It just points to the new location. Artifacts may not be accessible anymore if the data has
  56. * not been moved or copied. Assets retrieved before the relocation may still be pointing to the
  57. * old location.
  58. *
  59. * @param newLocation The URI to the new location
  60. *
  61. * @throws IOException If the repository cannot be relocated
  62. */
  63. void updateLocation(URI newLocation) throws IOException;
  64. /**
  65. * Returns information about a specific storage asset.
  66. * @param path
  67. * @return
  68. */
  69. StorageAsset getAsset(String path);
  70. /**
  71. * Consumes the data and sets a lock for the file during the operation.
  72. *
  73. * @param asset The asset from which the data is consumed.
  74. * @param consumerFunction The consumer that reads the data
  75. * @param readLock If true, a read lock is acquired on the asset.
  76. * @throws IOException
  77. */
  78. void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException;
  79. /**
  80. * Consumes the data and sets a lock for the file during the operation.
  81. *
  82. * @param asset The asset from which the data is consumed.
  83. * @param consumerFunction The consumer that reads the data
  84. * @param readLock If true, a read lock is acquired on the asset.
  85. * @throws IOException
  86. */
  87. void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException;
  88. /**
  89. * Writes data to the asset using a write lock.
  90. *
  91. * @param asset The asset to which the data is written.
  92. * @param consumerFunction The function that provides the data.
  93. * @param writeLock If true, a write lock is acquired on the destination.
  94. */
  95. void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock) throws IOException;;
  96. /**
  97. * Writes data and sets a lock during the operation.
  98. *
  99. * @param asset The asset to which the data is written.
  100. * @param consumerFunction The function that provides the data.
  101. * @param writeLock If true, a write lock is acquired on the destination.
  102. * @throws IOException
  103. */
  104. void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock) throws IOException;
  105. /**
  106. * Adds a new asset to the underlying storage.
  107. * @param path The path to the asset.
  108. * @param container True, if the asset should be a container, false, if it is a file.
  109. * @return
  110. */
  111. StorageAsset addAsset(String path, boolean container);
  112. /**
  113. * Removes the given asset from the storage.
  114. *
  115. * @param asset
  116. * @throws IOException
  117. */
  118. void removeAsset(StorageAsset asset) throws IOException;
  119. /**
  120. * Moves the asset to the given location and returns the asset object for the destination. Moves only assets that
  121. * belong to the same storage instance. It will throw a IOException if the assets are from differents storage
  122. * instances.
  123. *
  124. * @param origin The original asset
  125. * @param destination The destination path pointing to the new asset.
  126. * @param copyOptions The copy options.
  127. * @return The asset representation of the moved object.
  128. */
  129. StorageAsset moveAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
  130. /**
  131. * Moves the asset to the given location and returns the asset object for the destination. Moves only assets that
  132. * belong to the same storage instance. It will throw a IOException if the assets are from differents storage
  133. * instances.
  134. * *
  135. * @param origin The original asset
  136. * @param destination The destination path.
  137. * @param copyOptions The copy options (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
  138. * @throws IOException If it was not possible to copy the asset.
  139. */
  140. void moveAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
  141. /**
  142. * Copies the given asset to the new destination. Copies only assets that belong to the same storage instance.
  143. * It will throw a IOException if the assets are from differents storage instances.
  144. *
  145. * @param origin The original asset
  146. * @param destination The path to the new asset
  147. * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
  148. * @return The asset representation of the copied object
  149. * @throws IOException If it was not possible to copy the asset
  150. */
  151. StorageAsset copyAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException;
  152. /**
  153. * Copies the given asset to the new destination. Copies only assets that belong to the same storage instance.
  154. * It will throw a IOException if the assets are from differents storage instances.
  155. *
  156. * @param origin The original asset
  157. * @param destination The path to the new asset
  158. * @param copyOptions The copy options, e.g. (e.g. {@link java.nio.file.StandardCopyOption#REPLACE_EXISTING}
  159. * @throws IOException If it was not possible to copy the asset
  160. */
  161. void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException;
  162. }