org.sourcejammer.project.model.filesys
Class NodeLibraryFS

java.lang.Object
  |
  +--org.sourcejammer.project.model.filesys.NodeLibraryFS
All Implemented Interfaces:
NodeLibrary

public class NodeLibraryFS
extends java.lang.Object
implements NodeLibrary

Title: $FileName: NodeLibraryFS.java$

Version:
$VerNum: 15$ $KeyWordsOff: $

Caching, retrieving, and storage of files, projects, versions, etc..
Author:
$AuthorName: Rob MacGrogan$

Nested Class Summary
static class NodeLibraryFS.NodeType
           
private static class NodeLibraryFS.XMLNodes
           
 
Field Summary
private  FSNodeCache fileCache
           
private  java.util.Random keyGenerator
           
private static java.lang.String LOCK_DIRECTORY
           
private static long LOCK_NUM_TRIES
           
private static long LOCK_RETRY_WAIT
           
private  FSNodeCache masterFileCache
           
private  ArchiveInfoFlexFS moArchiveInfo
           
private  FSNodeCache projectCache
           
 
Constructor Summary
NodeLibraryFS(ArchiveInfoFlexFS info)
           
 
Method Summary
private  void clearLocks()
          Clears all locks from lock directory.
private  org.w3c.dom.Document generateLockFile(long nodeID, java.lang.String nodeType, long lKey)
          Generates and returns a lock XML file.
 FileNode getFileNode(long nodeID)
          Retrieves and locks a File node on the file system.
private  java.io.File getLockFile(long nodeID, java.lang.String nodeType)
           
private  java.lang.String getLockFileName(long nodeID, java.lang.String nodeType)
          Builds the file name to use for the lock file for the specified node.
 MasterFileNode getMasterFileNode(long nodeID)
           
 FileNode getNewFileNodeFromModel()
          Subclasses should implement this to return a new FileNode object.
 MasterFileNode getNewMasterFileFromModel()
          Returns a new MasterFile object with unique id already set.
 ProjectNode getNewProjectFromModel()
          Subclasses should implement this to return a new ProjectNode object.
 long getNextVersionNodeID()
          Returns next unique ID for a version.
 java.lang.String getProjectChildName(ProjectChild child)
          Return the name of a project child object.
 ProjectNode getProjectNode(long nodeID)
          Retrieve or construct a ProjectNode based on it's node id.
 java.io.File getSourceFilePointer(org.sourcejammer.project.view.NodeInfo versionNode)
           
 java.io.File getVersionCommentPointer(org.sourcejammer.project.view.NodeInfo versionNode)
           
private  boolean isNodeLocked(long nodeID, java.lang.String nodeType)
          Returns true if node is already locked.
 long lockNode(ControllerNode nd)
          Locks the node and returns the key.
private  long lockNode(ControllerNode nd, long lTimeOutValue)
          Locks the node and returns the key used to lock it.
private  long lockNode(long nodeID, java.lang.String nodeType)
          Locks the node with the specified ID, if that node is not already locked.
 long lockNode(MasterFileNode nd)
          Locks the node and returns the key.
private  long lockNode(MasterFileNode nd, long lTimeOutValue)
          Locks the node and returns the key used to lock it.
private  long obtainLock(long nodeID, java.lang.String nodeType)
           
 void permanentlyDeleteFile(long fileID)
          Permanently remove all vestiges of specified file from filesystem.
 void permanentlyDeleteProject(long projectID)
          Only deleted the project file.
 void releaseNode(ControllerNode nd)
          Releases the node after use.
 void removeVersion(FileNode ndFile, long fileKey, long versionID)
          Remove all files assocaited with version from file system.
private  long retrieveKey(java.io.File fl)
          Retrieves key for the specified node.
 java.lang.String retrieveVersionComment(long versionID)
           
 Delta retrieveVersionDelta(org.sourcejammer.project.view.NodeInfo versionNode)
           
 java.io.File retrieveVersionDeltaFile(org.sourcejammer.project.view.NodeInfo versionNode)
           
 byte[] retrieveVersionFull(org.sourcejammer.project.view.NodeInfo versionNode)
           
 Delta retrieveVersionTextDelta(org.sourcejammer.project.view.NodeInfo versionNode)
           
 TextLineReader retrieveVersionTextLineReader(org.sourcejammer.project.view.NodeInfo versionNode)
          When implemented, this method returns the full source of the specified VersionNode as a TextLineReader.
 void storeVersionComment(FileNode ndFile, long fileKey, long versionID, java.lang.String comment)
           
 void storeVersionDelta(FileNode ndFile, long fileKey, org.sourcejammer.project.view.NodeInfo versionNode, java.io.File file)
          Subclasses should implement to store file delta in the model implementation.
 void storeVersionFull(FileNode ndFile, long fileKey, org.sourcejammer.project.view.NodeInfo versionNode, java.io.File file)
          Subclasses should implement to store version file in the model implementation.
 void storeVersionTextDiff(FileNode ndFile, long fileKey, org.sourcejammer.project.view.NodeInfo versionNode, TextDiff file)
           
protected  void unlockNode(ControllerNode nd)
           
protected  void unlockNode(long nodeID, java.lang.String nodeType, long key)
          Unlocks the node with the specified ID and type, using the key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_DIRECTORY

private static final java.lang.String LOCK_DIRECTORY
See Also:
Constant Field Values

LOCK_RETRY_WAIT

private static final long LOCK_RETRY_WAIT
See Also:
Constant Field Values

LOCK_NUM_TRIES

private static final long LOCK_NUM_TRIES
See Also:
Constant Field Values

moArchiveInfo

private ArchiveInfoFlexFS moArchiveInfo

keyGenerator

private java.util.Random keyGenerator

fileCache

private FSNodeCache fileCache

projectCache

private FSNodeCache projectCache

masterFileCache

private FSNodeCache masterFileCache
Constructor Detail

NodeLibraryFS

public NodeLibraryFS(ArchiveInfoFlexFS info)
Method Detail

obtainLock

private long obtainLock(long nodeID,
                        java.lang.String nodeType)
                 throws ObjectLockingException
ObjectLockingException

lockNode

private long lockNode(long nodeID,
                      java.lang.String nodeType)
               throws ObjectLockingException
Locks the node with the specified ID, if that node is not already locked.

Parameters:
nodeID - -- unique ID of the node.
Returns:
-- the key to use in setting values in the node and in unlocking it.
Throws:
ObjectLockingException - if the node is already locked.

clearLocks

private void clearLocks()
Clears all locks from lock directory. Should only run on start up of server.


unlockNode

protected void unlockNode(long nodeID,
                          java.lang.String nodeType,
                          long key)
                   throws ObjectLockingException
Unlocks the node with the specified ID and type, using the key.

Parameters:
nodeID - -- unique id of the node.
Throws:
ObjectLockingException - if the node is not locked, or if the key is inaccurate.

getProjectNode

public ProjectNode getProjectNode(long nodeID)
                           throws FileAccessException,
                                  ProjectDoesNotExistException,
                                  SecurityException
Description copied from interface: NodeLibrary
Retrieve or construct a ProjectNode based on it's node id.

Specified by:
getProjectNode in interface NodeLibrary
FileAccessException
ProjectDoesNotExistException
SecurityException

getProjectChildName

public java.lang.String getProjectChildName(ProjectChild child)
                                     throws FileAccessException,
                                            org.sourcejammer.project.NodeDoesNotExistException
Return the name of a project child object. First checks cache. Then checks filesystem. Does not add child Node to cache.

Specified by:
getProjectChildName in interface NodeLibrary
FileAccessException
org.sourcejammer.project.NodeDoesNotExistException

getMasterFileNode

public MasterFileNode getMasterFileNode(long nodeID)
                                 throws FileAccessException,
                                        FileDoesNotExistException,
                                        SecurityException
Specified by:
getMasterFileNode in interface NodeLibrary
FileAccessException
FileDoesNotExistException
SecurityException

getFileNode

public FileNode getFileNode(long nodeID)
                     throws FileAccessException,
                            FileDoesNotExistException,
                            SecurityException
Retrieves and locks a File node on the file system.

Specified by:
getFileNode in interface NodeLibrary
FileAccessException
FileDoesNotExistException
SecurityException

releaseNode

public void releaseNode(ControllerNode nd)
                 throws FileAccessException
Description copied from interface: NodeLibrary
Releases the node after use.

Specified by:
releaseNode in interface NodeLibrary
FileAccessException

unlockNode

protected void unlockNode(ControllerNode nd)
                   throws FileAccessException
FileAccessException

getLockFileName

private java.lang.String getLockFileName(long nodeID,
                                         java.lang.String nodeType)
Builds the file name to use for the lock file for the specified node.


isNodeLocked

private boolean isNodeLocked(long nodeID,
                             java.lang.String nodeType)
Returns true if node is already locked. False otherwise.


generateLockFile

private org.w3c.dom.Document generateLockFile(long nodeID,
                                              java.lang.String nodeType,
                                              long lKey)
Generates and returns a lock XML file.


retrieveKey

private long retrieveKey(java.io.File fl)
                  throws java.io.IOException,
                         org.xml.sax.SAXException
Retrieves key for the specified node.

java.io.IOException
org.xml.sax.SAXException

getLockFile

private java.io.File getLockFile(long nodeID,
                                 java.lang.String nodeType)

permanentlyDeleteProject

public void permanentlyDeleteProject(long projectID)
                              throws SecurityException,
                                     ProjectDoesNotExistException,
                                     FileAccessException
Only deleted the project file. It is up to the calling routine to delete any file object, as needed.

Specified by:
permanentlyDeleteProject in interface NodeLibrary
SecurityException
ProjectDoesNotExistException
FileAccessException

permanentlyDeleteFile

public void permanentlyDeleteFile(long fileID)
                           throws SecurityException,
                                  FileDoesNotExistException,
                                  FileAccessException
Permanently remove all vestiges of specified file from filesystem. This method does the following:

  • Removes file from all parents
  • Removes file from removed listing in all parents from which it has already been removed
  • Deletes all source and comment files
  • Deletes file itself
  • Removes File object from cache.
  • Specified by:
    permanentlyDeleteFile in interface NodeLibrary
    SecurityException
    FileDoesNotExistException
    FileAccessException

    storeVersionFull

    public void storeVersionFull(FileNode ndFile,
                                 long fileKey,
                                 org.sourcejammer.project.view.NodeInfo versionNode,
                                 java.io.File file)
                          throws FileAccessException
    Subclasses should implement to store version file in the model implementation. FileNode must be locked and passed key must "fit" the FileNode, or SecurityException is thrown.

    Specified by:
    storeVersionFull in interface NodeLibrary
    FileAccessException

    storeVersionDelta

    public void storeVersionDelta(FileNode ndFile,
                                  long fileKey,
                                  org.sourcejammer.project.view.NodeInfo versionNode,
                                  java.io.File file)
                           throws FileAccessException
    Subclasses should implement to store file delta in the model implementation. FileNode must be locked and passed key must "fit" the FileNode, or SecurityException is thrown.

    Specified by:
    storeVersionDelta in interface NodeLibrary
    FileAccessException

    storeVersionTextDiff

    public void storeVersionTextDiff(FileNode ndFile,
                                     long fileKey,
                                     org.sourcejammer.project.view.NodeInfo versionNode,
                                     TextDiff file)
                              throws FileAccessException
    Specified by:
    storeVersionTextDiff in interface NodeLibrary
    FileAccessException

    getNewMasterFileFromModel

    public MasterFileNode getNewMasterFileFromModel()
                                             throws FileAccessException
    Returns a new MasterFile object with unique id already set.

    Specified by:
    getNewMasterFileFromModel in interface NodeLibrary
    FileAccessException

    getNewProjectFromModel

    public ProjectNode getNewProjectFromModel()
                                       throws FileAccessException
    Subclasses should implement this to return a new ProjectNode object. Unique ID for new project will be already be set in returned Node.

    Specified by:
    getNewProjectFromModel in interface NodeLibrary
    FileAccessException

    getNewFileNodeFromModel

    public FileNode getNewFileNodeFromModel()
                                     throws FileAccessException
    Subclasses should implement this to return a new FileNode object. Unique Id for file will already be set in returned Node.

    Specified by:
    getNewFileNodeFromModel in interface NodeLibrary
    FileAccessException

    getNextVersionNodeID

    public long getNextVersionNodeID()
                              throws FileAccessException
    Returns next unique ID for a version.

    Specified by:
    getNextVersionNodeID in interface NodeLibrary
    FileAccessException

    storeVersionComment

    public void storeVersionComment(FileNode ndFile,
                                    long fileKey,
                                    long versionID,
                                    java.lang.String comment)
                             throws FileAccessException
    Specified by:
    storeVersionComment in interface NodeLibrary
    FileAccessException

    retrieveVersionComment

    public java.lang.String retrieveVersionComment(long versionID)
                                            throws FileAccessException
    Specified by:
    retrieveVersionComment in interface NodeLibrary
    FileAccessException

    getSourceFilePointer

    public java.io.File getSourceFilePointer(org.sourcejammer.project.view.NodeInfo versionNode)
    Specified by:
    getSourceFilePointer in interface NodeLibrary

    getVersionCommentPointer

    public java.io.File getVersionCommentPointer(org.sourcejammer.project.view.NodeInfo versionNode)
    Specified by:
    getVersionCommentPointer in interface NodeLibrary

    retrieveVersionFull

    public byte[] retrieveVersionFull(org.sourcejammer.project.view.NodeInfo versionNode)
                               throws FileAccessException,
                                      WrongFileTypeException
    Specified by:
    retrieveVersionFull in interface NodeLibrary
    FileAccessException
    WrongFileTypeException

    retrieveVersionTextLineReader

    public TextLineReader retrieveVersionTextLineReader(org.sourcejammer.project.view.NodeInfo versionNode)
                                                 throws FileAccessException,
                                                        WrongFileTypeException,
                                                        org.sourcejammer.util.SourceJammerVersionException
    When implemented, this method returns the full source of the specified VersionNode as a TextLineReader. This method should only be called for files stored as Text. Implementing classes should throw WrongFileType if the underlying file is not text.

    Specified by:
    retrieveVersionTextLineReader in interface NodeLibrary
    FileAccessException
    WrongFileTypeException
    org.sourcejammer.util.SourceJammerVersionException

    retrieveVersionDeltaFile

    public java.io.File retrieveVersionDeltaFile(org.sourcejammer.project.view.NodeInfo versionNode)
                                          throws FileAccessException,
                                                 WrongFileTypeException
    Specified by:
    retrieveVersionDeltaFile in interface NodeLibrary
    FileAccessException
    WrongFileTypeException

    retrieveVersionDelta

    public Delta retrieveVersionDelta(org.sourcejammer.project.view.NodeInfo versionNode)
                               throws FileAccessException,
                                      WrongFileTypeException
    Specified by:
    retrieveVersionDelta in interface NodeLibrary
    FileAccessException
    WrongFileTypeException

    retrieveVersionTextDelta

    public Delta retrieveVersionTextDelta(org.sourcejammer.project.view.NodeInfo versionNode)
                                   throws FileAccessException,
                                          WrongFileTypeException
    Specified by:
    retrieveVersionTextDelta in interface NodeLibrary
    FileAccessException
    WrongFileTypeException

    lockNode

    public long lockNode(MasterFileNode nd)
                  throws SecurityException
    Locks the node and returns the key. Times out after default number of milliseconds.

    Specified by:
    lockNode in interface NodeLibrary
    SecurityException

    lockNode

    private long lockNode(MasterFileNode nd,
                          long lTimeOutValue)
                   throws SecurityException
    Locks the node and returns the key used to lock it. Calling routines MUST remember to UNLOCK the node when they are done with it. Method waits for node to unlock for lTimeOutValue milliseconds.

    SecurityException

    lockNode

    public long lockNode(ControllerNode nd)
                  throws SecurityException
    Locks the node and returns the key. Times out after default number of milliseconds.

    Specified by:
    lockNode in interface NodeLibrary
    SecurityException

    lockNode

    private long lockNode(ControllerNode nd,
                          long lTimeOutValue)
                   throws SecurityException
    Locks the node and returns the key used to lock it. Calling routines MUST remember to UNLOCK the node when they are done with it. Method waits for node to unlock for lTimeOutValue milliseconds.

    SecurityException

    removeVersion

    public void removeVersion(FileNode ndFile,
                              long fileKey,
                              long versionID)
                       throws FileAccessException,
                              NoSuchVersionException
    Remove all files assocaited with version from file system.

    Specified by:
    removeVersion in interface NodeLibrary
    FileAccessException
    NoSuchVersionException


    Copyright 2003 Soucejammer project.