Package edu.rit.pj.cluster
Class ResourceCache
java.lang.Object
edu.rit.pj.cluster.ResourceCache
Class ResourceCache provides a cache of resources, indexed by resource name.
A resource is a piece of content (sequence of bytes) obtained from a class
loader.
Note: Class ResourceCache is multiple thread safe.
- Version:
- 26-Oct-2006
- Author:
- Alan Kaminsky
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine if this resource cache contains resource information for the given resource name.boolean
containsContent
(String name) Determine if this resource cache contains the resource content for the given resource name.byte[]
Obtain the resource content for the given resource name from this resource cache (blocking).byte[]
Obtain the resource content for the given resource name from this resource cache (non-blocking).void
Store the given resource content under the given resource name in this resource cache.void
Remove the resource content for the given resource name from this resource cache.
-
Constructor Details
-
ResourceCache
public ResourceCache()Construct a new resource cache.
-
-
Method Details
-
contains
Determine if this resource cache contains resource information for the given resource name. If the answer is yes, the resource content may or may not have been found.- Parameters:
name
- Resource name.- Returns:
- True if this resource cache contains resource information for
name
, false otherwise.
-
containsContent
Determine if this resource cache contains the resource content for the given resource name. If the answer is yes, the resource content was found, otherwise the resource content was not found or no resource information is available.- Parameters:
name
- Resource name.- Returns:
- True if this resource cache contains the resource content for
name
, false otherwise.
-
get
Obtain the resource content for the given resource name from this resource cache (blocking). This method will block if necessary until this resource cache contains the content forname
or until this resource cache knows the content was not found.- Parameters:
name
- Resource name.- Returns:
- Resource content, or null if not found.
- Throws:
InterruptedException
- Thrown if the calling thread is interrupted while blocked in this method.InterruptedException
- if any.
-
getNoWait
Obtain the resource content for the given resource name from this resource cache (non-blocking). This method will return null if the resource content was not found or no resource information is available.- Parameters:
name
- Resource name.- Returns:
- Resource content, or null if not found or no information is available.
-
put
Store the given resource content under the given resource name in this resource cache. Any existing content forname
is overwritten.Note: The resource cache assumes that the contents of
content
are not changed afterput()
is called.- Parameters:
name
- Resource name.content
- Resource content, or null if not found.
-
remove
Remove the resource content for the given resource name from this resource cache. If there is no content forname
, theremove()
method does nothing.- Parameters:
name
- Resource name.
-