org.jboss.util
Class SynchronizedCachePolicy

java.lang.Object
  extended by org.jboss.util.SynchronizedCachePolicy
All Implemented Interfaces:
CachePolicy

public final class SynchronizedCachePolicy
extends Object
implements CachePolicy

A synchronized cache policy wrapper.

Version:
$Revision: 1958 $
Author:
Julien Viet
See Also:
CachePolicy

Constructor Summary
SynchronizedCachePolicy(CachePolicy delegate)
           
 
Method Summary
 void create()
          create the service, do expensive operations etc
 void destroy()
          destroy the service, tear down
 void flush()
          Flushes the cached objects from the cache.
 Object get(Object key)
          Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
 void insert(Object key, Object object)
          Inserts the specified object into the cache following the implemented policy.
 Object peek(Object key)
          Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
 void remove(Object key)
          Remove the cached object paired with the specified key.
 int size()
          Get the size of the cache.
 void start()
          start the service, create is already called
 void stop()
          stop the service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedCachePolicy

public SynchronizedCachePolicy(CachePolicy delegate)
Method Detail

get

public Object get(Object key)
Description copied from interface: CachePolicy
Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
Implementations of this method must have complexity of order O(1). Differently from CachePolicy.peek(java.lang.Object) this method not only return whether the object is present in the cache or not, but also applies the implemented policy that will "refresh" the cached object in the cache, because this cached object was really requested.

Specified by:
get in interface CachePolicy
Parameters:
key - the key paired with the object
See Also:
CachePolicy.peek(java.lang.Object)

peek

public Object peek(Object key)
Description copied from interface: CachePolicy
Returns the object paired with the specified key if it's present in the cache, otherwise must return null.
Implementations of this method must have complexity of order O(1). This method should not apply the implemented caching policy to the object paired with the given key, so that a client can query if an object is cached without "refresh" its cache status. Real requests for the object must be done using CachePolicy.get(java.lang.Object).

Specified by:
peek in interface CachePolicy
Parameters:
key - the key paired with the object
See Also:
CachePolicy.get(java.lang.Object)

insert

public void insert(Object key,
                   Object object)
Description copied from interface: CachePolicy
Inserts the specified object into the cache following the implemented policy.
Implementations of this method must have complexity of order O(1).

Specified by:
insert in interface CachePolicy
Parameters:
key - the key paired with the object
object - the object to cache
See Also:
CachePolicy.remove(java.lang.Object)

remove

public void remove(Object key)
Description copied from interface: CachePolicy
Remove the cached object paired with the specified key.
Implementations of this method must have complexity of order O(1).

Specified by:
remove in interface CachePolicy
Parameters:
key - the key paired with the object
See Also:
CachePolicy.insert(java.lang.Object, java.lang.Object)

flush

public void flush()
Description copied from interface: CachePolicy
Flushes the cached objects from the cache.

Specified by:
flush in interface CachePolicy

size

public int size()
Description copied from interface: CachePolicy
Get the size of the cache.

Specified by:
size in interface CachePolicy

create

public void create()
            throws Exception
Description copied from interface: CachePolicy
create the service, do expensive operations etc

Specified by:
create in interface CachePolicy
Throws:
Exception

start

public void start()
           throws Exception
Description copied from interface: CachePolicy
start the service, create is already called

Specified by:
start in interface CachePolicy
Throws:
Exception

stop

public void stop()
Description copied from interface: CachePolicy
stop the service

Specified by:
stop in interface CachePolicy

destroy

public void destroy()
Description copied from interface: CachePolicy
destroy the service, tear down

Specified by:
destroy in interface CachePolicy


Copyright © 2008 JBoss Inc.. All Rights Reserved.