Class MemoryNodeStore

  • All Implemented Interfaces:
    Observable, NodeStore

    public class MemoryNodeStore
    extends java.lang.Object
    implements NodeStore, Observable
    Basic in-memory node store implementation. Useful as a base class for more complex functionality.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.Closeable addObserver​(Observer observer)
      Register a new Observer.
      @NotNull java.lang.String checkpoint​(long lifetime)
      Creates a new checkpoint of the latest root of the tree.
      @NotNull java.lang.String checkpoint​(long lifetime, @NotNull java.util.Map<java.lang.String,​java.lang.String> properties)
      Creates a new checkpoint of the latest root of the tree.
      @NotNull java.util.Map<java.lang.String,​java.lang.String> checkpointInfo​(@NotNull java.lang.String checkpoint)
      Retrieve the properties associated with a checkpoint.
      @NotNull java.lang.Iterable<java.lang.String> checkpoints()
      Returns all valid checkpoints.
      ArrayBasedBlob createBlob​(java.io.InputStream inputStream)
      Create a Blob from the given input stream.
      Blob getBlob​(@NotNull java.lang.String reference)
      Get a blob by its reference.
      NodeState getRoot()
      Returns the latest state of the tree.
      java.util.Set<java.lang.String> listCheckpoints()
      test purpose only!
      NodeState merge​(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info)
      This implementation is equal to first rebasing the builder and then applying it to a new branch and immediately merging it back.
      NodeState rebase​(@NotNull NodeBuilder builder)
      This implementation is equal to applying the differences between the builders base state and its head state to a fresh builder on the stores root state using ConflictAnnotatingRebaseDiff for resolving conflicts.
      boolean release​(java.lang.String checkpoint)
      Releases the provided checkpoint.
      NodeState reset​(@NotNull NodeBuilder builder)
      This implementation is equal resetting the builder to the root of the store and returning the resulting node state from the builder.
      @Nullable NodeState retrieve​(@NotNull java.lang.String checkpoint)
      Retrieves the root node from a previously created repository checkpoint.
      java.lang.String toString()
      Returns a string representation the head state of this node store.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MemoryNodeStore

        public MemoryNodeStore​(NodeState state)
      • MemoryNodeStore

        public MemoryNodeStore()
    • Method Detail

      • toString

        public java.lang.String toString()
        Returns a string representation the head state of this node store.
        Overrides:
        toString in class java.lang.Object
      • addObserver

        public java.io.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.
      • 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​(@NotNull
                               @NotNull NodeBuilder builder,
                               @NotNull
                               @NotNull CommitHook commitHook,
                               @NotNull
                               @NotNull CommitInfo info)
                        throws CommitFailedException
        This implementation is equal to first rebasing the builder and then applying it to a new branch and immediately merging it back.
        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
        java.lang.IllegalArgumentException - if the builder is not acquired from a root state of this store
      • rebase

        public NodeState rebase​(@NotNull
                                @NotNull NodeBuilder builder)
        This implementation is equal to applying the differences between the builders base state and its head state to a fresh builder on the stores root state using ConflictAnnotatingRebaseDiff for resolving conflicts.
        Specified by:
        rebase in interface NodeStore
        Parameters:
        builder - the builder to rebase
        Returns:
        the node state resulting from the rebase.
        Throws:
        java.lang.IllegalArgumentException - if the builder is not acquired from a root state of this store
      • reset

        public NodeState reset​(@NotNull
                               @NotNull NodeBuilder builder)
        This implementation is equal resetting the builder to the root of the store and returning the resulting node state from the builder.
        Specified by:
        reset in interface NodeStore
        Parameters:
        builder - the builder to reset
        Returns:
        the node state resulting from the reset.
        Throws:
        java.lang.IllegalArgumentException - if the builder is not acquired from a root state of this store
      • createBlob

        public ArrayBasedBlob createBlob​(java.io.InputStream inputStream)
                                  throws java.io.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:
        An instance of ArrayBasedBlob.
        Throws:
        java.io.IOException - If an error occurs while reading from the stream
      • getBlob

        public Blob getBlob​(@NotNull
                            @NotNull java.lang.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()
      • checkpoint

        @NotNull
        public @NotNull java.lang.String checkpoint​(long lifetime,
                                                    @NotNull
                                                    @NotNull java.util.Map<java.lang.String,​java.lang.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

        @NotNull
        public @NotNull java.lang.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

        @NotNull
        public @NotNull java.util.Map<java.lang.String,​java.lang.String> checkpointInfo​(@NotNull
                                                                                              @NotNull java.lang.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.
      • checkpoints

        @NotNull
        public @NotNull java.lang.Iterable<java.lang.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.
      • retrieve

        @Nullable
        public @Nullable NodeState retrieve​(@NotNull
                                            @NotNull java.lang.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​(java.lang.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
      • listCheckpoints

        public java.util.Set<java.lang.String> listCheckpoints()
        test purpose only!