use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.
the class CacheFileWithoutCacheMT method renameFile.
@Override
public void renameFile(String new_file) throws CacheFileManagerException {
try {
synchronized (this) {
moving = true;
}
while (true) {
synchronized (this) {
boolean surviving = false;
for (int i = 1; i < files_use_count.length; i++) {
if (files_use_count[i] > 0) {
surviving = true;
break;
}
}
if (!surviving) {
for (int i = 1; i < files_use_count.length; i++) {
FMFile file = files[i];
if (file.isClone()) {
synchronized (CacheFileWithoutCacheMT.class) {
num_clones--;
}
}
file.close();
}
files = new FMFile[] { base_file };
files_use_count = new int[] { files_use_count[0] };
base_file.renameFile(new_file);
break;
}
}
try {
System.out.println("CacheFileWithoutCacheMT: waiting for clones to die");
Thread.sleep(250);
} catch (Throwable e) {
}
}
} catch (FMFileManagerException e) {
manager.rethrow(this, e);
} finally {
synchronized (this) {
moving = false;
}
}
}
use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.
the class CacheFileWithoutCacheMT method getFile.
protected FMFile getFile() throws CacheFileManagerException {
synchronized (this) {
if (moving) {
files_use_count[0]++;
return (files[0]);
}
int min_index = -1;
int min = Integer.MAX_VALUE;
for (int i = 0; i < files_use_count.length; i++) {
int count = files_use_count[i];
if (count < min) {
min = count;
min_index = i;
}
}
if (min == 0 || files_use_count.length == MAX_CLONES) {
files_use_count[min_index]++;
return (files[min_index]);
}
try {
FMFile clone = base_file.createClone();
// System.out.println( "Created clone " + clone.getName());
int old_num = files.length;
int new_num = old_num + 1;
synchronized (CacheFileWithoutCacheMT.class) {
num_clones++;
if (num_clones % 100 == 0) {
// System.out.println( "File clones=" + num_clones );
}
if (new_num == MAX_CLONES || new_num > max_clone_depth) {
max_clone_depth = new_num;
// System.out.println( "Clone depth of " + new_num + " for " + clone.getName());
}
}
FMFile[] new_files = new FMFile[new_num];
int[] new_files_use_count = new int[new_num];
System.arraycopy(files, 0, new_files, 0, old_num);
System.arraycopy(files_use_count, 0, new_files_use_count, 0, old_num);
new_files[old_num] = clone;
new_files_use_count[old_num] = 1;
files = new_files;
files_use_count = new_files_use_count;
return (clone);
} catch (FMFileManagerException e) {
manager.rethrow(this, e);
return (null);
}
}
}
Aggregations