Example #1
0
  private void performClose() {
    this.open = false;
    final FilesystemBlobStoreProcessor currentFilesystem = this.filesystem.getAndSet(null);

    if (currentFilesystem != null) {
      currentFilesystem.close();
    }
  }
Example #2
0
  /**
   * Store a blob in the blob store
   *
   * <p>The id function is being called with the exact of the blob as input and must return the ID
   * of the artifact in the database. The also requires that the artifact record is already
   * persisted into the database, without the blob attached.
   *
   * @param em the entity manager to use
   * @param in the input stream
   * @param idFunction the id function
   * @throws SQLException if a database error occurs
   * @throws IOException if an IO error occurs
   */
  public void storeBlob(
      final EntityManager em, final BufferedInputStream in, final Function<Long, String> idFunction)
      throws SQLException, IOException {
    checkOpen();

    final FilesystemBlobStoreProcessor currentFilesystem = this.filesystem.get();
    if (currentFilesystem != null) {
      currentFilesystem.storeBlob(in, idFunction);
    } else {
      this.database.storeBlob(em, in, idFunction);
    }
  }
Example #3
0
  /**
   * Clean up the BLOB of an already deleted artifact
   *
   * @param id
   */
  public void vacuumArtifact(final String id) throws IOException {
    logger.debug("Vacuuming artifact: {}", id);

    checkOpen();

    // there is no need to delete this at a database level, since the entity containing the BLOB is
    // already deleted

    final FilesystemBlobStoreProcessor currentFilesystem = this.filesystem.get();
    if (currentFilesystem != null) {
      currentFilesystem.deleteBlob(id);
    }
  }
Example #4
0
  public void setLocation(final File location) throws IOException {
    logger.info("Setting blob store location: {}", location);
    final FilesystemBlobStoreProcessor processor;

    processor = FilesystemBlobStoreProcessor.createOrLoad(location, this.coreService);

    final Map<String, String> properties = new HashMap<>(2);

    properties.put("blobStoreLocation", location.getAbsolutePath());
    properties.put("blobStoreId", processor.getStoreId());

    this.coreService.setCoreProperties("core", properties);

    final FilesystemBlobStoreProcessor old = this.filesystem.getAndSet(processor);

    if (old != null) {
      old.close();
    }
  }
Example #5
0
  public void streamArtifact(
      final EntityManager em,
      final ArtifactEntity artifact,
      final ThrowingConsumer<InputStream> consumer)
      throws IOException {
    checkOpen();

    final FilesystemBlobStoreProcessor currentFilesystem = this.filesystem.get();
    if (currentFilesystem != null) {
      if (currentFilesystem.streamArtifact(artifact.getId(), consumer)) {
        return;
      }
    }

    try {
      this.database.internalStreamArtifact(em, artifact, consumer);
    } catch (final SQLException e) {
      throw new IOException(e);
    }
  }