|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.drjava.model.cache.DocumentCache
public class DocumentCache
The document cache is a structure that maps OpenDefinitionsDocuments to DefinitionsDocuments (which contain the actual document text). Since the latter can consume a lot of memory, the cache virtualizes some of them using DefinitionsDocument reconstructors (DDReconstructor). It tries to limit the number of DefinitionsDocuments loaded in memory at one time, but it must of course retain all modified DefinitionsDocuments.
The cache creates a DocManager for each OpenDefinitionsDocument entered (registered) in the cache. The managers maintain the actual links to DefinitionsDocuments. Since the Managers themselves implement the DCacheAdapter interface, the model goes directly to the manager to get the instance of the DefinitionsDocument.
When a document is accessed through the document manager by the model, the cache informs the manager, which tells the active queue to add the manager to the end of the queue--if it isn't already in the queue. If the active queue had already reached maximum size, it deletes the last document in the queue to keep the queue from growing larger than its maximum size.
The resident queue only contains documents that have not been modified since their last save (except in the process of responding to notification that a document has been modified). When a document is modified for the first time, it is immediately removed from the resident queue and marked as UNMANAGED by its document manager. An UNMANAGED document remains in memory until it is saved or closed without being saved. If such a document is saved, it is inserted again in the resident queue.
Since the cache and document managers can both be concurrently accessed from multiple threads, the methods in the DocumentCache and DocManager classes are synchronized. Some operations require locks on both the cache and a document manager, but the code is written so that none of require these locks to be held simultaneously.
| Nested Class Summary | |
|---|---|
private class |
DocumentCache.DocManager
Manages the retrieval of a document for a corresponding open definitions document. |
static interface |
DocumentCache.RegistrationListener
This interface allows the unit tests to get a handle on what's going on since the work is spread between the ODD, the cache, and the Adapters. |
| Field Summary | |
|---|---|
private java.lang.Object |
_cacheLock
|
private static Log |
_log
Log file. |
private java.util.LinkedList<DocumentCache.RegistrationListener> |
_regListeners
|
private java.util.LinkedHashSet<DocumentCache.DocManager> |
_residentQueue
|
private int |
CACHE_SIZE
invariant _residentQueue.size() <= CACHE_SIZE |
private static int |
IN_QUEUE
|
private static int |
INIT_CACHE_SIZE
|
private static int |
NOT_IN_QUEUE
|
private static int |
UNMANAGED
|
private static int |
UNTITLED
|
| Constructor Summary | |
|---|---|
DocumentCache()
|
|
DocumentCache(int size)
|
|
| Method Summary | |
|---|---|
void |
addRegistrationListener(DocumentCache.RegistrationListener list)
|
void |
clearRegistrationListeners()
|
int |
getCacheSize()
|
int |
getNumInCache()
|
private void |
notifyRegistrationListeners(OpenDefinitionsDocument odd,
DocumentCache.DocManager man)
|
DCacheAdapter |
register(OpenDefinitionsDocument odd,
DDReconstructor rec)
Returns a cache adapter corresponding to the owner of the given reconstructor. |
void |
removeRegistrationListener(DocumentCache.RegistrationListener list)
|
void |
setCacheSize(int size)
Changes the number of unmodified documents allowed in the cache at one time. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final Log _log
private static final int INIT_CACHE_SIZE
private int CACHE_SIZE
private java.util.LinkedHashSet<DocumentCache.DocManager> _residentQueue
private java.lang.Object _cacheLock
private static final int IN_QUEUE
private static final int UNTITLED
private static final int NOT_IN_QUEUE
private static final int UNMANAGED
private java.util.LinkedList<DocumentCache.RegistrationListener> _regListeners
| Constructor Detail |
|---|
public DocumentCache(int size)
public DocumentCache()
| Method Detail |
|---|
public DCacheAdapter register(OpenDefinitionsDocument odd,
DDReconstructor rec)
odd - The open definitions document that is registering. (Useful for debugging purposes.)rec - A reconstructor from which to create the document that is to be managed in this cache
public void setCacheSize(int size)
public int getCacheSize()
public int getNumInCache()
public java.lang.String toString()
toString in class java.lang.Objectpublic void addRegistrationListener(DocumentCache.RegistrationListener list)
public void removeRegistrationListener(DocumentCache.RegistrationListener list)
public void clearRegistrationListeners()
private void notifyRegistrationListeners(OpenDefinitionsDocument odd,
DocumentCache.DocManager man)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||