org.objectweb.speedo.usercache.lib
Class UserCacheImpl

java.lang.Object
  extended byorg.objectweb.speedo.usercache.lib.UserCacheImpl
All Implemented Interfaces:
UserCache

public class UserCacheImpl
extends java.lang.Object
implements UserCache

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

Author:
S.Chassande-Barrioz

Field Summary
static int DEFAULT_SIZE
           
protected  java.util.Map key2oid
          Contains the association user key TO object identifier
protected  java.util.Map oid2key
          Contains the association object identifier TO user key
 
Constructor Summary
UserCacheImpl()
          Allocates an user cache with the default size.
UserCacheImpl(int size)
          Allocates an user cache with a particular size.
 
Method Summary
 java.lang.Object bind(java.lang.Object key, java.lang.Object oid)
          Adds an entry into user cache.
 java.lang.Object lookup(java.lang.Object key)
          Look for an identifier of persistent instance from an user key
 java.lang.Object unbindFromKey(java.lang.Object key)
          Forces the eviction of an entry from an user key
 java.lang.Object unbindFromOID(java.lang.Object oid)
          Forces the eviction of an entry from an object identifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SIZE

public static final int DEFAULT_SIZE
See Also:
Constant Field Values

key2oid

protected java.util.Map key2oid
Contains the association user key TO object identifier


oid2key

protected java.util.Map oid2key
Contains the association object identifier TO user key

Constructor Detail

UserCacheImpl

public UserCacheImpl()
Allocates an user cache with the default size.

See Also:
#DEFAULT_SIZE, UserCacheImpl(int)

UserCacheImpl

public UserCacheImpl(int size)
Allocates an user cache with a particular size. The size is not a maximal size, but serves only for the underlying underlying hash structure.

Parameters:
size - is the size of the cache.
Method Detail

bind

public java.lang.Object bind(java.lang.Object key,
                             java.lang.Object oid)
Description copied from interface: UserCache
Adds an entry into user cache. If an entry already exists with the same identifier or the same key, it has been replaced.

Specified by:
bind in interface UserCache
Parameters:
key - is the user key the user of the persistent instance (not null)
oid - is the identifier of the persistent instance (not null)
Returns:
the previous associated identifier of a persistent instance associated to the specified user key. The null value is returned if no entry was previously bound.

unbindFromKey

public java.lang.Object unbindFromKey(java.lang.Object key)
Description copied from interface: UserCache
Forces the eviction of an entry from an user key

Specified by:
unbindFromKey in interface UserCache
Parameters:
key - is the user key of a persistent instance (not null)
Returns:
the object identifier if found, otherwise null

unbindFromOID

public java.lang.Object unbindFromOID(java.lang.Object oid)
Description copied from interface: UserCache
Forces the eviction of an entry from an object identifier

Specified by:
unbindFromOID in interface UserCache
Parameters:
oid - is the identifier of a persistent instance (not null)
Returns:
the user key if found, otherwise null

lookup

public java.lang.Object lookup(java.lang.Object key)
Description copied from interface: UserCache
Look for an identifier of persistent instance from an user key

Specified by:
lookup in interface UserCache
Parameters:
key - is the user key of the searched persistent instance (not null)
Returns:
the identifier of the persistent instance corresponding to the user key. If not found, a null value is returned.