Class CachedResourceVariant
- All Implemented Interfaces:
IAdaptable
,IResourceVariant
Overriding subclasses need to provide a cache Id for all their resource variants
and a cache path for each resource variant that uniquely identifies it. In addition,
they must implement fetchContents
to retrieve the contents of the
resource variant and then call setContents
to place these contents in the cache.
Subclasses may also call cacheHandle
in order to place the handle in the
cache so that it can be retrieved later by calling getCachedHandle
on any
resource variant whose cache path is the same as the cached handle. This allows subclasses to
cache additional resource variant properties such as author, comment, etc.
The IStorage
instance returned by this class will be
an IEncodedStorage
.
The cache in which the resource variants reside will occasionally clear cached entries if they have not been accessed for a certain amount of time.
- Since:
- 3.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Cache this handle in the cache, replacing any previously cached handle.protected abstract void
fetchContents
(IProgressMonitor monitor) Method that is invoked when the contents of the resource variant need to be fetched.protected InputStream
Return the cached contents for this resource variant ornull
if the contents have not been cached.protected CachedResourceVariant
Return the cached handle for this resource variant if there is one.protected abstract String
Return the ID that uniquely identifies the cache in which this resource variant is to be cache.protected abstract String
Get the path that uniquely identifies the remote resource variant.Return the full path of this resource that should be displayed to the user.long
getSize()
Return the size (in bytes) of the contents of this resource variant.getStorage
(IProgressMonitor monitor) Return an instance of IStorage ornull
if the remote resource does not have contents (i.e. is a folder).boolean
Return whether there are already contents cached for this resource variant.protected boolean
Returntrue
if the cache contains an entry for this resource variant.protected void
setContents
(InputStream stream, IProgressMonitor monitor) This method should be invoked by subclasses from within theirfetchContents
method in order to cache the contents for this resource variant.Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.team.core.variants.IResourceVariant
asBytes, equals, getContentIdentifier, getName, isContainer
-
Constructor Details
-
CachedResourceVariant
public CachedResourceVariant()
-
-
Method Details
-
getStorage
Description copied from interface:IResourceVariant
Return an instance of IStorage ornull
if the remote resource does not have contents (i.e. is a folder). Since theISorage#getContents()
method does not accept anIProgressMonitor
, this method must ensure that the contents access by the resultingIStorage
is cached locally (hence theIProgressMonitor
argument to this method). Implementations of this method should ensure that the resultingIStorage
is accessing locally cached contents and is not contacting the server.The returned storage object may be an instance of (@link org.eclipse.core.resources.IEncodedStorage} in which case clients can determine the character encoding of the contents.
- Specified by:
getStorage
in interfaceIResourceVariant
- Parameters:
monitor
- a progress monitor- Returns:
- an
IStorage
that provides access to the contents of the remote resource ornull
if the remote resource is a container. - Throws:
TeamException
- if an error occurs
-
fetchContents
Method that is invoked when the contents of the resource variant need to be fetched. This method will only be invoked for files (i.e.isContainer()
returnsfalse
. Subclasses should override this method and invokesetContents
with a stream containing the fetched contents.- Parameters:
monitor
- a progress monitor- Throws:
TeamException
-
setContents
This method should be invoked by subclasses from within theirfetchContents
method in order to cache the contents for this resource variant.This method is not intended to be overridden by clients.
- Parameters:
stream
- the stream containing the contents of the resource variantmonitor
- a progress monitor- Throws:
TeamException
- if an error occurs
-
isContentsCached
public boolean isContentsCached()Return whether there are already contents cached for this resource variant. This method will returnfalse
even if the contents are currently being cached by another thread. The consequence of this is that the contents may be fetched twice in the rare case where two threads request the same contents concurrently. For containers, this method will always returnfalse
.This method is not intended to be overridden by clients.
- Returns:
- whether there are contents cached for this resource variant
-
getCachedContents
Return the cached contents for this resource variant ornull
if the contents have not been cached. For containers, this method will always returnnull
.This method is not intended to be overridden by clients.
- Returns:
- the cached contents or
null
- Throws:
TeamException
- if an error occurs
-
isHandleCached
protected boolean isHandleCached()Returntrue
if the cache contains an entry for this resource variant. It is possible that another instance of this variant is cached. To get the cached instance, callgetCachedHandle()
. Note that cached contents can be retrieved from any handle to a resource variant whose cache path (as returned bygetCachePath()
) match but other state information may only be accessible from the cached copy.- Returns:
- whether the variant is cached
- Restriction:
- This method is not intended to be overridden by clients.
-
getCachePath
Get the path that uniquely identifies the remote resource variant. This path describes the remote location where the remote resource is stored and also uniquely identifies each resource variant. It is used to uniquely identify this resource variant when it is stored in the resource variant cache. This path is also returned as the full path of theIStorage
returned from this variant so the path could be converted to anIPath
and displayed to the user.- Returns:
- the full path of the remote resource variant
-
getSize
public long getSize()Return the size (in bytes) of the contents of this resource variant. The method will return 0 if the contents have not yet been cached locally. For containers, this method will always return 0.- Returns:
- the size (in bytes) of the contents of this resource variant
-
getCacheId
Return the ID that uniquely identifies the cache in which this resource variant is to be cache. The ID of the plugin that provides the resource variant subclass is a good candidate for this ID. The creation, management and disposal of the cache is managed by Team.- Returns:
- the cache ID
-
getCachedHandle
Return the cached handle for this resource variant if there is one. If there isn't one, thennull
is returned. If there is no cached handle and one is desired, thencacheHandle()
should be called.- Returns:
- a cached copy of this resource variant or
null
- Restriction:
- This method is not intended to be overridden by clients.
-
cacheHandle
protected void cacheHandle()Cache this handle in the cache, replacing any previously cached handle. Note that caching this handle will replace any state associated with a previously cached handle, if there is one, but the contents will remain. The reason for this is the assumption that the cache path for a resource variant (as returned bygetCachePath()
identifies an immutable resource version (or revision). The ability to replace the handle itself is provided so that additional state may be cached before or after the contents are fetched.- Restriction:
- This method is not intended to be overridden by clients.
-
getDisplayPath
Return the full path of this resource that should be displayed to the user. This path is also used as the path of theIStorage
that is returned by this instance. Subclasses may override.- Returns:
- the full path of this resource that should be displayed to the user
- Since:
- 3.1
-