Class CompositeNodeStore

  • All Implemented Interfaces:
    Observable, NodeStore, PrefetchNodeStore

    public class CompositeNodeStore
    extends Object
    implements NodeStore, PrefetchNodeStore, Observable
    A NodeStore implementation that combines other NodeStore instances mounted under paths defined by Mount.

    The main objective of this implementation is to proxy operations working on at most single read-write store with any number of read-only stores. While the composition would technically work at the NodeStore level there are several less-than-obvious issues which prevent it:

    1. Thread safety of the write operation can be quite costly, and will come on top of the thread safety measures already put in place by the composite node stores.
    2. Many JCR subsystems require global state, e.g. the versioning store. This global state can become corrupt if multiple mounts operate on it or if mounts are added and removed.

    As such, the only supported configuration is at most a single write-enabled store.

    Because of the limitation described above, right now the only correct way to use CompositeNodeStore is to create a normal repository, split it into parts using oak-upgrade --{include,exclude}-paths and then configure this node store implementation to composite split parts together.

    • Method Detail

      • getRoot

        public NodeState getRoot()
        Description copied from interface: NodeStore
        Returns the latest state of the tree.
        Specified by:
        getRoot in interface NodeStore
        Returns:
        root node state
      • merge

        public NodeState merge​(NodeBuilder builder,
                               CommitHook commitHook,
                               CommitInfo info)
                        throws CommitFailedException
        Description copied from interface: NodeStore
        Merges the changes between the base and head states of the given builder to this store.
        Specified by:
        merge in interface NodeStore
        Parameters:
        builder - the builder whose changes to apply
        commitHook - the commit hook to apply while merging changes
        info - commit info associated with this merge operation
        Returns:
        the node state resulting from the merge.
        Throws:
        CommitFailedException - if the merge failed
      • rebase

        public NodeState rebase​(NodeBuilder builder)
        Description copied from interface: NodeStore
        Rebases the changes between the base and head states of the given builder on top of the current root state. The base state of the given builder becomes the latest root state of the repository, and the head state will contain the rebased changes.
        Specified by:
        rebase in interface NodeStore
        Parameters:
        builder - the builder to rebase
        Returns:
        the node state resulting from the rebase.
      • reset

        public NodeState reset​(NodeBuilder builder)
        Description copied from interface: NodeStore
        Reset the passed builder by throwing away all its changes and setting its base state to the current root state.
        Specified by:
        reset in interface NodeStore
        Parameters:
        builder - the builder to reset
        Returns:
        the node state resulting from the reset.
      • createBlob

        public Blob createBlob​(InputStream inputStream)
                        throws IOException
        Description copied from interface: NodeStore
        Create a Blob from the given input stream. The input stream is closed after this method returns.
        Specified by:
        createBlob in interface NodeStore
        Parameters:
        inputStream - The input stream for the Blob
        Returns:
        The Blob representing inputStream
        Throws:
        IOException - If an error occurs while reading from the stream
      • getBlob

        public Blob getBlob​(String reference)
        Description copied from interface: NodeStore
        Get a blob by its reference.
        Specified by:
        getBlob in interface NodeStore
        Parameters:
        reference - reference to the blob
        Returns:
        blob or null if the reference does not resolve to a blob.
        See Also:
        Blob.getReference()
      • checkpoints

        public Iterable<String> checkpoints()
        Description copied from interface: NodeStore
        Returns all valid checkpoints. The returned Iterable provides a snapshot of valid checkpoints at the time this method is called. That is, the Iterable will not reflect checkpoints created after this method was called.

        See NodeStore.checkpoint(long, Map) for a definition of a valid checkpoint.

        Specified by:
        checkpoints in interface NodeStore
        Returns:
        valid checkpoints.
      • checkpoint

        public String checkpoint​(long lifetime,
                                 Map<String,​String> properties)
        Description copied from interface: NodeStore
        Creates a new checkpoint of the latest root of the tree. The checkpoint remains valid for at least as long as requested and allows that state of the repository to be retrieved using the returned opaque string reference.

        The properties passed to this methods are associated with the checkpoint and can be retrieved through the NodeStore.checkpointInfo(String) method. Its semantics is entirely application specific.

        Specified by:
        checkpoint in interface NodeStore
        Parameters:
        lifetime - time (in milliseconds, > 0) that the checkpoint should remain available
        properties - properties to associate with the checkpoint
        Returns:
        string reference of this checkpoint
      • checkpoint

        public String checkpoint​(long lifetime)
        Description copied from interface: NodeStore
        Creates a new checkpoint of the latest root of the tree. The checkpoint remains valid for at least as long as requested and allows that state of the repository to be retrieved using the returned opaque string reference.

        This method is a shortcut for NodeStore.checkpoint(long, Map) passing an empty map for its 2nd argument.

        Specified by:
        checkpoint in interface NodeStore
        Parameters:
        lifetime - time (in milliseconds, > 0) that the checkpoint should remain available
        Returns:
        string reference of this checkpoint
      • checkpointInfo

        public Map<String,​String> checkpointInfo​(String checkpoint)
        Description copied from interface: NodeStore
        Retrieve the properties associated with a checkpoint.
        Specified by:
        checkpointInfo in interface NodeStore
        Parameters:
        checkpoint - string reference of a checkpoint
        Returns:
        the properties associated with the checkpoint referenced by checkpoint or an empty map when there is no such checkpoint.
      • retrieve

        public NodeState retrieve​(String checkpoint)
        Description copied from interface: NodeStore
        Retrieves the root node from a previously created repository checkpoint.
        Specified by:
        retrieve in interface NodeStore
        Parameters:
        checkpoint - string reference of a checkpoint
        Returns:
        the root node of the checkpoint, or null if the checkpoint is no longer available
      • release

        public boolean release​(String checkpoint)
        Description copied from interface: NodeStore
        Releases the provided checkpoint. If the provided checkpoint doesn't exist this method should return true.
        Specified by:
        release in interface NodeStore
        Parameters:
        checkpoint - string reference of a checkpoint
        Returns:
        true if the checkpoint was successfully removed, or if it doesn't exist
      • addObserver

        public Closeable addObserver​(Observer observer)
        Description copied from interface: Observable
        Register a new Observer. Clients need to call Closeable.close() to stop getting notifications on the registered observer and to free up any resources associated with the registration.
        Specified by:
        addObserver in interface Observable
        Returns:
        a Closeable instance.
      • prefetch

        public void prefetch​(Collection<String> paths,
                             NodeState rootState)
        Description copied from interface: PrefetchNodeStore
        Make an attempt to prefetch node states for the given paths and hold them in a cache.
        Specified by:
        prefetch in interface PrefetchNodeStore
        Parameters:
        paths - the paths of the node states to prefetch.
        rootState - the current root node state.