org.enhydra.shark.caching
Class LRUResourceCache

java.lang.Object
  extended by org.enhydra.shark.caching.LRUResourceCache
All Implemented Interfaces:
ObjectCache, ResourceCache

public class LRUResourceCache
extends java.lang.Object
implements ResourceCache

This class is LRU (least recently used mechanism) cache for storing resources.

Author:
Vladimir Puskas, Tanja Jovanovic

Field Summary
protected  org.enhydra.shark.utilities.LRUMap cache
          LRU resource cache.
 
Constructor Summary
LRUResourceCache()
           
 
Method Summary
 void add(java.lang.String username, WfResourceInternal res)
          Adds resource to the resource cache.
 void configure(CallbackUtilities cus)
          Configures resource cache.
 WfResourceInternal get(java.lang.String username)
          Returns the resource from the resource cache with username username.
 java.util.List getAll()
          Returns all resources from the resource cache.
 int getSize()
          Returns the size of the resource cache.
 int howManyEntries()
           
 void remove(java.lang.String username)
          Removes resource from the resource cache.
 void setSize(int size)
          Sets size of the resource cache to value size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected org.enhydra.shark.utilities.LRUMap cache
LRU resource cache.

Constructor Detail

LRUResourceCache

public LRUResourceCache()
Method Detail

configure

public void configure(CallbackUtilities cus)
               throws java.lang.Exception
Configures resource cache.

Specified by:
configure in interface ObjectCache
Parameters:
cus - an instance of CallbackUtilities used to get properties for configuring resource cache.
Throws:
java.lang.Exception - Thrown if an error occurs.

add

public void add(java.lang.String username,
                WfResourceInternal res)
         throws java.lang.Exception
Adds resource to the resource cache.

Specified by:
add in interface ResourceCache
Parameters:
username - Username of the resource.
res - WfResourceInternal object to be added to the resource cache.
Throws:
java.lang.Exception - Thrown if an error occurs.

remove

public void remove(java.lang.String username)
            throws java.lang.Exception
Removes resource from the resource cache.

Specified by:
remove in interface ResourceCache
Parameters:
username - Username of the resource.
Throws:
java.lang.Exception - Thrown if an error occurs.

get

public WfResourceInternal get(java.lang.String username)
                       throws java.lang.Exception
Returns the resource from the resource cache with username username.

Specified by:
get in interface ResourceCache
Parameters:
username - Username of the resource.
Returns:
Resource from the cache with the username username if exists, otherwise null.
Throws:
java.lang.Exception - Thrown if an error occurs.

getAll

public java.util.List getAll()
                      throws java.lang.Exception
Returns all resources from the resource cache.

Specified by:
getAll in interface ObjectCache
Returns:
All resources from the cache as List.
Throws:
java.lang.Exception - Thrown if an error occurs.

setSize

public void setSize(int size)
             throws java.lang.Exception
Sets size of the resource cache to value size. The value 0 means that the cache is disabled. The negative value means that the cache is unbounded. The positive number defines max number of cache entries.

Specified by:
setSize in interface ObjectCache
Parameters:
size - New size of the resource cache.
Throws:
java.lang.Exception - Thrown if an error occurs.

getSize

public int getSize()
            throws java.lang.Exception
Returns the size of the resource cache.

Specified by:
getSize in interface ObjectCache
Returns:
Size of the resource cache.
Throws:
java.lang.Exception - Thrown if an error occurs.

howManyEntries

public int howManyEntries()
                   throws java.lang.Exception
Specified by:
howManyEntries in interface ObjectCache
Throws:
java.lang.Exception