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
protected  boolean active
          Indicates if the user cache is active
static int DEFAULT_SIZE
           
protected  java.lang.String[] fields
          is the list of field name used for the cache index
protected  int id
          The identifier of the user cache (light weight pattern)
protected  java.util.Map key2oid
          Contains the association user key TO object identifier
protected  java.lang.String name
          The name of the user cache
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.
 int getId()
           
 java.lang.String[] getIndexFieldNames()
           
 java.lang.String getName()
           
 boolean isActive()
           
 java.lang.Object lookup(java.lang.Object key)
          Look for an identifier of persistent instance from an user key
 void setActive(boolean a)
           
 void setId(int _id)
           
 void setIndexFieldNames(java.lang.String[] fns)
           
 void setName(java.lang.String n)
           
 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


name

protected java.lang.String name
The name of the user cache


id

protected int id
The identifier of the user cache (light weight pattern)


active

protected boolean active
Indicates if the user cache is active


fields

protected java.lang.String[] fields
is the list of field name used for the cache index

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.

getId

public int getId()
Specified by:
getId in interface UserCache

setId

public void setId(int _id)

getIndexFieldNames

public java.lang.String[] getIndexFieldNames()
Specified by:
getIndexFieldNames in interface UserCache

setIndexFieldNames

public void setIndexFieldNames(java.lang.String[] fns)

getName

public java.lang.String getName()
Specified by:
getName in interface UserCache

setName

public void setName(java.lang.String n)

isActive

public boolean isActive()
Specified by:
isActive in interface UserCache

setActive

public void setActive(boolean a)