Interface ContentRepository


public interface ContentRepository
Defines the capabilities of a content repository. Append options are not available on the methods but a merge capability is provided which between that and creating new claims a merge is available.
  • Method Details

    • initialize

      void initialize(ContentRepositoryContext context) throws IOException
      Initializes the Content Repository, providing to it the ContentRepositoryContext.
      Parameters:
      context - to initialize repository
      Throws:
      IOException - if unable to init
    • shutdown

      void shutdown()
      Shuts down the Content Repository, freeing any resources that may be held. This is called when an administrator shuts down NiFi.
    • getContainerNames

      Set<String> getContainerNames()
      Returns:
      the names of all Containers that exist for this Content Repository
    • getContainerCapacity

      long getContainerCapacity(String containerName) throws IOException
      Parameters:
      containerName - name of container to check capacity on
      Returns:
      the maximum number of bytes that can be stored in the storage mechanism that backs the container with the given name
      Throws:
      IOException - if unable to check capacity
      IllegalArgumentException - if no container exists with the given name
    • getContainerUsableSpace

      long getContainerUsableSpace(String containerName) throws IOException
      Parameters:
      containerName - to check space on
      Returns:
      the number of bytes available to be used used by the storage mechanism that backs the container with the given name
      Throws:
      IOException - if unable to check space
      IllegalArgumentException - if no container exists with the given name
    • getContainerFileStoreName

      String getContainerFileStoreName(String containerName)
      Returns the name of the FileStore that the given container is stored on, or null if not applicable or unable to determine the file store name
      Parameters:
      containerName - the name of the container
      Returns:
      the name of the FileStore
    • create

      ContentClaim create(boolean lossTolerant) throws IOException
      Creates a new content claim
      Parameters:
      lossTolerant - indicates whether the content for the new claim is loss tolerant. If true the repository might choose more volatile storage options which could increase performance for a tradeoff with reliability
      Returns:
      newly created claim
      Throws:
      IOException - if unable to create claim
    • incrementClaimaintCount

      int incrementClaimaintCount(ContentClaim claim)
      Increments the number of claimants for the given claim
      Parameters:
      claim - to increment
      Returns:
      the number of claimants after incrementing
    • getClaimantCount

      int getClaimantCount(ContentClaim claim)
      Obtains the current number of claimants for the given claim
      Parameters:
      claim - to get count of
      Returns:
      the number of claimants
    • decrementClaimantCount

      int decrementClaimantCount(ContentClaim claim)
      Reduces the number of claimants for the given claim. Even if the given claim is null or content cannot be found or removed no exception will be thrown.
      Parameters:
      claim - to decrement
      Returns:
      new claimant count for the given claim
    • remove

      boolean remove(ContentClaim claim)
      Removes the content indicated by the given claim
      Parameters:
      claim - to remove
      Returns:
      a boolean indicating whether or not the destruction of the claim was successful
    • clone

      ContentClaim clone(ContentClaim original, boolean lossTolerant) throws IOException
      Clones the content for the given content claim and returns content claim of the new object
      Parameters:
      original - to clone
      lossTolerant - if can be place in a loss tolerant repository
      Returns:
      new claim
      Throws:
      IOException - if an IO error occurs. Any content written to the new destination prior to the error will be destroyed
    • importFrom

      long importFrom(Path content, ContentClaim claim) throws IOException
      Imports content from the given path creating a new content object and claim within the repository.
      Parameters:
      content - to import from
      claim - the claim to write imported content to
      Returns:
      the size of the claim
      Throws:
      IOException - if failure to read given content
    • importFrom

      long importFrom(InputStream content, ContentClaim claim) throws IOException
      Imports content from the given stream creating a new content object and claim within the repository.
      Parameters:
      content - to import from
      claim - the claim to write imported content to
      Returns:
      the size of the claim
      Throws:
      IOException - if unable to read content
    • exportTo

      long exportTo(ContentClaim claim, Path destination, boolean append) throws IOException
      Exports the content of the given claim to the given destination.
      Parameters:
      claim - to export from
      destination - where to export data
      append - if true appends to the destination; false overwrites
      Returns:
      the size of the destination or the claim
      Throws:
      IOException - if an IO error occurs. The state of the content for the given destination is unknown and callers should consider whether they should clean up any partially created paths
    • exportTo

      long exportTo(ContentClaim claim, Path destination, boolean append, long offset, long length) throws IOException
      Exports the content of the given claim to the given destination.
      Parameters:
      claim - to export from
      destination - where to export data
      append - if true appends to the destination; false overwrites
      offset - the offset at which the claim should start being copied
      length - the number of bytes to copy
      Returns:
      the size of the destination or the claim
      Throws:
      IOException - if an IO error occurs. The state of the content for the given destination is unknown and callers should consider whether they should clean up any partially created paths
    • exportTo

      long exportTo(ContentClaim claim, OutputStream destination) throws IOException
      Exports the content of the given claim to the given destination.
      Parameters:
      claim - to export from
      destination - where to export data
      Returns:
      the size of the claim
      Throws:
      IOException - if an IO error occurs.
    • exportTo

      long exportTo(ContentClaim claim, OutputStream destination, long offset, long length) throws IOException
      Exports a subset of the content of the given claim, starting at offset and copying length bytes, to the given destination.
      Parameters:
      claim - to export from
      destination - where to export data
      offset - the offset into the claim at which the copy should begin
      length - the number of bytes to copy
      Returns:
      the number of bytes copied
      Throws:
      IOException - if an IO error occurs.
    • size

      long size(ContentClaim claim) throws IOException
      Parameters:
      claim - to get size of
      Returns:
      size in bytes of content for given claim
      Throws:
      IOException - if size check failed
    • size

      long size(ResourceClaim claim) throws IOException
      Parameters:
      claim - to get size of
      Returns:
      size in bytes of the file/object backing the given resource claim, or 0 if this operation is not supported by the implementation
      Throws:
      IOException - if size check failed
    • read

      InputStream read(ContentClaim claim) throws IOException
      Provides access to the input stream for the given claim
      Parameters:
      claim - to read from
      Returns:
      InputStream over the content of the given claim
      Throws:
      IOException - if unable to read
    • read

      Provides access ot the input stream for the entire Resource Claim
      Parameters:
      claim - the resource claim to read from
      Returns:
      InputStream over the content of the entire Resource Claim
      Throws:
      IOException - if unable to read
    • isResourceClaimStreamSupported

      default boolean isResourceClaimStreamSupported()
      Indicates whether or not this Content Repository supports obtaining an InputStream for an entire Resource Claim. If this method returns false, the read(ResourceClaim) should not be called and instead read(ContentClaim) should always be used
      Returns:
      true if reading an entire Resource Claim is allowed, false otherwise
    • write

      OutputStream write(ContentClaim claim) throws IOException
      Obtains an OutputStream to the content for the given claim.
      Parameters:
      claim - to write to
      Returns:
      the stream to write to
      Throws:
      IOException - if unable to obtain stream
    • purge

      void purge()
      Purges the contents of the repository, as if the repository were newly created.
    • cleanup

      void cleanup()
      Performs any cleanup actions that may need to be taken upon system restart. For example, if content was partially written to the repository before the restart, the repository is given a chance to handle this data
    • isAccessible

      boolean isAccessible(ContentClaim contentClaim) throws IOException
      Parameters:
      contentClaim - the Content Claim to check
      Returns:
      Returns a boolean indicating whether or not the content specified by the given claim can be read, regardless of whether the content has been archived or not. If the ContentRepository does not implement archiving capabilities, this method will return false
      Throws:
      IOException - if unable to determine accessibility
    • getActiveResourceClaims

      default Set<ResourceClaim> getActiveResourceClaims(String containerName) throws IOException
      Optional operation that returns a List of all Resource Claims that exist in the given Container that are considered "active" (i.e., not archived)
      Parameters:
      containerName - the name of the container
      Returns:
      a List of all Resource Claims that exist in the given Container
      Throws:
      IOException - if unable to obtain a listing due to an IO failure
      UnsupportedOperationException - if this repository does not implement this capability.
      See Also:
    • isActiveResourceClaimsSupported

      default boolean isActiveResourceClaimsSupported()
      Indicates whether or not the repository supports obtaining a list of active Resource Claims via the getActiveResourceClaims(String) method
      Returns:
      true if the operation is supported, false otherwise