Class ResourceCache

java.lang.Object
edu.rit.pj.cluster.ResourceCache

public class ResourceCache extends Object
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

    Constructors
    Constructor
    Description
    Construct a new resource cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Determine if this resource cache contains resource information for the given resource name.
    boolean
    Determine if this resource cache contains the resource content for the given resource name.
    byte[]
    get(String name)
    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
    put(String name, byte[] content)
    Store the given resource content under the given resource name in this resource cache.
    void
    remove(String name)
    Remove the resource content for the given resource name from this resource cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ResourceCache

      public ResourceCache()
      Construct a new resource cache.
  • Method Details

    • contains

      public boolean contains(String name)
      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

      public boolean containsContent(String name)
      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

      public byte[] get(String name) throws InterruptedException
      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 for name 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

      public byte[] getNoWait(String name)
      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

      public void put(String name, byte[] content)
      Store the given resource content under the given resource name in this resource cache. Any existing content for name is overwritten.

      Note: The resource cache assumes that the contents of content are not changed after put() is called.

      Parameters:
      name - Resource name.
      content - Resource content, or null if not found.
    • remove

      public void remove(String name)
      Remove the resource content for the given resource name from this resource cache. If there is no content for name, the remove() method does nothing.
      Parameters:
      name - Resource name.