Search in sources :

Example 1 with FMFile

use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.

the class CacheFileWithoutCacheMT method read.

@Override
public void read(DirectByteBuffer[] buffers, long position, short policy) throws CacheFileManagerException {
    int read_length = 0;
    for (int i = 0; i < buffers.length; i++) {
        read_length += buffers[i].remaining(DirectByteBuffer.SS_CACHE);
    }
    FMFile file = null;
    try {
        file = getFile();
        file.read(buffers, position);
        manager.fileBytesRead(read_length);
        bytes_read += read_length;
    } catch (FMFileManagerException e) {
        manager.rethrow(this, e);
    } finally {
        releaseFile(file);
    }
}
Also used : FMFileManagerException(com.biglybt.core.diskmanager.file.FMFileManagerException) FMFile(com.biglybt.core.diskmanager.file.FMFile)

Example 2 with FMFile

use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.

the class CacheFileWithoutCacheMT method moveFile.

@Override
public void moveFile(File 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.moveFile(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;
        }
    }
}
Also used : FMFileManagerException(com.biglybt.core.diskmanager.file.FMFileManagerException) FMFile(com.biglybt.core.diskmanager.file.FMFile)

Example 3 with FMFile

use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.

the class FMFileManagerImpl method createFile.

@Override
public FMFile createFile(FMFileOwner owner, File file, int type) throws FMFileManagerException {
    FMFile res;
    if (AEDiagnostics.USE_DUMMY_FILE_DATA) {
        res = new FMFileTestImpl(owner, this, file, type);
    } else {
        if (limited) {
            res = new FMFileLimited(owner, this, file, type);
        } else {
            res = new FMFileUnlimited(owner, this, file, type);
        }
    }
    if (DEBUG) {
        try {
            files_mon.enter();
            files.add(res);
        } finally {
            files_mon.exit();
        }
    }
    return (res);
}
Also used : FMFile(com.biglybt.core.diskmanager.file.FMFile)

Example 4 with FMFile

use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.

the class CacheFileWithoutCacheMT method close.

@Override
public void close() throws CacheFileManagerException {
    try {
        synchronized (this) {
            for (int i = 0; i < files.length; i++) {
                FMFile file = files[i];
                if (file.isClone()) {
                    synchronized (CacheFileWithoutCacheMT.class) {
                        num_clones--;
                    }
                }
                file.close();
            }
        }
    } catch (FMFileManagerException e) {
        manager.rethrow(this, e);
    }
}
Also used : FMFileManagerException(com.biglybt.core.diskmanager.file.FMFileManagerException) FMFile(com.biglybt.core.diskmanager.file.FMFile)

Example 5 with FMFile

use of com.biglybt.core.diskmanager.file.FMFile in project BiglyBT by BiglySoftware.

the class CacheFileWithoutCacheMT method read.

@Override
public void read(DirectByteBuffer buffer, long position, short policy) throws CacheFileManagerException {
    int read_length = buffer.remaining(DirectByteBuffer.SS_CACHE);
    FMFile file = null;
    try {
        file = getFile();
        file.read(buffer, position);
        manager.fileBytesRead(read_length);
        bytes_read += read_length;
    } catch (FMFileManagerException e) {
        manager.rethrow(this, e);
    } finally {
        releaseFile(file);
    }
}
Also used : FMFileManagerException(com.biglybt.core.diskmanager.file.FMFileManagerException) FMFile(com.biglybt.core.diskmanager.file.FMFile)

Aggregations

FMFile (com.biglybt.core.diskmanager.file.FMFile)7 FMFileManagerException (com.biglybt.core.diskmanager.file.FMFileManagerException)6