use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.
the class BufferedContentDiskDriver method getFileInformation.
@Override
public FileInfo getFileInformation(SrvSession sess, TreeConnection tree, String path) throws IOException {
ContentContext tctx = (ContentContext) tree.getContext();
FileInfo info = getFileInformationInternal(sess, tree, path);
/*
* Some information is not maintained by the repo and represents an in-progress update.
* For example as a file is being written the modification and access dates change.
*/
if (tctx.hasStateCache()) {
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState(path, false);
if (fstate != null) {
if (logger.isDebugEnabled()) {
logger.debug("state cache available - overwriting from state cache: isDirectory=" + info.isDirectory());
}
FileInfo finfo = new FileInfo();
finfo.copyFrom(info);
/**
* File state is probably stale for directories which is why we don't attempt to
* cache.
*/
if (!info.isDirectory()) {
/*
* What about stale file state values here?
*/
if (fstate.hasFileSize()) {
if (logger.isDebugEnabled()) {
logger.debug("replace file size " + info.getSize() + " with " + fstate.getFileSize());
}
finfo.setFileSize(fstate.getFileSize());
}
if (fstate.hasAccessDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace access date " + new Date(finfo.getAccessDateTime()) + " with " + new Date(fstate.getAccessDateTime()));
}
finfo.setAccessDateTime(fstate.getAccessDateTime());
}
if (fstate.hasChangeDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace change date " + new Date(finfo.getChangeDateTime()) + " with " + new Date(fstate.getChangeDateTime()));
}
finfo.setChangeDateTime(fstate.getChangeDateTime());
}
if (fstate.hasModifyDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace modified date " + new Date(finfo.getModifyDateTime()) + " with " + new Date(fstate.getModifyDateTime()));
}
finfo.setModifyDateTime(fstate.getModifyDateTime());
}
if (fstate.hasAllocationSize()) {
if (logger.isDebugEnabled()) {
logger.debug("replace allocation size" + finfo.getAllocationSize() + " with " + fstate.getAllocationSize());
}
finfo.setAllocationSize(fstate.getAllocationSize());
}
}
if (logger.isDebugEnabled()) {
logger.debug("Return getFileInformation, path: " + path + ", returning:" + finfo + ", readOnly:" + finfo.isReadOnly() + ", fileId:" + finfo.getFileId() + ", fileSize:" + finfo.getSize() + ", directoryId:" + finfo.getDirectoryId() + ", createdDate: " + new Date(finfo.getCreationDateTime()) + ", accessDate:" + new Date(finfo.getAccessDateTime()) + ", modifiedDate:" + new Date(finfo.getModifyDateTime()) + ", changeDate:" + new Date(finfo.getChangeDateTime()) + ", fileAttributes: 0x" + Integer.toHexString(info.getFileAttributes()) + ", mode: 0x" + Integer.toHexString(finfo.getMode()));
}
return finfo;
}
}
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation Return:" + path + " returning" + info);
}
return info;
}
use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.
the class InFlightCorrectorImpl method correct.
public void correct(FileInfo info, String folderPath) {
ContentContext tctx = (ContentContext) tree.getContext();
String path = folderPath + info.getFileName();
if (tctx.hasStateCache()) {
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState(path, true);
if (fstate != null) {
logger.debug("correct " + path);
/*
* What about stale file state values here?
*/
if (fstate.hasFileSize()) {
if (logger.isDebugEnabled()) {
logger.debug("replace file size " + info.getSize() + " with " + fstate.getFileSize());
}
info.setFileSize(fstate.getFileSize());
}
if (fstate.hasAccessDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace access date " + new Date(info.getAccessDateTime()) + " with " + new Date(fstate.getAccessDateTime()));
}
info.setAccessDateTime(fstate.getAccessDateTime());
}
if (fstate.hasChangeDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace change date " + new Date(info.getChangeDateTime()) + " with " + new Date(fstate.getChangeDateTime()));
}
info.setChangeDateTime(fstate.getChangeDateTime());
}
if (fstate.hasModifyDateTime()) {
if (logger.isDebugEnabled()) {
logger.debug("replace modified date " + new Date(info.getModifyDateTime()) + " with " + new Date(fstate.getModifyDateTime()));
}
info.setModifyDateTime(fstate.getModifyDateTime());
}
if (fstate.hasAllocationSize()) {
if (logger.isDebugEnabled()) {
logger.debug("replace allocation size" + info.getAllocationSize() + " with " + fstate.getAllocationSize());
}
info.setAllocationSize(fstate.getAllocationSize());
}
}
}
}
use of org.alfresco.jlan.server.filesys.cache.FileStateCache 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;
}
}
use of org.alfresco.jlan.server.filesys.cache.FileStateCache 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);
}
}
}
use of org.alfresco.jlan.server.filesys.cache.FileStateCache in project alfresco-repository by Alfresco.
the class LegacyFileStateDriver method setFileInformation.
@Override
public void setFileInformation(SrvSession sess, TreeConnection tree, String name, FileInfo info) throws IOException {
diskInterface.setFileInformation(sess, tree, name, info);
ContentContext tctx = (ContentContext) tree.getContext();
if (tctx.hasStateCache()) {
FileStateCache cache = tctx.getStateCache();
FileState fstate = cache.findFileState(name, true);
// }
if (info.hasSetFlag(FileInfo.SetModifyDate)) {
if (logger.isDebugEnabled()) {
logger.debug("Set modification date in file state cache" + name + ", " + info.getModifyDateTime());
}
Date modifyDate = new Date(info.getModifyDateTime());
fstate.updateModifyDateTime(modifyDate.getTime());
}
}
}
Aggregations