mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Add task factory.
This commit is contained in:
@@ -6,7 +6,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import java.io.File;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface RemovableDriveTask {
|
||||
public interface RemovableDriveTask extends Runnable {
|
||||
|
||||
/**
|
||||
* Returns the file that this task is reading from or writing to.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.bramble.plugin.file;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.EventExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.file.RemovableDriveManager;
|
||||
@@ -20,7 +19,8 @@ import javax.inject.Inject;
|
||||
class RemovableDriveManagerImpl
|
||||
implements RemovableDriveManager, RemovableDriveTaskRegistry {
|
||||
|
||||
private final Executor ioExecutor, eventExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final RemovableDriveTaskFactory taskFactory;
|
||||
private final ConcurrentHashMap<ContactId, RemovableDriveTask>
|
||||
readers = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<ContactId, RemovableDriveTask>
|
||||
@@ -28,9 +28,9 @@ class RemovableDriveManagerImpl
|
||||
|
||||
@Inject
|
||||
RemovableDriveManagerImpl(@IoExecutor Executor ioExecutor,
|
||||
@EventExecutor Executor eventExecutor) {
|
||||
RemovableDriveTaskFactory taskFactory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventExecutor = eventExecutor;
|
||||
this.taskFactory = taskFactory;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -47,8 +47,7 @@ class RemovableDriveManagerImpl
|
||||
|
||||
@Override
|
||||
public RemovableDriveTask startReaderTask(ContactId c, File f) {
|
||||
RemovableDriverReaderTask task =
|
||||
new RemovableDriverReaderTask(eventExecutor, this, c, f);
|
||||
RemovableDriveTask task = taskFactory.createReader(this, c, f);
|
||||
RemovableDriveTask old = readers.putIfAbsent(c, task);
|
||||
if (old == null) {
|
||||
ioExecutor.execute(task);
|
||||
@@ -60,8 +59,7 @@ class RemovableDriveManagerImpl
|
||||
|
||||
@Override
|
||||
public RemovableDriveTask startWriterTask(ContactId c, File f) {
|
||||
RemovableDriverWriterTask task =
|
||||
new RemovableDriverWriterTask(eventExecutor, this, c, f);
|
||||
RemovableDriveTask task = taskFactory.createWriter(this, c, f);
|
||||
RemovableDriveTask old = writers.putIfAbsent(c, task);
|
||||
if (old == null) {
|
||||
ioExecutor.execute(task);
|
||||
|
||||
@@ -16,4 +16,10 @@ public class RemovableDriveModule {
|
||||
RemovableDriveManagerImpl removableDriveManager) {
|
||||
return removableDriveManager;
|
||||
}
|
||||
|
||||
@Provides
|
||||
RemovableDriveTaskFactory provideTaskFactory(
|
||||
RemovableDriveTaskFactoryImpl taskFactory) {
|
||||
return taskFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.bramble.plugin.file;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.file.RemovableDriveTask;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@NotNullByDefault
|
||||
interface RemovableDriveTaskFactory {
|
||||
|
||||
RemovableDriveTask createReader(RemovableDriveTaskRegistry registry,
|
||||
ContactId c, File f);
|
||||
|
||||
RemovableDriveTask createWriter(RemovableDriveTaskRegistry registry,
|
||||
ContactId c, File f);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.briarproject.bramble.plugin.file;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.event.EventExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.file.RemovableDriveTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class RemovableDriveTaskFactoryImpl implements RemovableDriveTaskFactory {
|
||||
|
||||
private final Executor eventExecutor;
|
||||
|
||||
@Inject
|
||||
RemovableDriveTaskFactoryImpl(@EventExecutor Executor eventExecutor) {
|
||||
this.eventExecutor = eventExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemovableDriveTask createReader(RemovableDriveTaskRegistry registry,
|
||||
ContactId c, File f) {
|
||||
return new RemovableDriverReaderTask(eventExecutor, registry, c, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RemovableDriveTask createWriter(RemovableDriveTaskRegistry registry,
|
||||
ContactId c, File f) {
|
||||
return new RemovableDriverWriterTask(eventExecutor, registry, c, f);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
abstract class RemovableDriveTaskImpl implements RemovableDriveTask, Runnable {
|
||||
abstract class RemovableDriveTaskImpl implements RemovableDriveTask {
|
||||
|
||||
private final Executor eventExecutor;
|
||||
final RemovableDriveTaskRegistry registry;
|
||||
|
||||
Reference in New Issue
Block a user