Protege 3.4.8

edu.stanford.smi.protege.server.update
Class DeferredOperationCache

java.lang.Object
  extended by edu.stanford.smi.protege.server.update.DeferredOperationCache
All Implemented Interfaces:
Cache<RemoteSession,Sft,List>

public class DeferredOperationCache
extends Object
implements Cache<RemoteSession,Sft,List>

Certain operations, most noteably begin/commit/rollback transaction apply to all the cache's in the RemoteClientFrameStore. It is clear that updating all of these caches on such an operation is expensive. So we defer telling the frame caches about transaction operations until that cache is needed. The RemoteClientFrameStore uses a Fifo writer to track the transactions that have not been seen by its various caches. When this cache is needed it can read through all the transaction operations that it has not seen and it will be ready to perform the needed operation.

Also, it is sometimes necessary to start a cache when the invoker is already in a transaction. This is bad. It can lead to incorrect data in the untransacted cache and missing rollbacks. This situation should be taken care of by the InvalidatableCache which commits suicide when it noties a transaction with nesting less than 0.

Author:
tredmond

Constructor Summary
DeferredOperationCache(Cache<RemoteSession,Sft,List> delegate, FifoReader<SerializedCacheUpdate<RemoteSession,Sft,List>> transactionUpdates)
           
 
Method Summary
 void abortCompleteCache()
           
 void beginTransaction(RemoteSession session)
          The session has entered a transaction.
 void commitTransaction(RemoteSession session)
          A transaction is committed.
 void finishCompleteCache()
          The startCompleteCache and the finishCompleteCache are part of a protocol.
 void flush()
          Try to avoid this.
 int getCacheId()
          This method returns a unique id for each cache.
 int getTransactionNesting(RemoteSession session)
          Returns the transaction nesting for a session.
 void invalidate(RemoteSession session)
          This notifies the cache that this cache is now invalid either because the object that this cache represents is deleted or for any other reason.
 boolean isCacheComplete()
           
 boolean isInvalid()
          This indicates that the cache has entered the deleted state or is otherwise invalid.
 void modifyCache(RemoteSession session, Sft var)
          This notifies the cache, that the caller has made a change to the value of the var.
 void modifyCache(RemoteSession session, Sft var, List value)
          This notifies the cache that the caller has made a change to the value of var and that the caller knows the new value is value.
 CacheResult<List> readCache(RemoteSession session, Sft var)
          If the variable var is cached then this returns the cached value.
 void rollbackTransaction(RemoteSession session)
          A transaction is rolled back.
 void startCompleteCache()
          The startCompleteCache and the finishCompleteCache are part of a protocol.
 void updateCache(RemoteSession session, Sft var)
          This call indicates that a read was scheduled but no useful value was retrieved.
 void updateCache(RemoteSession session, Sft var, List value)
          The caller has received an update that the new value of var is value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeferredOperationCache

public DeferredOperationCache(Cache<RemoteSession,Sft,List> delegate,
                              FifoReader<SerializedCacheUpdate<RemoteSession,Sft,List>> transactionUpdates)
Method Detail

readCache

public CacheResult<List> readCache(RemoteSession session,
                                   Sft var)
Description copied from interface: Cache
If the variable var is cached then this returns the cached value. It can be null in which case the isValid() method should be called to determine if this is just a missing cache element or actually the correct value. This call is required to never return null so that the code sequence
    CacheResult result = cache.readCache(session, var);
    if (result.isValid()) {
       return result.getValue();
    else {
       go to the source to  find the right value
    } 
 
works and is the recommended approach.

Specified by:
readCache in interface Cache<RemoteSession,Sft,List>
var - a variable
Returns:
the value in the cache for the variable var. Never returns null.

updateCache

public void updateCache(RemoteSession session,
                        Sft var)
Description copied from interface: Cache
This call indicates that a read was scheduled but no useful value was retrieved. This can happen between a startCompleteCache and a finishCompleteCache. The process filling the cache is supposed to read all possible variables that might have a value. But the process either doesn't want to read the var (too expensive) or was not able to. This allows the cache to understand that it does not have a value at this var.

Specified by:
updateCache in interface Cache<RemoteSession,Sft,List>
Parameters:
session - the session making the change

updateCache

public void updateCache(RemoteSession session,
                        Sft var,
                        List value)
Description copied from interface: Cache
The caller has received an update that the new value of var is value. This as viewed as a value read. The session is important for two reasons. First, if the transaction isolation level is repeatable read, a session must not use the cache on the first read during a transaction even if the correct value is known. The underlying mechanism must be invoked so that it can record that a read has occurred. Second the session is important to determine if the value being read might be visible only in the single

Specified by:
updateCache in interface Cache<RemoteSession,Sft,List>
Parameters:
session - the session making the change

modifyCache

public void modifyCache(RemoteSession session,
                        Sft var)
Description copied from interface: Cache
This notifies the cache, that the caller has made a change to the value of the var. It is important that the caller always calls one of the modifyCache calls when making changes to cached values.

Specified by:
modifyCache in interface Cache<RemoteSession,Sft,List>
Parameters:
session - the session making the change
var - the variable being modified.

modifyCache

public void modifyCache(RemoteSession session,
                        Sft var,
                        List value)
Description copied from interface: Cache
This notifies the cache that the caller has made a change to the value of var and that the caller knows the new value is value.

Specified by:
modifyCache in interface Cache<RemoteSession,Sft,List>
Parameters:
session - the session making the change
var - the variable being changed
value - the new value for the variable

invalidate

public void invalidate(RemoteSession session)
Description copied from interface: Cache
This notifies the cache that this cache is now invalid either because the object that this cache represents is deleted or for any other reason. If this change is outside a transaction or gets committed, the cache enters the invalid state. Once in the invalidated state all attempts to get a value return a value null value.

Specified by:
invalidate in interface Cache<RemoteSession,Sft,List>

isInvalid

public boolean isInvalid()
Description copied from interface: Cache
This indicates that the cache has entered the deleted state or is otherwise invalid. A cache cannot recover from this state.

Specified by:
isInvalid in interface Cache<RemoteSession,Sft,List>

flush

public void flush()
Description copied from interface: Cache
Try to avoid this. If this is invoked and you are at READ_COMMITTED or above, the cache can repeatedly get flushed on commit and rollback transactions until everything is closed out.

Specified by:
flush in interface Cache<RemoteSession,Sft,List>

startCompleteCache

public void startCompleteCache()
Description copied from interface: Cache
The startCompleteCache and the finishCompleteCache are part of a protocol. In the interval between the startCompleteCache and the finishCompleteCache, the values in the cache - with the exception of any entries that have been explicitly invalidated - are a complete list of all the real values.

Specified by:
startCompleteCache in interface Cache<RemoteSession,Sft,List>

finishCompleteCache

public void finishCompleteCache()
Description copied from interface: Cache
The startCompleteCache and the finishCompleteCache are part of a protocol. In the interval between the startCompleteCache and the finishCompleteCache, the values in the cache - with the exception of any entries that have been explicitly invalidated - are a complete list of all the real values.

Specified by:
finishCompleteCache in interface Cache<RemoteSession,Sft,List>

abortCompleteCache

public void abortCompleteCache()
Specified by:
abortCompleteCache in interface Cache<RemoteSession,Sft,List>

isCacheComplete

public boolean isCacheComplete()
Specified by:
isCacheComplete in interface Cache<RemoteSession,Sft,List>

beginTransaction

public void beginTransaction(RemoteSession session)
Description copied from interface: Cache
The session has entered a transaction. Nesting is counted.

Specified by:
beginTransaction in interface Cache<RemoteSession,Sft,List>

commitTransaction

public void commitTransaction(RemoteSession session)
Description copied from interface: Cache
A transaction is committed.

Specified by:
commitTransaction in interface Cache<RemoteSession,Sft,List>

rollbackTransaction

public void rollbackTransaction(RemoteSession session)
Description copied from interface: Cache
A transaction is rolled back.

Specified by:
rollbackTransaction in interface Cache<RemoteSession,Sft,List>

getTransactionNesting

public int getTransactionNesting(RemoteSession session)
Description copied from interface: Cache
Returns the transaction nesting for a session. This is really just a convenience method for the implementation.

Specified by:
getTransactionNesting in interface Cache<RemoteSession,Sft,List>

getCacheId

public int getCacheId()
Description copied from interface: Cache
This method returns a unique id for each cache. This is to give the entire aspect stack of a cache to make logging and debugging easier

Specified by:
getCacheId in interface Cache<RemoteSession,Sft,List>

Protege 3.4.8

Submit a bug report or feature request
Protégé is a trademark of Stanford University.
Copyright (c) 1998-2012 Stanford University.