mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Update progress of writer task.
This commit is contained in:
@@ -3,12 +3,14 @@ package org.briarproject.bramble.plugin.file;
|
|||||||
import org.briarproject.bramble.api.connection.ConnectionManager;
|
import org.briarproject.bramble.api.connection.ConnectionManager;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||||
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
import org.briarproject.bramble.api.sync.event.MessagesSentEvent;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -18,8 +20,10 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.ID;
|
import static org.briarproject.bramble.api.plugin.file.RemovableDriveConstants.ID;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class RemovableDriveWriterTask extends RemovableDriveTaskImpl
|
class RemovableDriveWriterTask extends RemovableDriveTaskImpl
|
||||||
@@ -46,15 +50,24 @@ class RemovableDriveWriterTask extends RemovableDriveTaskImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TransportConnectionWriter w =
|
SimplexPlugin plugin = getPlugin();
|
||||||
getPlugin().createWriter(createProperties());
|
TransportConnectionWriter w = plugin.createWriter(createProperties());
|
||||||
if (w == null) {
|
if (w == null) {
|
||||||
LOG.warning("Failed to create writer");
|
LOG.warning("Failed to create writer");
|
||||||
registry.removeWriter(contactId, this);
|
registry.removeWriter(contactId, this);
|
||||||
setSuccess(false);
|
setSuccess(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: Get total bytes to send from DB
|
int maxLatency = plugin.getMaxLatency();
|
||||||
|
try {
|
||||||
|
setTotal(db.transactionWithResult(true, txn ->
|
||||||
|
db.getMessageBytesToSend(txn, contactId, maxLatency)));
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
registry.removeWriter(contactId, this);
|
||||||
|
setSuccess(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
connectionManager.manageOutgoingConnection(contactId, ID,
|
connectionManager.manageOutgoingConnection(contactId, ID,
|
||||||
new DecoratedWriter(w));
|
new DecoratedWriter(w));
|
||||||
@@ -68,7 +81,7 @@ class RemovableDriveWriterTask extends RemovableDriveTaskImpl
|
|||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info(m.getMessageIds().size() + " messages sent");
|
LOG.info(m.getMessageIds().size() + " messages sent");
|
||||||
}
|
}
|
||||||
// TODO: Update progress
|
addDone(m.getTotalLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user