edu.rice.cs.drjava.model.cache
Class DocumentCache.DocManager

java.lang.Object
  extended by edu.rice.cs.drjava.model.cache.DocumentCache.DocManager
All Implemented Interfaces:
DCacheAdapter
Enclosing class:
DocumentCache

private class DocumentCache.DocManager
extends Object
implements DCacheAdapter

Manages the retrieval of a document for a corresponding open definitions document. This manager only maintains its document data if it contained in _residentQueue, which is maintained using a round-robin replacement scheme.


Field Summary
private  DefinitionsDocument _doc
           
private  HashSet<String> _keywords
          Set of keywords if they were updated since the document had been kicked out, or null if not updated.
private  DDReconstructor _rec
           
private  int _stat
           
 
Constructor Summary
DocumentCache.DocManager(DDReconstructor rec, boolean isUntitled)
          Instantiates a manager for the documents that are produced by the given document reconstructor.
 
Method Summary
private  void add()
          Adds this DocManager to the queue and sets status to IN_QUEUE.
 void addDocumentListener(DocumentListener l)
          Adds DocumentListener to the reconstructor.
 void close()
          Closes the corresponding document for this adapter.
(package private)  void closingKickOut()
          Called by the cache when the document is being closed.
 void documentModified()
           
 void documentReset()
           
 void documentSaved()
          Updates status of this document in the cache.
 DefinitionsDocument getDocument()
          Gets the physical document (DD) for this manager.
 int getLength()
          Gets the length of this document using (i) cached _doc or (ii) reconstructor (which may force the document to be loaded.
 String getText()
          Gets the text of this document using the cached reconstructor if document is not resident or it is unchanged.
 String getText(int offset, int len)
           
 boolean isReady()
          Checks whether the document is resident (in the cache or modified).
private  boolean isUnmanagedOrUntitled()
          All of the following private methods presume that _cacheLock is held
(package private)  void kickOut()
          Called by the cache when the document is removed from the active queue and subject to virtualization.
private  void kickOut(boolean isClosing)
          Performs the actual kickOut operation.
private  DefinitionsDocument makeDocument()
          Makes this document; assumes that cacheLock is already held.
private  void remove()
          Removes this DocManager from the queue and sets status to NOT_IN_QUEUE.
 void setKeywords(Set<String> keywords)
          Set the specified keywords as keywords for syntax highlighting.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_rec

private final DDReconstructor _rec

_keywords

private volatile HashSet<String> _keywords
Set of keywords if they were updated since the document had been kicked out, or null if not updated.


_stat

private volatile int _stat

_doc

private volatile DefinitionsDocument _doc
Constructor Detail

DocumentCache.DocManager

public DocumentCache.DocManager(DDReconstructor rec,
                                boolean isUntitled)
Instantiates a manager for the documents that are produced by the given document reconstructor.

Parameters:
rec - The reconstructor used to create the document
Method Detail

addDocumentListener

public void addDocumentListener(DocumentListener l)
Adds DocumentListener to the reconstructor.

Specified by:
addDocumentListener in interface DCacheAdapter

makeDocument

private DefinitionsDocument makeDocument()
Makes this document; assumes that cacheLock is already held.


getDocument

public DefinitionsDocument getDocument()
                                throws IOException,
                                       FileMovedException
Gets the physical document (DD) for this manager. If DD is not in memory, it loads it from its image in its DDReconstructor and returns it. If the document has been modified in memory since it was last fetched, make it "unmanaged", removing it from the queue. It will remain in memory until saved. If a document is not in the queue, add it.

Specified by:
getDocument in interface DCacheAdapter
Returns:
the physical document that is managed by this adapter
Throws:
IOException
FileMovedException

getLength

public int getLength()
Gets the length of this document using (i) cached _doc or (ii) reconstructor (which may force the document to be loaded.

Specified by:
getLength in interface DCacheAdapter

getText

public String getText()
Gets the text of this document using the cached reconstructor if document is not resident or it is unchanged. If document is not locked, may return stale data.

Specified by:
getText in interface DCacheAdapter

getText

public String getText(int offset,
                      int len)
               throws BadLocationException
Specified by:
getText in interface DCacheAdapter
Throws:
BadLocationException

isReady

public boolean isReady()
Checks whether the document is resident (in the cache or modified).

Specified by:
isReady in interface DCacheAdapter
Returns:
if the document is resident.

close

public void close()
Closes the corresponding document for this adapter. Done when a document is closed by the navigator.

Specified by:
close in interface DCacheAdapter

documentModified

public void documentModified()
Specified by:
documentModified in interface DCacheAdapter

documentReset

public void documentReset()
Specified by:
documentReset in interface DCacheAdapter

documentSaved

public void documentSaved()
Updates status of this document in the cache.

Specified by:
documentSaved in interface DCacheAdapter

add

private void add()
Adds this DocManager to the queue and sets status to IN_QUEUE. Assumes _cacheLock is already held.


remove

private void remove()
Removes this DocManager from the queue and sets status to NOT_IN_QUEUE. Assumes _cacheLock is already held.


isUnmanagedOrUntitled

private boolean isUnmanagedOrUntitled()
All of the following private methods presume that _cacheLock is held


kickOut

void kickOut()
Called by the cache when the document is removed from the active queue and subject to virtualization. Assumes cacheLock is already held.


closingKickOut

void closingKickOut()
Called by the cache when the document is being closed. Note that _doc can be null in this case! Assumes cacheLock is already held.


kickOut

private void kickOut(boolean isClosing)
Performs the actual kickOut operation. Assumes cacheLock is already held.


toString

public String toString()
Overrides:
toString in class Object

setKeywords

public void setKeywords(Set<String> keywords)
Set the specified keywords as keywords for syntax highlighting.

Specified by:
setKeywords in interface DCacheAdapter
Parameters:
keywords - keywords to highlight