Search in sources :

Example 1 with FileAccessToken

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

the class LegacyFileStateDriver method createFile.

@Override
public NetworkFile createFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    FileStateCache cache = null;
    FileState fstate = null;
    FileAccessToken token = null;
    if (tctx.hasStateCache()) {
        cache = tctx.getStateCache();
        fstate = tctx.getStateCache().findFileState(params.getPath(), true);
        token = cache.grantFileAccess(params, fstate, FileStatus.NotExist);
        if (logger.isDebugEnabled()) {
            logger.debug("create file created lock token:" + token);
        }
    }
    try {
        NetworkFile newFile = diskInterface.createFile(sess, tree, params);
        int openCount = 1;
        if (newFile instanceof NetworkFileLegacyReferenceCount) {
            NetworkFileLegacyReferenceCount counter = (NetworkFileLegacyReferenceCount) newFile;
            openCount = counter.incrementLegacyOpenCount();
        }
        // This is the create so we store the first access token always
        newFile.setAccessToken(token);
        if (tctx.hasStateCache()) {
            fstate.setProcessId(params.getProcessId());
            fstate.setSharedAccess(params.getSharedAccess());
            // Indicate that the file is open
            fstate.setFileStatus(newFile.isDirectory() ? FileStatus.DirectoryExists : FileStatus.FileExists);
            long allocationSize = params.getAllocationSize();
            if (allocationSize > 0) {
                fstate.setAllocationSize(allocationSize);
                fstate.setFileSize(allocationSize);
            }
            if (newFile instanceof NodeRefNetworkFile) {
                NodeRefNetworkFile x = (NodeRefNetworkFile) newFile;
                x.setFileState(fstate);
            }
            if (newFile instanceof TempNetworkFile) {
                TempNetworkFile x = (TempNetworkFile) newFile;
                x.setFileState(fstate);
            }
        }
        if (newFile instanceof NodeRefNetworkFile) {
            NodeRefNetworkFile x = (NodeRefNetworkFile) newFile;
            x.setProcessId(params.getProcessId());
            x.setAccessToken(token);
        }
        if (newFile instanceof TempNetworkFile) {
            TempNetworkFile x = (TempNetworkFile) newFile;
            x.setAccessToken(token);
        }
        return newFile;
    } catch (IOException ie) {
        if (logger.isDebugEnabled()) {
            logger.debug("create file exception caught", ie);
        }
        if (tctx.hasStateCache() && token != null) {
            if (cache != null && fstate != null && token != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("create file release lock token:" + token);
                }
                cache.releaseFileAccess(fstate, token);
            }
        }
        throw ie;
    } catch (RuntimeException re) {
        // we could be out of memory or a NPE or some other unforseen situation.  JLAN will complain loudly ... as it should.
        if (logger.isDebugEnabled()) {
            logger.debug("create file exception caught", re);
        }
        if (tctx.hasStateCache() && token != null) {
            if (cache != null && fstate != null && token != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("create file release lock token:" + token);
                }
                cache.releaseFileAccess(fstate, token);
            }
        }
        throw re;
    }
}
Also used : FileStateCache(org.alfresco.jlan.server.filesys.cache.FileStateCache) FileState(org.alfresco.jlan.server.filesys.cache.FileState) NetworkFileLegacyReferenceCount(org.alfresco.filesys.alfresco.NetworkFileLegacyReferenceCount) IOException(java.io.IOException) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) FileAccessToken(org.alfresco.jlan.server.filesys.FileAccessToken)

Example 2 with FileAccessToken

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

the class LegacyFileStateDriver method openFile.

@Override
public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams params) throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    String path = params.getPath();
    boolean rollbackOpen = false;
    boolean rollbackToken = false;
    boolean rollbackCount = false;
    boolean rollbackSetToken = false;
    FileAccessToken token = null;
    FileStateCache cache = null;
    FileState fstate = null;
    NetworkFile openFile = null;
    if (tctx.hasStateCache()) {
        cache = tctx.getStateCache();
        fstate = tctx.getStateCache().findFileState(params.getPath(), true);
        if (!params.isDirectory()) {
            try {
                token = cache.grantFileAccess(params, fstate, FileStatus.Unknown);
            } catch (IOException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("UNABLE to grant file access for path:" + path + ", params" + params, e);
                }
                throw e;
            }
            rollbackToken = true;
            if (logger.isDebugEnabled()) {
                logger.debug("open file created lock token:" + token + ", for path:" + path);
            }
        }
    }
    try {
        openFile = diskInterface.openFile(sess, tree, params);
        rollbackOpen = true;
        if (openFile instanceof NetworkFileLegacyReferenceCount) {
            NetworkFileLegacyReferenceCount counter = (NetworkFileLegacyReferenceCount) openFile;
            int legacyOpenCount = counter.incrementLegacyOpenCount();
            if (logger.isDebugEnabled()) {
                logger.debug("openFile: legacyOpenCount: " + legacyOpenCount);
            }
            rollbackCount = true;
        } else {
            logger.debug("openFile does not implement NetworkFileLegacyReferenceCount");
        }
        if (openFile.hasAccessToken()) {
            // already has an access token, release the second token
            if (cache != null && fstate != null && token != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("already has access token, release lock token:" + token);
                }
                cache.releaseFileAccess(fstate, token);
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("store access token on open network file object token:" + token);
            }
            // first access token
            openFile.setAccessToken(token);
            rollbackSetToken = true;
        }
        if (tctx.hasStateCache()) {
            fstate = tctx.getStateCache().findFileState(path, true);
            fstate.setProcessId(params.getProcessId());
            fstate.setSharedAccess(params.getSharedAccess());
            // Access date time is read/write time not open time
            // fstate.updateAccessDateTime();
            fstate.setFileSize(openFile.getFileSize());
            fstate.updateChangeDateTime(openFile.getModifyDate());
            fstate.updateModifyDateTime(openFile.getModifyDate());
        }
        if (openFile instanceof ContentNetworkFile) {
            ContentNetworkFile x = (ContentNetworkFile) openFile;
            x.setProcessId(params.getProcessId());
            if (fstate != null) {
                x.setFileState(fstate);
                fstate.setFileStatus(FileStatus.FileExists);
            }
        } else if (openFile instanceof TempNetworkFile) {
            TempNetworkFile x = (TempNetworkFile) openFile;
            if (fstate != null) {
                x.setFileState(fstate);
                fstate.setFileStatus(FileStatus.FileExists);
            }
        } else if (openFile instanceof AlfrescoFolder) {
            AlfrescoFolder x = (AlfrescoFolder) openFile;
            if (fstate != null) {
                x.setFileState(fstate);
                fstate.setFileStatus(FileStatus.DirectoryExists);
            }
        } else if (openFile instanceof NetworkFile) {
            NetworkFile x = (NetworkFile) openFile;
            if (fstate != null) {
                // NetworkFile does not have setFileState
                // x.setFileState(fstate);
                fstate.setFileStatus(FileStatus.FileExists);
            }
        }
        rollbackToken = false;
        rollbackCount = false;
        rollbackSetToken = false;
        rollbackOpen = false;
        if (logger.isDebugEnabled()) {
            logger.debug("successfully opened file:" + openFile);
        }
        return openFile;
    } finally {
        if (rollbackToken) {
            if (logger.isDebugEnabled()) {
                logger.debug("rollback token:" + token);
            }
            if (cache != null && fstate != null && token != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("open file release lock token:" + token);
                }
                cache.releaseFileAccess(fstate, token);
            }
        }
        if (rollbackCount) {
            if (logger.isDebugEnabled()) {
                logger.debug("rollback legacy open count:" + token);
            }
            if (openFile instanceof NetworkFileLegacyReferenceCount) {
                NetworkFileLegacyReferenceCount counter = (NetworkFileLegacyReferenceCount) openFile;
                counter.decrementLagacyOpenCount();
            }
        }
        if (rollbackSetToken) {
            if (logger.isDebugEnabled()) {
                logger.debug("rollback set access token:" + token);
            }
            openFile.setAccessToken(null);
        }
        if (rollbackOpen) {
            if (logger.isDebugEnabled()) {
                logger.debug("rollback open:" + token);
            }
            diskInterface.closeFile(sess, tree, openFile);
        }
    }
}
Also used : FileState(org.alfresco.jlan.server.filesys.cache.FileState) IOException(java.io.IOException) NetworkFileLegacyReferenceCount(org.alfresco.filesys.alfresco.NetworkFileLegacyReferenceCount) FileAccessToken(org.alfresco.jlan.server.filesys.FileAccessToken) FileStateCache(org.alfresco.jlan.server.filesys.cache.FileStateCache) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile)

Example 3 with FileAccessToken

use of org.alfresco.jlan.server.filesys.FileAccessToken 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)

Aggregations

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