|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.exolab.castor.persist.LockEngine
public final class LockEngine
LockEngine is a gateway for all the ClassMolders of a persistence storage. It maintains dirty checking cache state and lock, and provides a thread safe environment for ClassMolder. LockEngine guarantees that no two conflicting operations will be let running concurrently for the same object.
For example, it ensures that exactly one transaction may read (load) exclusively on one object; transaction can not deleted an object while the other is reading it, etc...
User should not create more than one instance of LockEngine for each persistent storage. So that object can be properly locked and ObjectModifiedException can be avoided.
However, if more than one instance of LockEngine or some other external
application run concurrently, if the Persistence supports dirty checking,
like a fully complaint JDBC Relational Database, proper
ObjectModifiedException will be thrown to ensure data consistency.
IMPLEMENTATION NOTES:
An object may be persistent in multiple caches at any given time. There is no way to load an object from multiple caches, but an object can be loaded in one engine and then made persistent in another. The engines are totally independent and no conflicts should occur.
| Constructor Summary | |
|---|---|
LockEngine(DatabaseContext databaseContext,
ClassDescriptorResolver cdResolver,
PersistenceFactory persistenceFactory)
Construct a new cache engine with the specified mapping table, persistence engine and the log intercepter. |
|
| Method Summary | |
|---|---|
void |
closeCaches()
Close all caches (to allow for resource clean-up). |
OID |
create(TransactionContext tx,
OID oid,
Object object)
Creates a new object in the persistence storage. |
void |
delete(TransactionContext tx,
OID oid)
Called at transaction commit time to delete the object. |
void |
dumpCache()
Dump cached objects of all types to output. |
void |
dumpCache(Class<?> cls)
Dump cached objects of specific type to output. |
void |
expireCache()
Expires all objects of all types from cache. |
void |
expireCache(Class<?> cls)
Forces the cache to be expired for the object represented by ClassMolder and identity. |
boolean |
expireCache(TransactionContext tx,
OID oid,
int timeout)
Expire object from the cache. |
void |
forgetObject(TransactionContext tx,
OID oid)
Called at transaction commit or rollback to forget an object and release its locks. |
ClassMolderRegistry |
getClassMolderRegistry()
|
DatabaseContext |
getDatabaseContext()
|
Persistence |
getPersistence(Class<?> cls)
Get the persistence of the specified class. |
PersistenceFactory |
getPersistenceFactory()
|
HashMap<Xid,TransactionContext> |
getXATransactions()
Returns an association between Xid and transactions contexts. |
boolean |
isCached(Class<?> cls,
OID oid)
Provides information about whether an object of Class cls with identity iod is currently cached. |
boolean |
isLocked(Class<?> cls,
OID oid)
Indicates whether an object with the specified OID is currently locked. |
void |
load(AbstractTransactionContext tx,
OID oid,
ProposedEntity proposedObject,
AccessMode suggestedAccessMode,
int timeout,
QueryResults results,
ClassMolder paramMolder,
Identity identity)
Loads an object of the specified type and identity from persistent storage. |
void |
markCreate(TransactionContext tx,
OID oid,
Object object)
Mark an object and its related or dependent object to be created. |
void |
markDelete(TransactionContext tx,
OID oid,
Object object,
int timeout)
Make the object is deleted. |
OID |
preStore(TransactionContext tx,
OID oid,
Object object,
int timeout)
Called at transaction commit to store an object that has been loaded during the transaction. |
void |
releaseLock(TransactionContext tx,
OID oid)
Called at transaction commit or rollback to release all locks held on the object. |
void |
revertObject(TransactionContext tx,
OID oid,
Object object)
Reverts an object to the cached copy given the object's OID. |
void |
softLock(TransactionContext tx,
OID oid,
int timeout)
Acquire a write lock on the object in memory. |
void |
store(TransactionContext tx,
OID oid,
Object object)
Store the object in TransactionContext. |
boolean |
update(AbstractTransactionContext tx,
OID oid,
Object object,
AccessMode suggestedAccessMode,
int timeout)
Updates an existing object to this engine. |
void |
updateCache(TransactionContext tx,
OID oid,
Object object)
Update the cached object with changes done to its copy. |
void |
writeLock(TransactionContext tx,
OID oid,
int timeout)
Acquire a write lock on the object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LockEngine(DatabaseContext databaseContext,
ClassDescriptorResolver cdResolver,
PersistenceFactory persistenceFactory)
throws MappingException
databaseContext - the databaseContextcdResolver - the cdResolverpersistenceFactory - Factory for creating persistence engines for each
object described in the map.
MappingException - Indicate that one of the mappings is invalid| Method Detail |
|---|
public DatabaseContext getDatabaseContext()
public ClassMolderRegistry getClassMolderRegistry()
public Persistence getPersistence(Class<?> cls)
cls - the specified class
public void load(AbstractTransactionContext tx,
OID oid,
ProposedEntity proposedObject,
AccessMode suggestedAccessMode,
int timeout,
QueryResults results,
ClassMolder paramMolder,
Identity identity)
throws PersistenceException
tx - The transaction contextoid - The identity of the object to loadproposedObject - The type of the object to loadsuggestedAccessMode - The desired access modetimeout - The timeout waiting to acquire a lock on the
object (specified in seconds)results - the QueryResultsparamMolder - the ClassMolderidentity - the Identity
PersistenceException - An error reported by the persistence engine
public void markCreate(TransactionContext tx,
OID oid,
Object object)
throws PersistenceException
tx - The transaction context.oid - The identity of the object, or null.object - The newly created object.
PersistenceException - An error reported by the persistence engine. Timeout or
deadlock occurred attempting to acquire lock on object.
public OID create(TransactionContext tx,
OID oid,
Object object)
throws PersistenceException
tx - The transaction contextoid - The identity of the object, or nullobject - The newly created object
PersistenceException - An error reported by the
persistence engine
public void delete(TransactionContext tx,
OID oid)
throws PersistenceException
forgetObject(org.castor.persist.TransactionContext, org.exolab.castor.persist.OID)
tx - The transaction contextoid - The object's identity
PersistenceException - An error reported by the
persistence engine
public void markDelete(TransactionContext tx,
OID oid,
Object object,
int timeout)
throws PersistenceException
tx - The transaction contextoid - The object's identityobject - The objecttimeout - The timeout
PersistenceException - If the lock is not granted
public boolean update(AbstractTransactionContext tx,
OID oid,
Object object,
AccessMode suggestedAccessMode,
int timeout)
throws PersistenceException
tx - The transaction contextoid - The object's identityobject - The objectsuggestedAccessMode - The desired access modetimeout - The timeout waiting to acquire a lock on the
object (specified in seconds)
PersistenceException - An error reported by the
persistence engine, or lock, or concurrent modification
public OID preStore(TransactionContext tx,
OID oid,
Object object,
int timeout)
throws PersistenceException
tx - The transaction contextoid - The object's identityobject - The object to storetimeout - The timeout waiting to acquire a lock on the
object (specified in seconds)
PersistenceException - An error reported by the
persistence engine, lock, or concurrent modification
public void store(TransactionContext tx,
OID oid,
Object object)
throws PersistenceException
tx - The transaction contextoid - The object's OIDobject - the object
PersistenceException - n error reported by the
persistence engine, or lock
public void writeLock(TransactionContext tx,
OID oid,
int timeout)
throws PersistenceException
tx - The transaction contextoid - The object's OIDtimeout - The timeout waiting to acquire a lock on the
object (specified in seconds)
PersistenceException - An error reported by the
persistence engine, or lock
public void softLock(TransactionContext tx,
OID oid,
int timeout)
throws LockNotGrantedException
tx - The transaction contextoid - The object's OIDtimeout - The timeout waiting to acquire a lock on the
object (specified in seconds)
LockNotGrantedException - Timeout or deadlock occurred
attempting to acquire lock on object persistent storage
public void revertObject(TransactionContext tx,
OID oid,
Object object)
throws PersistenceException
tx - The transaction contextoid - The object's oidobject - The object into which to copy
PersistenceException - An error reported by the
persistence engine obtaining a dependent object
public void updateCache(TransactionContext tx,
OID oid,
Object object)
store(org.castor.persist.TransactionContext, org.exolab.castor.persist.OID, java.lang.Object) and is assumed to have obtained a write
lock.
tx - The transaction contextoid - The object's oidobject - The object to copy from
public void releaseLock(TransactionContext tx,
OID oid)
tx - The transaction contextoid - The object OID
public void forgetObject(TransactionContext tx,
OID oid)
tx - The transaction contextoid - The object OID
public boolean expireCache(TransactionContext tx,
OID oid,
int timeout)
throws PersistenceException
tx - The transaction contextoid - The object OIDtimeout - The max time to wait while acquiring a lock on the
object (specified in seconds)
PersistenceException - An error reported by the persistence engine, or lockpublic void expireCache(Class<?> cls)
cls - Class type instance.public void expireCache()
public void dumpCache()
public void closeCaches()
public void dumpCache(Class<?> cls)
cls - A class type.public HashMap<Xid,TransactionContext> getXATransactions()
public boolean isCached(Class<?> cls,
OID oid)
cls - Class type.oid - Object identity
public boolean isLocked(Class<?> cls,
OID oid)
cls - Class type.oid - Object identity
public PersistenceFactory getPersistenceFactory()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||