use of org.alfresco.jlan.server.locking.LockManager 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);
}
}
}
}
Aggregations