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