Refactoring of the pseudo file/desktop action code to allow use by AVM and repo filesystem drivers.

Added virtualization view to the AVM filesystem driver that shows all stores and versions using a single
shared filesystem.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4443 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gary Spencer
2006-11-27 09:39:49 +00:00
parent 0eda95cc5f
commit a2a543684b
39 changed files with 2153 additions and 871 deletions

View File

@@ -17,11 +17,10 @@
package org.alfresco.filesys.avm;
import org.alfresco.filesys.server.filesys.DiskDeviceContext;
import org.alfresco.filesys.alfresco.AlfrescoContext;
import org.alfresco.filesys.alfresco.IOControlHandler;
import org.alfresco.filesys.server.filesys.DiskInterface;
import org.alfresco.filesys.server.filesys.FileSystem;
import org.alfresco.filesys.server.filesys.SrvDiskInfo;
import org.alfresco.filesys.server.state.FileStateReaper;
import org.alfresco.filesys.server.state.FileStateTable;
/**
* AVM Filesystem Context Class
@@ -30,7 +29,7 @@ import org.alfresco.filesys.server.state.FileStateTable;
*
* @author GKSpencer
*/
public class AVMContext extends DiskDeviceContext {
public class AVMContext extends AlfrescoContext {
// Constants
//
@@ -43,14 +42,18 @@ public class AVMContext extends DiskDeviceContext {
private String m_storePath;
private int m_version = VERSION_HEAD;
// File state table and associated file state reaper
private FileStateTable m_stateTable;
private FileStateReaper m_stateReaper;
// Flag to indicate if the virtualization view is enabled
//
// The first set of folders then map to the stores and the second layer map to the versions with
// paths below.
private boolean m_virtualView;
/**
* Class constructor
*
* <p>Construct a context for a normal view onto a single store/version within AVM.
*
* @param filesysName String
* @param storePath String
* @param version int
@@ -68,17 +71,24 @@ public class AVMContext extends DiskDeviceContext {
// Set the store version to use
m_version = version;
// Default the filesystem to look like an 80Gb sized disk with 90% free space
setDiskInformation(new SrvDiskInfo(2560000, 64, 512, 2304000));
// Set filesystem parameters
setFilesystemAttributes(FileSystem.CasePreservedNames + FileSystem.UnicodeOnDisk +
FileSystem.CaseSensitiveSearch);
}
/**
* Class constructor
*
* <p>Construct a context for a virtualization view onto all stores/versions within AVM.
*
* @param filesysName String
*/
public AVMContext( String filesysName)
{
super( filesysName, "VirtualView");
// Enable the virtualization view
m_virtualView = true;
}
/**
* Return the filesystem type, either FileSystem.TypeFAT or FileSystem.TypeNTFS.
*
@@ -109,69 +119,34 @@ public class AVMContext extends DiskDeviceContext {
return m_version;
}
/**
* Check if the virtualization view is enabled
*
* @return boolean
*/
public final boolean isVirtualizationView()
{
return m_virtualView;
}
/**
* Close the filesystem context
*/
public void CloseContext() {
// Deregister the file state table from the reaper
if ( m_stateTable != null)
enableStateTable( false, m_stateReaper);
// Call the base class
super.CloseContext();
}
/**
* Determine if the file state table is enabled
* Create the I/O control handler for this filesystem type
*
* @return boolean
* @param filesysDriver DiskInterface
* @return IOControlHandler
*/
public final boolean hasStateTable()
protected IOControlHandler createIOHandler( DiskInterface filesysDriver)
{
return m_stateTable != null ? true : false;
}
/**
* Return the file state table
*
* @return FileStateTable
*/
public final FileStateTable getStateTable()
{
return m_stateTable;
}
/**
* Enable/disable the file state table
*
* @param ena boolean
* @param stateReaper FileStateReaper
*/
public final void enableStateTable(boolean ena, FileStateReaper stateReaper)
{
if ( ena == false)
{
// Remove the state table from the reaper
stateReaper.removeStateTable( getFilesystemName());
m_stateTable = null;
}
else if ( m_stateTable == null)
{
// Create the file state table
m_stateTable = new FileStateTable();
// Register with the file state reaper
stateReaper.addStateTable( getFilesystemName(), m_stateTable);
}
// Save the reaper, for deregistering when the filesystem is closed
m_stateReaper = stateReaper;
return null;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,6 @@ import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.smb.SeekType;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.apache.commons.logging.Log;

View File

@@ -36,11 +36,12 @@ public class AVMPath {
// Version id string for the head version
private static final String VersionNameHead = "Head";
public static final String VersionNameHead = "Head";
// AVM path seperator
public static final char AVM_SEPERATOR = '/';
public static final char AVM_SEPERATOR = '/';
public static final String AVM_SEPERATOR_STR = "/";
// Store name
@@ -57,9 +58,18 @@ public class AVMPath {
// AVM style path
private String m_avmPath;
/**
* Default constructor
*/
public AVMPath()
{
}
/**
* Class constructor
*
* <p>Construct an AVM path for the virtualization view, with store and version folders
*
* @param shrPath String
*/
@@ -69,6 +79,22 @@ public class AVMPath {
parsePath( shrPath);
}
/**
* Class constructor
*
* <p>Construct an AVM path for a standard view onto a store/version
*
* @param storeName String
* @param version int
* @param path String
*/
public AVMPath(String storeName, int version, String path)
{
// Parse the path
parsePath( storeName, version, path);
}
/**
* Return the store name
@@ -100,6 +126,28 @@ public class AVMPath {
return m_version;
}
/**
* Return the version as a string
*
* @return String
*/
public final String getVersionString()
{
if ( m_version == -1)
return VersionNameHead;
return "" + m_version;
}
/**
* Check if there is a share relative path
*
* @return boolean
*/
public final boolean hasRelativePath()
{
return m_path != null ? true : false;
}
/**
* Return the share relative path
*
@@ -127,22 +175,54 @@ public class AVMPath {
*/
public final boolean isValid()
{
return m_storeName == null ? false : true;
return m_storeName == null && m_path == null ? false : true;
}
/**
* Parse the path
* Check if the path is to a pseudo folder in the virtualization view
*
* @return boolean
*/
public final boolean isPseudoPath()
{
return m_version == InvalidVersionId || m_path == null ? true : false;
}
/**
* Check if the path is the root path
*
* @return boolean
*/
public final boolean isRootPath()
{
if ( m_path != null && m_path.equals( FileName.DOS_SEPERATOR_STR))
return true;
return false;
}
/**
* Parse the path, for the virtualization view onto all stores/versions
*
* @param path String
*/
private final void parsePath( String path)
public final void parsePath( String path)
{
// Clear current settings
m_storeName = null;
m_version = InvalidVersionId;
m_path = null;
m_avmPath = null;
// Split the path
String[] paths = FileName.splitAllPaths(path);
if ( paths == null || paths.length == 0)
{
m_path = FileName.DOS_SEPERATOR_STR;
return;
}
// Set the store name
@@ -204,11 +284,78 @@ public class AVMPath {
pathStr.append( ":");
pathStr.append( m_path.replace( FileName.DOS_SEPERATOR, AVM_SEPERATOR));
m_avmPath = pathStr.toString();
}
else
{
// Share relative path is the root of the share
m_path = FileName.DOS_SEPERATOR_STR;
// Build the AVM path
StringBuilder pathStr = new StringBuilder();
pathStr.append( m_storeName);
pathStr.append( ":/");
m_avmPath = pathStr.toString();
}
}
}
/**
* Parse the path, to generate a path for a single store/version
*
* @param storeName String
* @param version int
* @param path String
*/
public final void parsePath( String storeName, int version, String path)
{
// Clear current settings
m_storeName = null;
m_version = InvalidVersionId;
m_path = null;
m_avmPath = null;
// Set the store/version
m_storeName = storeName;
m_version = version;
// Save the relative path
m_path = path;
// Build the store path
StringBuilder avmPath = new StringBuilder();
avmPath.append( m_storeName);
if ( storeName.indexOf( ":") == -1)
avmPath.append( ":");
if ( path == null || path.length() == 0)
{
avmPath.append( AVM_SEPERATOR);
// Set the share relative path as the root path
m_path = FileName.DOS_SEPERATOR_STR;
}
else
{
if ( path.startsWith( FileName.DOS_SEPERATOR_STR) == false)
avmPath.append( AVM_SEPERATOR);
avmPath.append( path.replace( FileName.DOS_SEPERATOR, AVM_SEPERATOR));
}
m_avmPath = avmPath.toString();
}
/**
* Return the AVM path details as a string
*

View File

@@ -17,9 +17,6 @@
package org.alfresco.filesys.avm;
import java.util.Collection;
import java.util.SortedMap;
import org.alfresco.filesys.server.filesys.FileAttribute;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.SearchContext;

View File

@@ -29,9 +29,7 @@ import org.alfresco.filesys.server.core.ShareMapper;
import org.alfresco.filesys.server.core.ShareType;
import org.alfresco.filesys.server.core.SharedDevice;
import org.alfresco.filesys.server.core.SharedDeviceList;
import org.alfresco.filesys.server.filesys.DiskDeviceContext;
import org.alfresco.filesys.server.filesys.DiskSharedDevice;
import org.alfresco.filesys.server.filesys.SrvDiskInfo;
import org.alfresco.filesys.util.StringList;
import org.alfresco.service.cmr.avm.AVMNotFoundException;
import org.alfresco.service.cmr.avm.AVMService;

View File

@@ -0,0 +1,282 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.avm;
import org.alfresco.filesys.server.filesys.FileAttribute;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.SearchContext;
import org.alfresco.filesys.server.pseudo.PseudoFile;
import org.alfresco.filesys.server.pseudo.PseudoFileList;
import org.alfresco.filesys.util.WildCard;
/**
* Pseudo File List Search Context Class
*
* <p>Returns files from a pseudo file list for a wildcard search.
*
* @author gkspencer
*/
public class PseudoFileListSearchContext extends SearchContext {
// Pseudo file list and current index
private PseudoFileList m_fileList;
private int m_fileIdx;
// File attributes
private int m_attrib;
// Optional wildcard filter
private WildCard m_filter;
/**
* Class constructor
*
* @param fileList PseudoFileList
* @param attrib int
* @param filter WildCard
*/
public PseudoFileListSearchContext( PseudoFileList fileList, int attrib, WildCard filter)
{
m_attrib = attrib;
m_filter = filter;
m_fileList = fileList;
}
/**
* Determine if there are more files for the active search.
*
* @return boolean
*/
public boolean hasMoreFiles()
{
return m_fileIdx < m_fileList.numberOfFiles() ? true : false;
}
/**
* Return file information for the next file in the active search. Returns false if the search
* is complete.
*
* @param info FileInfo to return the file information.
* @return true if the file information is valid, else false
*/
public boolean nextFileInfo(FileInfo info)
{
// Check if there is another file record to return
if ( m_fileIdx >= m_fileList.numberOfFiles())
return false;
// Search for the next valid file
boolean foundMatch = false;
PseudoFile curFile = null;
while (foundMatch == false && m_fileIdx < m_fileList.numberOfFiles())
{
// Get the next file from the list
curFile = m_fileList.getFileAt( m_fileIdx++);
// Check if the file name matches the search pattern
if ( m_filter != null)
{
// Check if the current file matches the wildcard pattern
if ( m_filter.matchesPattern(curFile.getFileName()) == true)
{
// Check if the file matches the search attributes
if (FileAttribute.hasAttribute(m_attrib, FileAttribute.Directory) &&
curFile.isDirectory())
{
// Found a match
foundMatch = true;
}
else if ( curFile.isFile())
{
// Found a match
foundMatch = true;
}
// Check if we found a match
if ( foundMatch == false)
{
// Get the next file from the list
if ( ++m_fileIdx < m_fileList.numberOfFiles())
curFile = m_fileList.getFileAt( m_fileIdx);
}
}
}
else
foundMatch = true;
}
// If we found a match then fill in the file information
if ( foundMatch)
{
// Fill in the file information
info.setFileName( curFile.getFileName());
// Get the file information from the pseudo file
FileInfo pfInfo = curFile.getFileInfo();
if ( curFile.isFile())
{
info.setFileSize( pfInfo.getSize());
info.setAllocationSize( pfInfo.getAllocationSize());
}
else
info.setFileSize( 0L);
info.setAccessDateTime( pfInfo.getAccessDateTime());
info.setCreationDateTime( pfInfo.getCreationDateTime());
info.setModifyDateTime( pfInfo.getModifyDateTime());
// Build the file attributes
int attr = pfInfo.getFileAttributes();
if ( pfInfo.isHidden() == false &&
curFile.getFileName().startsWith( ".") ||
curFile.getFileName().equalsIgnoreCase( "Desktop.ini") ||
curFile.getFileName().equalsIgnoreCase( "Thumbs.db"))
attr += FileAttribute.Hidden;
info.setFileAttributes( attr);
}
// Indicate if the file information is valid
return foundMatch;
}
/**
* Return the file name of the next file in the active search. Returns null is the search is
* complete.
*
* @return String
*/
public String nextFileName()
{
// Check if there is another file record to return
// Find the next matching file name
while ( m_fileIdx < m_fileList.numberOfFiles()) {
// Check if the current file name matches the search pattern
String fname = m_fileList.getFileAt( m_fileIdx++).getFileName();
if ( m_filter.matchesPattern(fname))
return fname;
}
// No more matching file names
return null;
}
/**
* Return the total number of file entries for this search if known, else return -1
*
* @return int
*/
public int numberOfEntries()
{
return m_fileList.numberOfFiles();
}
/**
* Return the resume id for the current file/directory in the search.
*
* @return int
*/
public int getResumeId()
{
return m_fileIdx;
}
/**
* Restart a search at the specified resume point.
*
* @param resumeId Resume point id.
* @return true if the search can be restarted, else false.
*/
public boolean restartAt(int resumeId)
{
// Range check the resume id
int resId = resumeId - 1;
if ( resId < 0 || resId >= m_fileList.numberOfFiles())
return false;
// Reset the current file index
m_fileIdx = resId;
return true;
}
/**
* Restart the current search at the specified file.
*
* @param info File to restart the search at.
* @return true if the search can be restarted, else false.
*/
public boolean restartAt(FileInfo info)
{
// Search backwards from the current file
int curFileIdx = m_fileIdx;
if (m_fileIdx >= m_fileList.numberOfFiles())
{
m_fileIdx = m_fileList.numberOfFiles() - 1;
}
while ( m_fileIdx > 0) {
// Check if the current file is the required search restart point
if ( m_fileList.getFileAt( m_fileIdx).getFileName().equals( info.getFileName()))
return true;
else
m_fileIdx--;
}
// Failed to find the restart file
m_fileIdx = curFileIdx;
return false;
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.avm;
import org.alfresco.filesys.server.filesys.FileAttribute;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.FileName;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.server.pseudo.PseudoFile;
import org.alfresco.filesys.server.pseudo.PseudoFolderNetworkFile;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
/**
* Store Pseudo File Class
*
* <p>Represents an AVM store as a folder.
*
* @author gkspencer
*/
public class StorePseudoFile extends PseudoFile {
/**
* Class constructor
*
* @param storeDesc AVMStoreDescriptor
*/
public StorePseudoFile( AVMStoreDescriptor storeDesc)
{
super( storeDesc.getName(), FileAttribute.Directory + FileAttribute.ReadOnly);
// Create static file information from the store details
FileInfo fInfo = new FileInfo( storeDesc.getName(), 0L, FileAttribute.Directory + FileAttribute.ReadOnly);
fInfo.setCreationDateTime( storeDesc.getCreateDate());
setFileInfo( fInfo);
}
/**
* Return a network file for reading/writing the pseudo file
*
* @param netPath String
* @return NetworkFile
*/
@Override
public NetworkFile getFile(String netPath) {
// Split the path to get the name
String[] paths = FileName.splitPath( netPath);
// Create a network file for the folder
return new PseudoFolderNetworkFile( paths[1], netPath);
}
/**
* Return the file information for the pseudo file
*
* @return FileInfo
*/
@Override
public FileInfo getFileInfo() {
return getInfo();
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.avm;
import org.alfresco.filesys.server.filesys.FileAttribute;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.FileName;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.server.pseudo.PseudoFile;
import org.alfresco.filesys.server.pseudo.PseudoFolderNetworkFile;
import org.alfresco.service.cmr.avm.VersionDescriptor;
/**
* Version Pseudo File Class
*
* <p>Represents an AVM store version as a folder.
*
* @author gkspencer
*/
public class VersionPseudoFile extends PseudoFile {
/**
* Class constructor
*
* @param name String
*/
public VersionPseudoFile( String name)
{
super( name, FileAttribute.Directory + FileAttribute.ReadOnly);
// Create static file information from the store details
FileInfo fInfo = new FileInfo( name, 0L, FileAttribute.Directory + FileAttribute.ReadOnly);
setFileInfo( fInfo);
}
/**
* Class constructor
*
* @param name String
* @param verDesc VersionDescriptor
*/
public VersionPseudoFile( String name, VersionDescriptor verDesc)
{
super( name, FileAttribute.Directory + FileAttribute.ReadOnly);
// Create static file information from the store details
FileInfo fInfo = new FileInfo( name, 0L, FileAttribute.Directory + FileAttribute.ReadOnly);
fInfo.setCreationDateTime( verDesc.getCreateDate());
setFileInfo( fInfo);
}
/**
* Return a network file for reading/writing the pseudo file
*
* @param netPath String
* @return NetworkFile
*/
@Override
public NetworkFile getFile(String netPath) {
// Split the path to get the name
String[] paths = FileName.splitPath( netPath);
// Create a network file for the folder
return new PseudoFolderNetworkFile( paths[1], netPath);
}
/**
* Return the file information for the pseudo file
*
* @return FileInfo
*/
@Override
public FileInfo getFileInfo() {
return getInfo();
}
}