Protege 3.4.1

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

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

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

This is a hacky cache designed to solve two problems seen by the remote client frame store. First, 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. However, since this cache will only be used by the invoker, I believe that all this badness is countered by flushing the cache when the invokers transaction completes. I also believe that all transactions will be closed when this flush is called making it a clean flush. This is true because the server sends the begin and end of transactions made by other clients (not the invoker) in a group. Second, the begin/commit/rollback transaction operations apply to all the frame caches 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.

Author:
tredmond

Constructor Summary
DeferredTransactionsCache(Cache<RemoteSession,Sft,List> delegate, RemoteSession invoker, int invokersTransactionNesting, 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 delete(RemoteSession session)
          This notifies the cache that the caller has made deleted the object that this cache represents.
 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.
 boolean isCacheComplete()
           
 boolean isDeleted()
          This indicates that the cache has entered the deleted state.
 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

DeferredTransactionsCache

public DeferredTransactionsCache(Cache<RemoteSession,Sft,List> delegate,
                                 RemoteSession invoker,
                                 int invokersTransactionNesting,
                                 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

delete

public void delete(RemoteSession session)
Description copied from interface: Cache
This notifies the cache that the caller has made deleted the object that this cache represents. If this change is outside a transaction or gets committed, the cache enters the deleted state. Once in the deleted state all attempts to get a value return a value null value. Attempts to modify the cache after it has entered the deleted state will bring the cache back.

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

isDeleted

public boolean isDeleted()
Description copied from interface: Cache
This indicates that the cache has entered the deleted state. Once in this state the cache cannot recover.

Specified by:
isDeleted 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.1

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