Top Description Methods
org.apache.derby.iapi.services.cache

public Interface Cacheable

Known Direct Subinterfaces
org.apache.derby.iapi.services.cache.SizedCacheable
Known Direct Implementers
org.apache.derby.impl.sql.catalog.PermissionsCacheable, org.apache.derby.impl.sql.catalog.SequenceUpdater, org.apache.derby.impl.sql.catalog.SPSNameCacheable, org.apache.derby.impl.sql.catalog.TDCacheable, org.apache.derby.impl.store.access.CacheableConglomerate, org.apache.derby.impl.store.raw.data.CachedPage, org.apache.derby.impl.store.raw.data.FileContainer, org.apache.derby.impl.services.bytecode.VMTypeIdCacheable, org.apache.derby.impl.sql.conn.CachedStatement
Imports
org.apache.derby.shared.common.error.StandardException

Any object that implements this interface can be cached using the services of the CacheManager/CacheFactory. In addition to implementing this interface the class must be public and it must have a public no-arg constructor. This is because the cache manager will construct objects itself and then set their identity by calling the setIdentity method.

A Cacheable object has five states:

  1. No identity - The object is only accessable by the cache manager
  2. Identity, clean, unkept - The object has an identity, is clean but is only accessable by the cache manager
  3. Identity, clean, kept - The object has an identity, is clean, and is in use by one or more threads
  4. Identity, kept, dirty - The object has an identity, is dirty, and is in use by one or more threads
  5. Identity, unkept, dirty - The object has an identity, is dirty but is only accessable by the cache manager

While the object is kept it is guaranteed not to change identity. While it is unkept no-one outside of the cache manager can have a reference to the object. The cache manager returns kept objects and they return to the unkept state when all the current users of the object have released it.
It is required that the object can only move into a dirty state while it is kept.
MT - Mutable : thread aware - Calls to Cacheable method must only be made by the cache manager or the object itself.
See Also
CacheManager, CacheFactory, Class#newInstance

Method Summary

Modifier and TypeMethod and Description
public void
clean(boolean
True if the object will be removed
forRemove
)

Clean the object.

public void
clearIdentity()

Put the object into the No Identity state.

public Cacheable

Returns:

an object reference if the object can take on the identity, null otherwise.
createIdentity
(Object
The handle on the cacheable
key
,
Object
Creation details
createParameter
)

Create a new item.

public Object

Returns:

the object identity
getIdentity
()

Get the identity of this object.

public boolean

Returns:

true if the object is dirty
isDirty
()

Returns true if the object is dirty.

public Cacheable

Returns:

an object reference if the object can take on the identity, null otherwise.
setIdentity
(Object
The handle on the cacheable
key
)

Set the identity of the object.

Method Detail

cleanback to summary
public void clean(boolean forRemove) throws StandardException

Clean the object. It is up to the object to ensure synchronization of the isDirty() and clean() method calls.
If forRemove is true then the object is being removed due to an explict remove request, in this case the cache manager will have called this method regardless of the state of the isDirty()
If an exception is thrown the object must be left in the clean state.
MT - thread safe - Can be called at any time by the cache manager, it is the responsibility of the object implementing Cacheable to ensure any users of the object do not conflict with the clean call.

Parameters
forRemove:boolean

True if the object will be removed

Exceptions
StandardException:
Standard Derby error policy.
clearIdentityback to summary
public void clearIdentity()

Put the object into the No Identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

createIdentityback to summary
public Cacheable createIdentity(Object key, Object createParameter) throws StandardException

Create a new item.

Create a new item and set the identity of the object to represent it. The object will be in the No Identity state, ie. it will have just been created or clearIdentity() was just called.
The object must copy the information out of key, not just store a reference to key if the key is not immutable. After this call the expression getIdentity().equals(key) must return true.

If the class of the object needs to change (e.g. to support a different format) then the object should create a new object, call its initParameter() with the parameters the original object was called with, set its identity and return a reference to it. The cache manager will discard the reference to the old object.
If an exception is thrown the object must be left in the no-identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

Parameters
key:Object

The handle on the cacheable

createParameter:Object

Creation details

Returns:Cacheable

an object reference if the object can take on the identity, null otherwise.

Exceptions
StandardException:
If forCreate is true and the object cannot be created.
See Also
CacheManager#create
getIdentityback to summary
public Object getIdentity()

Get the identity of this object.
MT - thread safe.

Returns:Object

the object identity

isDirtyback to summary
public boolean isDirty()

Returns true if the object is dirty. May be called when the object is kept or unkept.
MT - thread safe

Returns:boolean

true if the object is dirty

setIdentityback to summary
public Cacheable setIdentity(Object key) throws StandardException

Set the identity of the object.

Set the identity of the object to represent an item that already exists, e.g. an existing container. The object will be in the No Identity state, ie. it will have just been created or clearIdentity() was just called.
The object must copy the information out of key, not just store a reference to key. After this call the expression getIdentity().equals(key) must return true.
If the class of the object needs to change (e.g. to support a different format) then the object should create a new object, call its initParameter() with the parameters the original object was called with, set its identity and return a reference to it. The cache manager will discard the reference to the old object.
If an exception is thrown the object must be left in the no-identity state.
MT - single thread required - Method must only be called be cache manager and the cache manager will guarantee only one thread can be calling it.

Parameters
key:Object

The handle on the cacheable

Returns:Cacheable

an object reference if the object can take on the identity, null otherwise.

Exceptions
StandardException:
Standard Derby Policy
See Also
CacheManager#find