ostore.cache
Class CacheableIdentity

java.lang.Object
  |
  +--ostore.cache.CacheableIdentity
All Implemented Interfaces:
QuickSerializable

public class CacheableIdentity
extends Object
implements QuickSerializable

Version:
$ID: CacheableIdentity.java,v 1.0 This class identifies important characteristics of a cached object. By trading in a CacheableIdentity, one can receive a CacheableHandle to gain access to the object stored in the cache. This class helps store/retrieve objects when they are evicted from the cache.
Author:
Larry H. Tung

Field Summary
static int DISS
          indicates that this object is a disseminatable
static int DISS_BUCKET
          indicates that this object is a disseminatable bucket
static int GUID
          indicates that this object has a GUID
static int VHASH
          indicates that this object has a VHASH
 
Constructor Summary
CacheableIdentity()
          Create a CacheableIdentity for a specific object.
CacheableIdentity(InputBuffer buffer)
          Constructs a CacheableIdentity from its serialized form.
CacheableIdentity(int[] type, Object[] names)
          Create a CacheableIdentity for a specific object which has multiple types.
CacheableIdentity(int type, Object name)
          Create a CacheableIdentity for a specific object of a given type.
CacheableIdentity(VID vid)
          Create a CacheableIdentity for an object named by a VID.
 
Method Summary
 void addPair(int type, Object name)
          Add another pair to this CacheableIdentity.
 CacheableIdentity append(CacheableIdentity old)
          Append any differences from this to a copy of old
 CacheableIdentity copy()
          makes a new copy of an existing CacheableIdentity
 boolean equals(Object other)
          Tests for complete equality with other CacheableIdentitys.
 Object get(int type)
          return the object associated with type where type is one of the globally defined types above (ie GUID, VHASH...)
 int hashCode()
          Adds the hash code of all the internal names.
 boolean matches(CacheableIdentity other)
          Tests for equivalence among CacheableIdentitys.
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

GUID

public static final int GUID
indicates that this object has a GUID

See Also:
Constant Field Values

VHASH

public static final int VHASH
indicates that this object has a VHASH

See Also:
Constant Field Values

DISS

public static final int DISS
indicates that this object is a disseminatable

See Also:
Constant Field Values

DISS_BUCKET

public static final int DISS_BUCKET
indicates that this object is a disseminatable bucket

See Also:
Constant Field Values
Constructor Detail

CacheableIdentity

public CacheableIdentity()
Create a CacheableIdentity for a specific object. One will then call addPair to give this CacheableIdentity its attributes


CacheableIdentity

public CacheableIdentity(VID vid)
Create a CacheableIdentity for an object named by a VID.

Parameters:
vid - The identifier of the block.

CacheableIdentity

public CacheableIdentity(int type,
                         Object name)
Create a CacheableIdentity for a specific object of a given type. Type must be one of the valid static integers, such as CacheableIdentity.some_type where some_type is equal to GUID or VHASH.

Parameters:
name - when evicted, will use name to identity object. For example, if the disk is used to store evicted items, the item will have name as its name.
type - predefined static integer representing a characteristic of the object. For example, CacheableIdentity.GUID indicates that this object has a GUID.

CacheableIdentity

public CacheableIdentity(int[] type,
                         Object[] names)
Create a CacheableIdentity for a specific object which has multiple types.

Parameters:
names - when evicted, will use name to identity object. For example, if the disk is used to store evicted items, the item will have name as its name.
type - holds all types that this object can be defined by. For example, object may have a GUID and VHASH, and type[] will hold both CacheableIdentity.GUID and CacheableIdentity.VHASH

CacheableIdentity

public CacheableIdentity(InputBuffer buffer)
                  throws QSException
Constructs a CacheableIdentity from its serialized form.

Parameters:
buffer - serialized form of object.
Method Detail

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.

Specified by:
serialize in interface QuickSerializable
Parameters:
buffer - the output buffer to add the object to

copy

public CacheableIdentity copy()
makes a new copy of an existing CacheableIdentity


append

public CacheableIdentity append(CacheableIdentity old)
Append any differences from this to a copy of old

Parameters:
old - id currently used by Cache

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object other)
Tests for complete equality with other CacheableIdentitys. The two must contain the same names with the same types, although internal order is unimportant.

Overrides:
equals in class Object
See Also:
matches(ostore.cache.CacheableIdentity)

matches

public boolean matches(CacheableIdentity other)
Tests for equivalence among CacheableIdentitys.

Returns:
true iff any name and type is common between this and other.

hashCode

public int hashCode()
Adds the hash code of all the internal names.

Overrides:
hashCode in class Object

get

public Object get(int type)
return the object associated with type where type is one of the globally defined types above (ie GUID, VHASH...)
if the CacheableIdentity does not contain type, return null


addPair

public void addPair(int type,
                    Object name)
Add another pair to this CacheableIdentity. This gives the cache more flexibility in storing this object.