org.objectweb.speedo.usercache.lib
Class UserCacheViewImpl

java.lang.Object
  extended byorg.objectweb.speedo.usercache.lib.UserCacheViewImpl
All Implemented Interfaces:
UserCacheView

public class UserCacheViewImpl
extends java.lang.Object
implements UserCacheView

Is a basic UserCacheView implementation using WeakReference in order to not disturb the real cache of persistent object.

Author:
S.Chassande-Barrioz

Field Summary
protected  java.util.Map cache
          This field is the cache.
protected  java.lang.ref.ReferenceQueue queue
          Queue used to register the weak references stored in the cache.
 
Constructor Summary
UserCacheViewImpl()
           
 
Method Summary
 java.lang.Object bind(java.lang.Object id, java.lang.Object obj)
          Register a persistent instance into the user view.
 void clean()
          Removes all entries that have been garbage collected.
 java.lang.Object lookup(java.lang.Class clazz, java.lang.Object key)
          Look for a persistent instance with an user identifier and a class
 java.lang.Object rebind(java.lang.Object oldkey, java.lang.Object newkey, java.lang.Object obj)
          Register an entry with an new user key.
 java.lang.Object unbind(java.lang.Class clazz, java.lang.Object key)
          Forces the eviction of an entry
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected java.util.Map cache
This field is the cache. This is a Map which the key are Class objects and the values are a map linking an user key to a persistent instance. Map(Class persistentClass, Map(Object userkey, Object persistentObject))


queue

protected java.lang.ref.ReferenceQueue queue
Queue used to register the weak references stored in the cache.

Constructor Detail

UserCacheViewImpl

public UserCacheViewImpl()
Method Detail

clean

public void clean()
Removes all entries that have been garbage collected.

Specified by:
clean in interface UserCacheView

bind

public java.lang.Object bind(java.lang.Object id,
                             java.lang.Object obj)
Description copied from interface: UserCacheView
Register a persistent instance into the user view. The persistent instance is bound with the couple (obj.getClass(), key). It means that entry are bound per class and par user key.

Specified by:
bind in interface UserCacheView
Parameters:
id - is the user key of the persistent instance
obj - is the persistent instance. It cannot be null.
Returns:
the previous associated persistent instance associated to the specified user key. The null value is returned if no previous instance was registered.

rebind

public java.lang.Object rebind(java.lang.Object oldkey,
                               java.lang.Object newkey,
                               java.lang.Object obj)
Description copied from interface: UserCacheView
Register an entry with an new user key. The old registration is removed.

Specified by:
rebind in interface UserCacheView
Parameters:
oldkey - is the old user key of the persistent instance
newkey - is the new user key of the persistent instance
obj - is the persistent instance. It cannot be null.
Returns:
the previous associated persistent instance associated to the new user key. The null value is returned if no previous instance was registered.

unbind

public java.lang.Object unbind(java.lang.Class clazz,
                               java.lang.Object key)
Description copied from interface: UserCacheView
Forces the eviction of an entry

Specified by:
unbind in interface UserCacheView
Parameters:
clazz - is the class of the persistent instance
key - is the user key of the persistent instance
Returns:

lookup

public java.lang.Object lookup(java.lang.Class clazz,
                               java.lang.Object key)
Description copied from interface: UserCacheView
Look for a persistent instance with an user identifier and a class

Specified by:
lookup in interface UserCacheView
Parameters:
clazz - is the class of the searched persistent instance
key - is the user key of the searched persistent instance
Returns: