mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Checkpoint of file state refactoring.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4417 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,6 +20,8 @@ package org.alfresco.filesys.avm;
|
||||
import org.alfresco.filesys.server.filesys.DiskDeviceContext;
|
||||
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
|
||||
@@ -41,15 +43,21 @@ 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;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param filesysName String
|
||||
* @param storePath String
|
||||
* @param version int
|
||||
*/
|
||||
public AVMContext( String storePath, int version)
|
||||
public AVMContext( String filesysName, String storePath, int version)
|
||||
{
|
||||
super( storePath + "(" + version + ")");
|
||||
super( filesysName, storePath + "(" + version + ")");
|
||||
|
||||
// Set the store root path, remove any trailing slash as relative paths will be appended to this value
|
||||
|
||||
@@ -106,8 +114,64 @@ public class AVMContext extends DiskDeviceContext {
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean hasStateTable()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.filesys.server.SrvSession;
|
||||
import org.alfresco.filesys.server.core.DeviceContext;
|
||||
import org.alfresco.filesys.server.core.DeviceContextException;
|
||||
import org.alfresco.filesys.server.core.DeviceInterface;
|
||||
import org.alfresco.filesys.server.filesys.AccessDeniedException;
|
||||
import org.alfresco.filesys.server.filesys.DirectoryNotEmptyException;
|
||||
import org.alfresco.filesys.server.filesys.DiskInterface;
|
||||
@@ -40,6 +41,7 @@ import org.alfresco.filesys.server.filesys.FileStatus;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
import org.alfresco.filesys.server.filesys.SearchContext;
|
||||
import org.alfresco.filesys.server.filesys.TreeConnection;
|
||||
import org.alfresco.filesys.server.state.FileStateReaper;
|
||||
import org.alfresco.filesys.util.StringList;
|
||||
import org.alfresco.filesys.util.WildCard;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
@@ -93,6 +95,10 @@ public class AVMDiskDriver implements DiskInterface {
|
||||
|
||||
private ServiceRegistry m_serviceRegistry;
|
||||
|
||||
// File state reaper
|
||||
|
||||
private FileStateReaper m_stateReaper;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
@@ -140,6 +146,16 @@ public class AVMDiskDriver implements DiskInterface {
|
||||
return m_serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file state reaper
|
||||
*
|
||||
* @return FileStateReaper
|
||||
*/
|
||||
public final FileStateReaper getStateReaper()
|
||||
{
|
||||
return m_stateReaper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AVM service
|
||||
*
|
||||
@@ -200,15 +216,27 @@ public class AVMDiskDriver implements DiskInterface {
|
||||
m_mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the file state reaper
|
||||
*
|
||||
* @param stateReaper FileStateReaper
|
||||
*/
|
||||
public final void setStateReaper(FileStateReaper stateReaper)
|
||||
{
|
||||
m_stateReaper = stateReaper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and validate the parameter string and create a device context object for this instance
|
||||
* of the shared device.
|
||||
*
|
||||
* @param devIface DeviceInterface
|
||||
* @param name String
|
||||
* @param cfg ConfigElement
|
||||
* @return DeviceContext
|
||||
* @exception DeviceContextException
|
||||
*/
|
||||
public DeviceContext createContext(ConfigElement cfg)
|
||||
public DeviceContext createContext(DeviceInterface devIface, String name, ConfigElement cfg)
|
||||
throws DeviceContextException
|
||||
{
|
||||
// Use the system user as the authenticated context for the filesystem initialization
|
||||
@@ -315,7 +343,7 @@ public class AVMDiskDriver implements DiskInterface {
|
||||
|
||||
// Create the context
|
||||
|
||||
context = new AVMContext(storePath, version);
|
||||
context = new AVMContext( name, storePath, version);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -342,6 +370,10 @@ public class AVMDiskDriver implements DiskInterface {
|
||||
}
|
||||
}
|
||||
|
||||
// Enable file state caching
|
||||
|
||||
context.enableStateTable( true, getStateReaper());
|
||||
|
||||
// Return the context for this shared filesystem
|
||||
|
||||
return context;
|
||||
|
238
source/java/org/alfresco/filesys/avm/AVMPath.java
Normal file
238
source/java/org/alfresco/filesys/avm/AVMPath.java
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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.FileName;
|
||||
|
||||
/**
|
||||
* AVM Path Class
|
||||
*
|
||||
* <p>Parses a share relative path into store, version and remaining path values.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class AVMPath {
|
||||
|
||||
// Constants
|
||||
//
|
||||
// Invalid version id value
|
||||
|
||||
private static final int InvalidVersionId = -2;
|
||||
|
||||
// Version id string for the head version
|
||||
|
||||
private static final String VersionNameHead = "Head";
|
||||
|
||||
// AVM path seperator
|
||||
|
||||
public static final char AVM_SEPERATOR = '/';
|
||||
|
||||
// Store name
|
||||
|
||||
private String m_storeName;
|
||||
|
||||
// Version id
|
||||
|
||||
private int m_version = InvalidVersionId;
|
||||
|
||||
// Remaining path
|
||||
|
||||
private String m_path;
|
||||
|
||||
// AVM style path
|
||||
|
||||
private String m_avmPath;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param shrPath String
|
||||
*/
|
||||
public AVMPath(String shrPath)
|
||||
{
|
||||
// Parse the path
|
||||
|
||||
parsePath( shrPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the store name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public final String getStoreName()
|
||||
{
|
||||
return m_storeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the version id was specified in the path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean hasVersion()
|
||||
{
|
||||
return m_version != InvalidVersionId ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int getVersion()
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the share relative path
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public final String getRelativePath()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the AVM style path, in <store>:/<path> format
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public final String getAVMPath()
|
||||
{
|
||||
return m_avmPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the path is valid
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isValid()
|
||||
{
|
||||
return m_storeName == null ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the path
|
||||
*
|
||||
* @param path String
|
||||
*/
|
||||
private final void parsePath( String path)
|
||||
{
|
||||
// Split the path
|
||||
|
||||
String[] paths = FileName.splitAllPaths(path);
|
||||
|
||||
if ( paths == null || paths.length == 0)
|
||||
return;
|
||||
|
||||
// Set the store name
|
||||
|
||||
m_storeName = paths[0];
|
||||
|
||||
if ( paths.length > 1)
|
||||
{
|
||||
// Validate the version id
|
||||
|
||||
String verStr = paths[1];
|
||||
if ( verStr.equalsIgnoreCase( VersionNameHead))
|
||||
m_version = -1;
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
// Parse the version id
|
||||
|
||||
m_version = Integer.parseInt( verStr);
|
||||
|
||||
// Validate the version id
|
||||
|
||||
if ( m_version < 0)
|
||||
{
|
||||
// Invalid version id
|
||||
|
||||
m_storeName = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch ( NumberFormatException ex)
|
||||
{
|
||||
m_storeName = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If there additional path elements build the share and AVM relative paths
|
||||
|
||||
if ( paths.length > 2)
|
||||
{
|
||||
// Build the share relative path
|
||||
|
||||
StringBuilder pathStr = new StringBuilder();
|
||||
|
||||
for ( int i = 2; i < paths.length; i++)
|
||||
{
|
||||
pathStr.append( FileName.DOS_SEPERATOR);
|
||||
pathStr.append( paths[i]);
|
||||
}
|
||||
|
||||
m_path = pathStr.toString();
|
||||
|
||||
// Build the AVM path, in <store>:/<path> format
|
||||
|
||||
pathStr.setLength( 0);
|
||||
|
||||
pathStr.append( m_storeName);
|
||||
pathStr.append( ":");
|
||||
pathStr.append( m_path.replace( FileName.DOS_SEPERATOR, AVM_SEPERATOR));
|
||||
|
||||
m_avmPath = pathStr.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the AVM path details as a string
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
str.append("[");
|
||||
str.append(getStoreName());
|
||||
str.append(",");
|
||||
|
||||
if ( hasVersion())
|
||||
str.append(getVersion());
|
||||
else
|
||||
str.append("NoVersion");
|
||||
|
||||
str.append(",");
|
||||
str.append(getRelativePath());
|
||||
str.append(":");
|
||||
str.append(getAVMPath());
|
||||
str.append("]");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
@@ -249,12 +249,9 @@ public class AVMShareMapper implements ShareMapper {
|
||||
|
||||
// Create a dynamic share mapped to the AVM store/version
|
||||
|
||||
DiskDeviceContext avmCtx = new AVMContext( storePath, storeVersion);
|
||||
AVMContext avmCtx = new AVMContext( name, storePath, storeVersion);
|
||||
avmCtx.enableStateTable( true, avmDrv.getStateReaper());
|
||||
|
||||
// Default the filesystem to look like an 80Gb sized disk with 90% free space
|
||||
|
||||
avmCtx.setDiskInformation(new SrvDiskInfo(2560, 64, 512, 2304));
|
||||
|
||||
// Create a dynamic shared device for the store version
|
||||
|
||||
DiskSharedDevice diskShare = new DiskSharedDevice( name, avmDrv, avmCtx, SharedDevice.Temporary);
|
||||
|
Reference in New Issue
Block a user