Search in sources :

Example 6 with FileStateCache

use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.

the class LegacyFileStateDriver method closeFile.

@Override
public void closeFile(SrvSession sess, TreeConnection tree, NetworkFile file) throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    FileStateCache cache = null;
    FileState fstate = null;
    if (logger.isDebugEnabled()) {
        logger.debug("closeFile:" + file.getFullName() + ", accessToken:" + file.getAccessToken());
    }
    int legacyOpenCount = 0;
    if (file instanceof NetworkFileLegacyReferenceCount) {
        NetworkFileLegacyReferenceCount counter = (NetworkFileLegacyReferenceCount) file;
        legacyOpenCount = counter.decrementLagacyOpenCount();
        if (logger.isDebugEnabled()) {
            logger.debug("closeFile: legacyOpenCount=" + legacyOpenCount);
        }
    } else {
        logger.debug("file to close does not implement NetworkFileLegacyReferenceCount");
    }
    try {
        if (file.hasOpLock()) {
            if (logger.isDebugEnabled()) {
                logger.debug("File Has OpLock - release oplock for closed file, file=" + file.getFullName());
            }
            // Release the oplock
            OpLockManager oplockMgr = opLockInterface.getOpLockManager(sess, tree);
            oplockMgr.releaseOpLock(file.getOpLock().getPath());
            if (logger.isDebugEnabled()) {
                logger.debug("Released oplock for closed file, file=" + file.getFullName());
            }
        }
        if (file.hasLocks()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Release all locks, file=" + file.getFullName());
            }
            LockManager lockMgr = fileLockingInterface.getLockManager(sess, tree);
            if (lockMgr != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Releasing locks for closed file, file=" + file.getFullName() + ", locks=" + file.numberOfLocks());
                }
                // Release all locks on the file owned by this session
                lockMgr.releaseLocksForFile(sess, tree, file);
            }
        }
        diskInterface.closeFile(sess, tree, file);
        logger.debug("file closed");
    } finally {
        if (tctx.hasStateCache()) {
            cache = tctx.getStateCache();
            fstate = cache.findFileState(file.getFullName(), true);
            if (legacyOpenCount == 0 || file.isForce()) {
                if (cache != null && fstate != null && file.getAccessToken() != null) {
                    FileAccessToken token = file.getAccessToken();
                    if (logger.isDebugEnabled() && token != null) {
                        logger.debug("close file, legacy count == 0 release access token:" + token);
                    }
                    cache.releaseFileAccess(fstate, token);
                    file.setAccessToken(null);
                }
            }
            if (fstate.getOpenCount() == 0) {
                logger.debug("fstate OpenCount == 0, reset in-flight state");
                fstate.setAllocationSize(-1);
                fstate.setFileSize(-1);
                fstate.updateChangeDateTime(0);
                fstate.updateModifyDateTime(0);
            }
        }
    }
}
Also used : FileStateCache(org.alfresco.jlan.server.filesys.cache.FileStateCache) FileState(org.alfresco.jlan.server.filesys.cache.FileState) LockManager(org.alfresco.jlan.server.locking.LockManager) OpLockManager(org.alfresco.jlan.server.locking.OpLockManager) NetworkFileLegacyReferenceCount(org.alfresco.filesys.alfresco.NetworkFileLegacyReferenceCount) OpLockManager(org.alfresco.jlan.server.locking.OpLockManager) FileAccessToken(org.alfresco.jlan.server.filesys.FileAccessToken)

Example 7 with FileStateCache

use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.

the class LegacyFileStateDriver method renameFile.

@Override
public void renameFile(SrvSession sess, TreeConnection tree, String oldName, String newName) throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    diskInterface.renameFile(sess, tree, oldName, newName);
    if (tctx.hasStateCache()) {
        FileStateCache cache = tctx.getStateCache();
        FileState fstate = cache.findFileState(oldName, false);
        if (fstate != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("rename file state from:" + oldName + ", to:" + newName);
            }
            cache.renameFileState(newName, fstate, fstate.isDirectory());
        }
    }
}
Also used : FileStateCache(org.alfresco.jlan.server.filesys.cache.FileStateCache) FileState(org.alfresco.jlan.server.filesys.cache.FileState)

Example 8 with FileStateCache

use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.

the class LegacyFileStateDriver method deleteFile.

@Override
public void deleteFile(SrvSession sess, TreeConnection tree, String name) throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    diskInterface.deleteFile(sess, tree, name);
    if (tctx.hasStateCache()) {
        FileStateCache cache = tctx.getStateCache();
        FileState fstate = cache.findFileState(name, false);
        if (fstate != null) {
            fstate.setFileStatus(FileStatus.NotExist);
            fstate.setOpenCount(0);
        }
    }
}
Also used : FileStateCache(org.alfresco.jlan.server.filesys.cache.FileStateCache) FileState(org.alfresco.jlan.server.filesys.cache.FileState)

Aggregations

FileState (org.alfresco.jlan.server.filesys.cache.FileState)8 FileStateCache (org.alfresco.jlan.server.filesys.cache.FileStateCache)8 Date (java.util.Date)3 NetworkFileLegacyReferenceCount (org.alfresco.filesys.alfresco.NetworkFileLegacyReferenceCount)3 FileAccessToken (org.alfresco.jlan.server.filesys.FileAccessToken)3 IOException (java.io.IOException)2 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)2 FileInfo (org.alfresco.jlan.server.filesys.FileInfo)1 LockManager (org.alfresco.jlan.server.locking.LockManager)1 OpLockManager (org.alfresco.jlan.server.locking.OpLockManager)1