Add RemovableDriveManager method.

This commit is contained in:
akwizgran
2021-06-17 13:01:33 +01:00
committed by Torsten Grote
parent 796cbcaf4b
commit 1f1ea8f3ed
3 changed files with 20 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.bramble.api.plugin.file;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.properties.TransportProperties;
@@ -37,4 +38,9 @@ public interface RemovableDriveManager {
* ignored.
*/
RemovableDriveTask startWriterTask(ContactId c, TransportProperties p);
/**
* Returns true if there is anything to send to the given contact.
*/
boolean isWriterTaskNeeded(ContactId c) throws DbException;
}

View File

@@ -1,6 +1,8 @@
package org.briarproject.bramble.plugin.file;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.file.RemovableDriveManager;
@@ -14,12 +16,15 @@ import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static org.briarproject.bramble.plugin.file.RemovableDrivePluginFactory.MAX_LATENCY;
@ThreadSafe
@NotNullByDefault
class RemovableDriveManagerImpl
implements RemovableDriveManager, RemovableDriveTaskRegistry {
private final Executor ioExecutor;
private final DatabaseComponent db;
private final RemovableDriveTaskFactory taskFactory;
private final Object lock = new Object();
@@ -30,8 +35,9 @@ class RemovableDriveManagerImpl
@Inject
RemovableDriveManagerImpl(@IoExecutor Executor ioExecutor,
RemovableDriveTaskFactory taskFactory) {
DatabaseComponent db, RemovableDriveTaskFactory taskFactory) {
this.ioExecutor = ioExecutor;
this.db = db;
this.taskFactory = taskFactory;
}
@@ -74,6 +80,12 @@ class RemovableDriveManagerImpl
return created;
}
@Override
public boolean isWriterTaskNeeded(ContactId c) throws DbException {
return db.transactionWithResult(true, txn ->
db.containsAnythingToSend(txn, c, MAX_LATENCY, true));
}
@Override
public void removeReader(RemovableDriveTask task) {
synchronized (lock) {

View File

@@ -17,7 +17,7 @@ import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.I
@NotNullByDefault
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
private static final int MAX_LATENCY = (int) DAYS.toMillis(14);
static final int MAX_LATENCY = (int) DAYS.toMillis(14);
@Inject
RemovableDrivePluginFactory() {