Refactor manager and tasks to remove reliance on files.

This commit is contained in:
akwizgran
2021-05-10 14:36:01 +01:00
parent 0ce0551f0d
commit eae329cdfa
9 changed files with 58 additions and 50 deletions

View File

@@ -2,8 +2,7 @@ package org.briarproject.bramble.api.plugin.file;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.File;
import org.briarproject.bramble.api.properties.TransportProperties;
import javax.annotation.Nullable;
@@ -26,15 +25,17 @@ public interface RemovableDriveManager {
/**
* Starts and returns a reader task for the given contact, reading from
* the given file. If a reader task for the contact is already running,
* it will be returned and the file argument will be ignored.
* a stream described by the given transport properties. If a reader task
* for the contact is already running, it will be returned and the
* transport properties will be ignored.
*/
RemovableDriveTask startReaderTask(ContactId c, File f);
RemovableDriveTask startReaderTask(ContactId c, TransportProperties p);
/**
* Starts and returns a writer task for the given contact, writing to
* the given file. If a writer task for the contact is already running,
* it will be returned and the file argument will be ignored.
* a stream described by the given transport properties. If a writer task
* for the contact is already running, it will be returned and the
* transport properties will be ignored.
*/
RemovableDriveTask startWriterTask(ContactId c, File f);
RemovableDriveTask startWriterTask(ContactId c, TransportProperties p);
}

View File

@@ -2,16 +2,16 @@ package org.briarproject.bramble.api.plugin.file;
import org.briarproject.bramble.api.Consumer;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.io.File;
import org.briarproject.bramble.api.properties.TransportProperties;
@NotNullByDefault
public interface RemovableDriveTask extends Runnable {
/**
* Returns the file that this task is reading from or writing to.
* Returns the {@link TransportProperties} that were used for creating
* this task.
*/
File getFile();
TransportProperties getTransportProperties();
/**
* Adds an observer to the task. The observer will be notified of state
@@ -37,10 +37,19 @@ public interface RemovableDriveTask extends Runnable {
this.success = success;
}
/**
* Returns the total length in bytes of the messages read or written
* so far.
*/
public long getDone() {
return done;
}
/**
* Returns the total length in bytes of the messages that will have
* been read or written when the task is complete, or zero if the
* total is unknown.
*/
public long getTotal() {
return total;
}