|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.FileManager
The list of all shared files. Provides operations to add and remove individual files, directory, or sets of directories. Provides a method to efficiently query for files whose names contain certain keywords.
This class is thread-safe.
Field Summary | |
static java.lang.String |
BROWSE_QUERY
The string used by LimeWire to browse hosts. |
static java.lang.String |
DELIMETERS
Characters used to tokenize queries and file names. |
static java.io.FilenameFilter |
DIRECTORY_FILTER
The only DirectoryFilter object that should be used. |
static java.lang.String |
INDEXING_QUERY
The string used by Clip2 reflectors to index hosts. |
static java.io.FilenameFilter |
SHAREABLE_FILE_FILTER
The only ShareableFileFilter object that should be used. |
Constructor Summary | |
FileManager()
Creates a new FileManager instance. |
Method Summary | |
FileDesc |
addFileIfShared(java.io.File file)
|
abstract FileDesc |
addFileIfShared(java.io.File file,
java.util.List metadata)
|
void |
addIncompleteFile(java.io.File incompleteFile,
java.util.Set urns,
java.lang.String name,
int size,
VerifyingFile vf)
Adds an incomplete file to be used for partial file sharing. |
protected abstract void |
addXMLToResponse(Response res,
FileDesc desc)
This implementation does nothing. |
static void |
debug(java.lang.String out)
|
FileDesc |
fileChanged(java.io.File f)
Notification that a file has changed and new hashes should be calculated. |
FileDesc |
get(int i)
Returns the file descriptor with the given index. |
FileDesc[] |
getAllSharedFileDescriptors()
Returns a list of all shared file descriptors. |
FileDesc |
getFileDescForFile(java.io.File f)
Returns the FileDesc that is wrapping this File or null if the file is not shared. |
FileDesc |
getFileDescForUrn(URN urn)
Returns the FileDesc for the specified URN. |
static java.io.File[] |
getFilesRecursive(java.io.File directory,
java.lang.String[] filter)
|
FileDesc[] |
getIncompleteFileDescriptors()
Returns a list of all shared incomplete file descriptors. |
java.util.List |
getIndivisibleKeyWords()
|
java.util.List |
getKeyWords()
called when a query route table has to be made. |
int |
getNumFiles()
Returns the number of files. |
int |
getNumIncompleteFiles()
Returns the number of shared incomplete files. |
int |
getNumPendingFiles()
Returns the number of pending files. |
FileDesc[] |
getSharedFileDescriptors(java.io.File directory)
Returns a list of all shared file descriptors in the given directory, in any order. |
int |
getSize()
Returns the size of all files, in bytes. |
static boolean |
isFileShareable(java.io.File file,
long fileLength)
Returns true if this file is sharable. |
boolean |
isValidIndex(int i)
Determines whether or not the specified index is valid. |
void |
loadSettings(boolean notifyOnClear)
Ensures this contains exactly the files specified by the EXTENSIONS_TO_SHARE and DIRECTORIES_TO_SHARE properties. |
protected void |
loadSettingsBlocking(boolean notifyOnClear)
Clears this', reloads this' extensions, generates an array of directories, and then indexes the generated directories files. |
protected boolean |
loadThreadInterrupted()
Returns true if the load thread has been interrupted an this should stop loading files. |
Response[] |
query(QueryRequest request)
Returns an array of all responses matching the given request. |
FileDesc |
removeFileIfShared(java.io.File f)
|
boolean |
renameFileIfShared(java.io.File oldName,
java.io.File newName)
If oldName isn't shared, returns false. |
protected void |
repOk()
|
protected IntSet |
search(java.lang.String query,
IntSet priors)
Returns a set of indices of files matching q, or null if there are no matches. |
protected abstract boolean |
shouldIncludeXMLInResponse(QueryRequest qr)
A normal FileManager will never include XML. |
void |
start()
Asynchronously loads all files by calling loadSettings. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String INDEXING_QUERY
public static final java.lang.String BROWSE_QUERY
public static java.io.FilenameFilter SHAREABLE_FILE_FILTER
public static java.io.FilenameFilter DIRECTORY_FILTER
public static final java.lang.String DELIMETERS
Constructor Detail |
public FileManager()
Method Detail |
public void start()
loadSettings
public int getSize()
public int getNumFiles()
public int getNumIncompleteFiles()
public int getNumPendingFiles()
public FileDesc get(int i)
i
- the index of the FileDesc to access
IndexOutOfBoundsException
- if the index is out of
rangepublic boolean isValidIndex(int i)
i >= 0 && i < _files.size()
i
- the index to check
public FileDesc getFileDescForFile(java.io.File f)
public FileDesc getFileDescForUrn(URN urn)
urn
- the urn for the file
public FileDesc[] getIncompleteFileDescriptors()
public FileDesc[] getAllSharedFileDescriptors()
public FileDesc[] getSharedFileDescriptors(java.io.File directory)
public static java.io.File[] getFilesRecursive(java.io.File directory, java.lang.String[] filter)
directory
- Gets all files under this directory RECURSIVELY.filter
- If null, then returns all files. Else, only returns files
extensions in the filter array.
public static void debug(java.lang.String out)
public void loadSettings(boolean notifyOnClear)
This method is thread-safe but non-blocking. When the method returns, the directory and extension settings used by addFileIfShared() are initialized. However, files will actually be indexed asynchronously in another thread. This is useful because indexing may take up to 30 seconds or so if sharing many files. If loadSettings is subsequently called before the indexing is complete, the original settings are discarded, and loading starts over immediately. Modification 8/01 - This method is still non-blocking and thread safe, but it was refactored to make for easier subclassing of FileManager. Now, a protected method called loadSettingsBlocking() is used to index the files asynchronously. Subclasses can override or extend this method to impose their own functionality. For example, see MetaFileManager.
notifyOnClear
- if true, callback is notified via clearSharedFiles
when the previous load settings thread has been killed.protected boolean loadThreadInterrupted()
protected void loadSettingsBlocking(boolean notifyOnClear)
public FileDesc addFileIfShared(java.io.File file)
public abstract FileDesc addFileIfShared(java.io.File file, java.util.List metadata)
public void addIncompleteFile(java.io.File incompleteFile, java.util.Set urns, java.lang.String name, int size, VerifyingFile vf)
incompleteFile
- the incomplete file.urns
- the set of all known URNs for this incomplete filename
- the completed name of this incomplete filesize
- the completed size of this incomplete filevf
- the VerifyingFile containing the ranges for this inc. filepublic FileDesc fileChanged(java.io.File f)
public FileDesc removeFileIfShared(java.io.File f)
public boolean renameFileIfShared(java.io.File oldName, java.io.File newName)
public static boolean isFileShareable(java.io.File file, long fileLength)
public java.util.List getKeyWords()
public java.util.List getIndivisibleKeyWords()
public Response[] query(QueryRequest request)
protected abstract boolean shouldIncludeXMLInResponse(QueryRequest qr)
protected abstract void addXMLToResponse(Response res, FileDesc desc)
protected IntSet search(java.lang.String query, IntSet priors)
protected void repOk()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |