Package net.ontopia.persistence.proxy
Class SharedCache
- java.lang.Object
-
- net.ontopia.persistence.proxy.SharedCache
-
- All Implemented Interfaces:
AccessRegistrarIF,StorageCacheIF
public class SharedCache extends Object implements StorageCacheIF, AccessRegistrarIF
INTERNAL: A shared storage cache implementation. The cache uses a lookup index to store its cache entries. This cache is transaction independent.
-
-
Field Summary
Fields Modifier and Type Field Description protected ClusterIFclusterprotected TicketIFcurrent_ticketprotected longcurrent_ticket_valueprotected Map<IdentityIF,CacheEntry>datacacheprotected intevictionprotected Map<Object,Integer>field_countsprotected StorageIFstorageprotected longtimestamp
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(boolean notifyCluster)INTERNAL: Clears the cache.voidclose()INTERNAL: Releases all resources used by the storage cache.IdentityIFcreateIdentity(Class<?> type, long key)INTERNAL: Factory method for creating new identity objects.IdentityIFcreateIdentity(Class<?> type, Object key)INTERNAL: Factory method for creating new identity objects.IdentityIFcreateIdentity(Class<?> type, Object[] keys)INTERNAL: Factory method for creating new identity objects.voidevictField(IdentityIF identity, int field, boolean notifyCluster)INTERNAL: Evict the identity's field value from the cache.voidevictFields(IdentityIF identity, boolean notifyCluster)INTERNAL: Evict all the identity's field values from the cache.voidevictIdentity(IdentityIF identity, boolean notifyCluster)INTERNAL: Evict the identity from the cache.booleanexists(StorageAccessIF access, IdentityIF identity)INTERNAL: Can be called to verify whether the specified identity exists in the cache or in the data repository.protected intgetFieldsCount(Class<?> type)AccessRegistrarIFgetRegistrar()INTERNAL: Returns the access registrar instance that is used by the storage cache.TicketIFgetTicket()INTERNAL: Get ticket that should be used as first argument to register methods.ObjectgetValue(StorageAccessIF access, IdentityIF identity, int field)INTERNAL: A call forwarded by the transaction (TransactionIF) from persistent objects (PersistentIF) when the field value needs to be retrieved from storage.booleanisFieldLoaded(IdentityIF identity, int field)INTERNAL: Can be called to check if the specfied field has been registered with the cache.booleanisObjectLoaded(IdentityIF identity)INTERNAL: Can be called to check if the identity has been registered with the cache.intprefetch(StorageAccessIF access, Class<?> type, int field, int nextField, boolean traverse, Collection<IdentityIF> identities)voidregisterEviction()INTERNAL: Tells the cache that eviction is starting.voidregisterField(TicketIF ticket, IdentityIF identity, int field, Object value)INTERNAL: Called by storage accessors (FieldAccessIF) when they read the value of an object field from the database.voidregisterIdentity(TicketIF ticket, IdentityIF identity)INTERNAL: Called by storage accessors (QueryIFs or FieldAccessIF) when they locate the identity of an object in the database.voidreleaseEviction()INTERNAL: Deregister eviction.voidsetCluster(ClusterIF cluster)StringtoString()voidwriteReport(Writer out, boolean dumpCache)
-
-
-
Field Detail
-
storage
protected StorageIF storage
-
datacache
protected Map<IdentityIF,CacheEntry> datacache
-
current_ticket_value
protected long current_ticket_value
-
current_ticket
protected TicketIF current_ticket
-
eviction
protected int eviction
-
cluster
protected ClusterIF cluster
-
timestamp
protected long timestamp
-
-
Method Detail
-
setCluster
public void setCluster(ClusterIF cluster)
-
getRegistrar
public AccessRegistrarIF getRegistrar()
Description copied from interface:StorageCacheIFINTERNAL: Returns the access registrar instance that is used by the storage cache. If it does not need an access registrar, or it does not have one, null is returned.- Specified by:
getRegistrarin interfaceStorageCacheIF
-
close
public void close()
Description copied from interface:StorageCacheIFINTERNAL: Releases all resources used by the storage cache.- Specified by:
closein interfaceStorageCacheIF
-
exists
public boolean exists(StorageAccessIF access, IdentityIF identity)
Description copied from interface:StorageCacheIFINTERNAL: Can be called to verify whether the specified identity exists in the cache or in the data repository. Whether the data repository is actually asked depends on the policy of the storage cache.- Specified by:
existsin interfaceStorageCacheIF
-
getValue
public Object getValue(StorageAccessIF access, IdentityIF identity, int field)
Description copied from interface:StorageCacheIFINTERNAL: A call forwarded by the transaction (TransactionIF) from persistent objects (PersistentIF) when the field value needs to be retrieved from storage. The field value will be returned.- Specified by:
getValuein interfaceStorageCacheIF
-
isObjectLoaded
public boolean isObjectLoaded(IdentityIF identity)
Description copied from interface:StorageCacheIFINTERNAL: Can be called to check if the identity has been registered with the cache. The data repository will not be asked.- Specified by:
isObjectLoadedin interfaceStorageCacheIF
-
isFieldLoaded
public boolean isFieldLoaded(IdentityIF identity, int field)
Description copied from interface:StorageCacheIFINTERNAL: Can be called to check if the specfied field has been registered with the cache. The data repository will not be asked.- Specified by:
isFieldLoadedin interfaceStorageCacheIF
-
evictIdentity
public void evictIdentity(IdentityIF identity, boolean notifyCluster)
Description copied from interface:StorageCacheIFINTERNAL: Evict the identity from the cache.- Specified by:
evictIdentityin interfaceStorageCacheIF
-
evictFields
public void evictFields(IdentityIF identity, boolean notifyCluster)
Description copied from interface:StorageCacheIFINTERNAL: Evict all the identity's field values from the cache.- Specified by:
evictFieldsin interfaceStorageCacheIF
-
evictField
public void evictField(IdentityIF identity, int field, boolean notifyCluster)
Description copied from interface:StorageCacheIFINTERNAL: Evict the identity's field value from the cache.- Specified by:
evictFieldin interfaceStorageCacheIF
-
prefetch
public int prefetch(StorageAccessIF access, Class<?> type, int field, int nextField, boolean traverse, Collection<IdentityIF> identities)
- Specified by:
prefetchin interfaceStorageCacheIF
-
createIdentity
public IdentityIF createIdentity(Class<?> type, long key)
Description copied from interface:AccessRegistrarIFINTERNAL: Factory method for creating new identity objects. Key is guaranteed to have a width of 1 and key value which a Long.- Specified by:
createIdentityin interfaceAccessRegistrarIF
-
createIdentity
public IdentityIF createIdentity(Class<?> type, Object key)
Description copied from interface:AccessRegistrarIFINTERNAL: Factory method for creating new identity objects. Key is guaranteed to have a width of 1.- Specified by:
createIdentityin interfaceAccessRegistrarIF
-
createIdentity
public IdentityIF createIdentity(Class<?> type, Object[] keys)
Description copied from interface:AccessRegistrarIFINTERNAL: Factory method for creating new identity objects. Key can have any width.- Specified by:
createIdentityin interfaceAccessRegistrarIF
-
registerIdentity
public void registerIdentity(TicketIF ticket, IdentityIF identity)
Description copied from interface:AccessRegistrarIFINTERNAL: Called by storage accessors (QueryIFs or FieldAccessIF) when they locate the identity of an object in the database.- Specified by:
registerIdentityin interfaceAccessRegistrarIF
-
registerField
public void registerField(TicketIF ticket, IdentityIF identity, int field, Object value)
Description copied from interface:AccessRegistrarIFINTERNAL: Called by storage accessors (FieldAccessIF) when they read the value of an object field from the database.- Specified by:
registerFieldin interfaceAccessRegistrarIF
-
getTicket
public TicketIF getTicket()
Description copied from interface:AccessRegistrarIFINTERNAL: Get ticket that should be used as first argument to register methods. The ticket is used figure out if value should be registered or not.- Specified by:
getTicketin interfaceAccessRegistrarIF
-
registerEviction
public void registerEviction()
Description copied from interface:StorageCacheIFINTERNAL: Tells the cache that eviction is starting.- Specified by:
registerEvictionin interfaceStorageCacheIF
-
releaseEviction
public void releaseEviction()
Description copied from interface:StorageCacheIFINTERNAL: Deregister eviction.- Specified by:
releaseEvictionin interfaceStorageCacheIF
-
getFieldsCount
protected int getFieldsCount(Class<?> type)
-
clear
public void clear(boolean notifyCluster)
Description copied from interface:StorageCacheIFINTERNAL: Clears the cache.- Specified by:
clearin interfaceStorageCacheIF
-
writeReport
public void writeReport(Writer out, boolean dumpCache) throws IOException
- Throws:
IOException
-
-