Class ResourceVariantByteStore

  • Direct Known Subclasses:
    PersistantResourceVariantByteStore, SessionResourceVariantByteStore

    public abstract class ResourceVariantByteStore
    extends Object
    The purpose of a ResourceVariantByteStore is to support the caching of the synchronization bytes for the resource variants that represent a resource line-up of interest such as a version, baseline or branch. The cache stores bytes in order to minimize the memory footprint of the tree. It is the responsibility of the client of this API to cache enough bytes to meaningfully identify a resource variant (and possibly create an IResourceVariant handle from them).

    The bytes for a resource variant are accessed using the local IResource handle that corresponds to the resource variant (using the getBytes method). The potential children of a resource variant are also accessed by using the local handle that corresponds to the resource variant (using the members method).

    Since:
    3.0
    • Constructor Detail

      • ResourceVariantByteStore

        public ResourceVariantByteStore()
    • Method Detail

      • dispose

        public abstract void dispose()
        Dispose of any cached sync bytes when this cache is no longer needed.
      • getBytes

        public abstract byte[] getBytes​(IResource resource)
                                 throws TeamException
        Return the bytes for the variant corresponding the given local resource. A return value of null means that no bytes have been stored for the resource variant. It is up to the client to determine whether this means that the resource variant does not exist or that it has not been fetched or otherwise determined yet.
        Parameters:
        resource - the local resource
        Returns:
        the bytes that represent the resource's variant
        Throws:
        TeamException
      • setBytes

        public abstract boolean setBytes​(IResource resource,
                                         byte[] bytes)
                                  throws TeamException
        Set the bytes for the variant corresponding the given local resource. The bytes should never be null. If it is known that the remote does not exist, deleteBytes(IResource) should be used instead. If the sync bytes for the remote are stale and should be removed, flushBytes(IResouce, int) should be called.
        Parameters:
        resource - the local resource
        bytes - the bytes that represent the resource's variant
        Returns:
        true if the bytes changed
        Throws:
        TeamException
      • flushBytes

        public abstract boolean flushBytes​(IResource resource,
                                           int depth)
                                    throws TeamException
        Remove the bytes from the tree for the resource variants corresponding to the given local resource and its descendants to the given depth. After the bytes are removed, getBytes(resource) will return null for the affected resources.
        Parameters:
        resource - the local resource
        depth - the depth of the operation (one of IResource.DEPTH_ZERO, IResource.DEPTH_ONE, or IResource.DEPTH_INFINITE)
        Returns:
        true if there were bytes present which were removed
        Throws:
        TeamException
      • deleteBytes

        public abstract boolean deleteBytes​(IResource resource)
                                     throws TeamException
        Method called to indicate that it is known that there is no variant associated with the local resource. Subclasses may handle this information in different ways. The flush(IResource, int) method should be used in the cases where a client wishes to remove bytes for other reason.
        Parameters:
        resource - the local resource
        Returns:
        true if this changes the bytes for the variant
        Throws:
        TeamException
      • members

        public abstract IResource[] members​(IResource resource)
                                     throws TeamException
        Return the children of the given resource that have resource variants in this tree.
        Parameters:
        resource - the parent resource
        Returns:
        the members who have resource variants in this tree.
        Throws:
        TeamException
      • equals

        protected boolean equals​(byte[] syncBytes1,
                                 byte[] syncBytes2)
        Helper method to compare two byte arrays for equality
        Parameters:
        syncBytes1 - the first byte array or null
        syncBytes2 - the second byte array or null
        Returns:
        whether the two arrays are equal (i.e. same content)
      • run

        public void run​(IResource root,
                        IWorkspaceRunnable runnable,
                        IProgressMonitor monitor)
                 throws TeamException
        Run the given action which may contain multiple modifications to the byte store. By default, the action is run. Subclasses may override to obtain scheduling rules or batch deltas (if the byte store modifies workspace resources).
        Parameters:
        root - the root resource for all modifications
        runnable - the action to perform
        monitor - a progress monitor.
        Throws:
        TeamException - if the operation failed.
        OperationCanceledException - if the operation is canceled.