mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Pass executor to scheduler.
This commit is contained in:
@@ -9,6 +9,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.event.EventExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.network.NetworkStatus;
|
||||
@@ -17,6 +18,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -51,6 +53,7 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
||||
|
||||
private final TaskScheduler scheduler;
|
||||
private final EventBus eventBus;
|
||||
private final Executor eventExecutor;
|
||||
private final Context appContext;
|
||||
private final AtomicReference<Future<?>> connectivityCheck =
|
||||
new AtomicReference<>();
|
||||
@@ -60,9 +63,10 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
||||
|
||||
@Inject
|
||||
AndroidNetworkManager(TaskScheduler scheduler, EventBus eventBus,
|
||||
Application app) {
|
||||
@EventExecutor Executor eventExecutor, Application app) {
|
||||
this.scheduler = scheduler;
|
||||
this.eventBus = eventBus;
|
||||
this.eventExecutor = eventExecutor;
|
||||
this.appContext = app.getApplicationContext();
|
||||
}
|
||||
|
||||
@@ -104,7 +108,8 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
||||
|
||||
private void scheduleConnectionStatusUpdate(int delay, TimeUnit unit) {
|
||||
Future<?> newConnectivityCheck =
|
||||
scheduler.schedule(this::updateConnectionStatus, delay, unit);
|
||||
scheduler.schedule(this::updateConnectionStatus, eventExecutor,
|
||||
delay, unit);
|
||||
Future<?> oldConnectivityCheck =
|
||||
connectivityCheck.getAndSet(newConnectivityCheck);
|
||||
if (oldConnectivityCheck != null) oldConnectivityCheck.cancel(false);
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -78,10 +79,11 @@ class AndroidTaskScheduler implements TaskScheduler, Service, AlarmListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> schedule(Runnable task, long delay, TimeUnit unit) {
|
||||
public Future<?> schedule(Runnable task, Executor executor, long delay,
|
||||
TimeUnit unit) {
|
||||
long now = SystemClock.elapsedRealtime();
|
||||
long dueMillis = now + MILLISECONDS.convert(delay, unit);
|
||||
ScheduledTask s = new ScheduledTask(task, dueMillis);
|
||||
ScheduledTask s = new ScheduledTask(task, executor, dueMillis);
|
||||
if (dueMillis <= now) {
|
||||
scheduledExecutorService.execute(s);
|
||||
} else {
|
||||
@@ -93,13 +95,13 @@ class AndroidTaskScheduler implements TaskScheduler, Service, AlarmListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> scheduleWithFixedDelay(Runnable task, long delay,
|
||||
long interval, TimeUnit unit) {
|
||||
public Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||
long delay, long interval, TimeUnit unit) {
|
||||
Runnable wrapped = () -> {
|
||||
task.run();
|
||||
scheduleWithFixedDelay(task, interval, interval, unit);
|
||||
scheduleWithFixedDelay(task, executor, interval, interval, unit);
|
||||
};
|
||||
return schedule(wrapped, delay, unit);
|
||||
return schedule(wrapped, executor, delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,8 +177,9 @@ class AndroidTaskScheduler implements TaskScheduler, Service, AlarmListener {
|
||||
|
||||
private final long dueMillis;
|
||||
|
||||
public ScheduledTask(Runnable runnable, long dueMillis) {
|
||||
super(runnable, null);
|
||||
public ScheduledTask(Runnable runnable, Executor executor,
|
||||
long dueMillis) {
|
||||
super(() -> executor.execute(runnable), null);
|
||||
this.dueMillis = dueMillis;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,14 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.AndroidWakeLock;
|
||||
import org.briarproject.bramble.api.system.AndroidWakeLockFactory;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -38,12 +41,15 @@ class AndroidWakeLockFactoryImpl implements AndroidWakeLockFactory {
|
||||
private final SharedWakeLock sharedWakeLock;
|
||||
|
||||
@Inject
|
||||
AndroidWakeLockFactoryImpl(TaskScheduler scheduler, Application app) {
|
||||
AndroidWakeLockFactoryImpl(TaskScheduler scheduler,
|
||||
@EventExecutor Executor eventExecutor,
|
||||
Application app) {
|
||||
PowerManager powerManager = (PowerManager)
|
||||
requireNonNull(app.getSystemService(POWER_SERVICE));
|
||||
String tag = getWakeLockTag(app);
|
||||
sharedWakeLock = new RenewableWakeLock(powerManager, scheduler,
|
||||
PARTIAL_WAKE_LOCK, tag, LOCK_DURATION_MS, SAFETY_MARGIN_MS);
|
||||
eventExecutor, PARTIAL_WAKE_LOCK, tag, LOCK_DURATION_MS,
|
||||
SAFETY_MARGIN_MS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.PowerManager.WakeLock;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -28,6 +29,7 @@ class RenewableWakeLock implements SharedWakeLock {
|
||||
|
||||
private final PowerManager powerManager;
|
||||
private final TaskScheduler scheduler;
|
||||
private final Executor eventExecutor;
|
||||
private final int levelAndFlags;
|
||||
private final String tag;
|
||||
private final long durationMs, safetyMarginMs;
|
||||
@@ -44,11 +46,16 @@ class RenewableWakeLock implements SharedWakeLock {
|
||||
@GuardedBy("lock")
|
||||
private long acquired = 0;
|
||||
|
||||
RenewableWakeLock(PowerManager powerManager, TaskScheduler scheduler,
|
||||
int levelAndFlags, String tag, long durationMs,
|
||||
RenewableWakeLock(PowerManager powerManager,
|
||||
TaskScheduler scheduler,
|
||||
Executor eventExecutor,
|
||||
int levelAndFlags,
|
||||
String tag,
|
||||
long durationMs,
|
||||
long safetyMarginMs) {
|
||||
this.powerManager = powerManager;
|
||||
this.scheduler = scheduler;
|
||||
this.eventExecutor = eventExecutor;
|
||||
this.levelAndFlags = levelAndFlags;
|
||||
this.tag = tag;
|
||||
this.durationMs = durationMs;
|
||||
@@ -69,8 +76,8 @@ class RenewableWakeLock implements SharedWakeLock {
|
||||
// power management apps
|
||||
wakeLock.setReferenceCounted(false);
|
||||
wakeLock.acquire(durationMs + safetyMarginMs);
|
||||
future = scheduler.schedule(this::renew, durationMs,
|
||||
MILLISECONDS);
|
||||
future = scheduler.schedule(this::renew, eventExecutor,
|
||||
durationMs, MILLISECONDS);
|
||||
acquired = android.os.SystemClock.elapsedRealtime();
|
||||
}
|
||||
}
|
||||
@@ -93,7 +100,8 @@ class RenewableWakeLock implements SharedWakeLock {
|
||||
wakeLock.setReferenceCounted(false);
|
||||
wakeLock.acquire(durationMs + safetyMarginMs);
|
||||
oldWakeLock.release();
|
||||
future = scheduler.schedule(this::renew, durationMs, MILLISECONDS);
|
||||
future = scheduler.schedule(this::renew, eventExecutor,
|
||||
durationMs, MILLISECONDS);
|
||||
acquired = now;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.briarproject.bramble.api.system;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -16,13 +16,16 @@ import java.util.concurrent.TimeUnit;
|
||||
public interface TaskScheduler {
|
||||
|
||||
/**
|
||||
* See {@link ScheduledExecutorService#schedule(Runnable, long, TimeUnit)}.
|
||||
* Submits the given task to the given executor after the given delay.
|
||||
*/
|
||||
Future<?> schedule(Runnable task, long delay, TimeUnit unit);
|
||||
Future<?> schedule(Runnable task, Executor executor, long delay,
|
||||
TimeUnit unit);
|
||||
|
||||
/**
|
||||
* See {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)}.
|
||||
* Submits the given task to the given executor after the given delay,
|
||||
* and then repeatedly with the given interval between executions
|
||||
* (measured from the end of one execution to the beginning of the next).
|
||||
*/
|
||||
Future<?> scheduleWithFixedDelay(Runnable task, long delay,
|
||||
long interval, TimeUnit unit);
|
||||
Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||
long delay, long interval, TimeUnit unit);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
||||
synchronized (lock) {
|
||||
if (streams.isEmpty()) {
|
||||
task = scheduler.scheduleWithFixedDelay(this::checkTimeouts,
|
||||
CHECK_INTERVAL_MS, CHECK_INTERVAL_MS, MILLISECONDS);
|
||||
ioExecutor, CHECK_INTERVAL_MS, CHECK_INTERVAL_MS,
|
||||
MILLISECONDS);
|
||||
}
|
||||
streams.add(stream);
|
||||
}
|
||||
@@ -73,23 +74,21 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
||||
if (toCancel != null) toCancel.cancel(false);
|
||||
}
|
||||
|
||||
// Scheduler
|
||||
@IoExecutor
|
||||
private void checkTimeouts() {
|
||||
ioExecutor.execute(() -> {
|
||||
List<TimeoutInputStream> snapshot;
|
||||
synchronized (lock) {
|
||||
snapshot = new ArrayList<>(streams);
|
||||
}
|
||||
for (TimeoutInputStream stream : snapshot) {
|
||||
if (stream.hasTimedOut()) {
|
||||
LOG.info("Input stream has timed out");
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, INFO, e);
|
||||
}
|
||||
List<TimeoutInputStream> snapshot;
|
||||
synchronized (lock) {
|
||||
snapshot = new ArrayList<>(streams);
|
||||
}
|
||||
for (TimeoutInputStream stream : snapshot) {
|
||||
if (stream.hasTimedOut()) {
|
||||
LOG.info("Input stream has timed out");
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, INFO, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ class PollerImpl implements Poller, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make this wakeful
|
||||
private void connectToContact(ContactId c) {
|
||||
for (SimplexPlugin s : pluginManager.getSimplexPlugins())
|
||||
if (s.shouldPoll()) connectToContact(c, s);
|
||||
@@ -189,8 +190,8 @@ class PollerImpl implements Poller, EventListener {
|
||||
// it will abort safely when it finds it's been replaced
|
||||
if (scheduled != null) scheduled.future.cancel(false);
|
||||
PollTask task = new PollTask(p, due, randomiseNext);
|
||||
Future<?> future = scheduler.schedule(() ->
|
||||
ioExecutor.execute(task), delay, MILLISECONDS);
|
||||
Future<?> future = scheduler.schedule(task, ioExecutor, delay,
|
||||
MILLISECONDS);
|
||||
tasks.put(t, new ScheduledPollTask(task, future));
|
||||
}
|
||||
} finally {
|
||||
@@ -233,9 +234,9 @@ class PollerImpl implements Poller, EventListener {
|
||||
private class ScheduledPollTask {
|
||||
|
||||
private final PollTask task;
|
||||
private final Future future;
|
||||
private final Future<?> future;
|
||||
|
||||
private ScheduledPollTask(PollTask task, Future future) {
|
||||
private ScheduledPollTask(PollTask task, Future<?> future) {
|
||||
this.task = task;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
@@ -143,8 +143,8 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
||||
} catch (DbException e) {
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
scheduler.scheduleWithFixedDelay(this::poll, POLLING_INTERVAL_MS,
|
||||
POLLING_INTERVAL_MS, MILLISECONDS);
|
||||
scheduler.scheduleWithFixedDelay(this::poll, worker,
|
||||
POLLING_INTERVAL_MS, POLLING_INTERVAL_MS, MILLISECONDS);
|
||||
}
|
||||
|
||||
@EventExecutor
|
||||
@@ -204,12 +204,10 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
||||
return plugin.createRendezvousEndpoint(k, cs.alice, h);
|
||||
}
|
||||
|
||||
// Scheduler
|
||||
// Worker
|
||||
private void poll() {
|
||||
worker.execute(() -> {
|
||||
removeExpiredPendingContacts();
|
||||
for (PluginState ps : pluginStates.values()) poll(ps);
|
||||
});
|
||||
removeExpiredPendingContacts();
|
||||
for (PluginState ps : pluginStates.values()) poll(ps);
|
||||
}
|
||||
|
||||
// Worker
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.bramble.system;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -10,8 +11,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
* A {@link TaskScheduler} that delegates all calls to a
|
||||
* {@link ScheduledExecutorService}.
|
||||
* A {@link TaskScheduler} that uses a {@link ScheduledExecutorService}.
|
||||
*/
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
@@ -24,13 +24,16 @@ class TaskSchedulerImpl implements TaskScheduler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> schedule(Runnable task, long delay, TimeUnit unit) {
|
||||
return delegate.schedule(task, delay, unit);
|
||||
public Future<?> schedule(Runnable task, Executor executor, long delay,
|
||||
TimeUnit unit) {
|
||||
Runnable execute = () -> executor.execute(task);
|
||||
return delegate.schedule(execute, delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> scheduleWithFixedDelay(Runnable task, long delay,
|
||||
long interval, TimeUnit unit) {
|
||||
return delegate.scheduleWithFixedDelay(task, delay, interval, unit);
|
||||
public Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||
long delay, long interval, TimeUnit unit) {
|
||||
Runnable execute = () -> executor.execute(task);
|
||||
return delegate.scheduleWithFixedDelay(execute, delay, interval, unit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.contact.PendingContactId;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.crypto.TransportCrypto;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
@@ -198,17 +199,16 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
|
||||
private void scheduleKeyUpdate(long now) {
|
||||
long delay = timePeriodLength - now % timePeriodLength;
|
||||
scheduler.schedule(this::updateKeys, delay, MILLISECONDS);
|
||||
scheduler.schedule(this::updateKeys, dbExecutor, delay, MILLISECONDS);
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
private void updateKeys() {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
db.transaction(false, this::updateKeys);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
try {
|
||||
db.transaction(false, this::updateKeys);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -234,7 +234,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) pollingInterval),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
}});
|
||||
|
||||
@@ -262,7 +263,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) pollingInterval),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Second event
|
||||
// Get the plugin
|
||||
@@ -304,7 +306,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) pollingInterval),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Second event
|
||||
// Get the plugin
|
||||
@@ -320,7 +323,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(now + 1));
|
||||
oneOf(future).cancel(false);
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval - 2), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) pollingInterval - 2),
|
||||
with(MILLISECONDS));
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
|
||||
@@ -345,8 +349,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
// Schedule a polling task immediately
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
|
||||
with(MILLISECONDS));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
will(new RunAction());
|
||||
// Running the polling task schedules the next polling task
|
||||
@@ -357,7 +361,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) (pollingInterval * 0.5)), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Get the transport properties and connected contacts
|
||||
oneOf(transportPropertyManager).getRemoteProperties(transportId);
|
||||
@@ -388,8 +393,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
// Schedule a polling task immediately
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
|
||||
with(MILLISECONDS));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
will(new RunAction());
|
||||
// Running the polling task schedules the next polling task
|
||||
@@ -400,7 +405,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) (pollingInterval * 0.5)), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) (pollingInterval * 0.5)),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// Get the transport properties and connected contacts
|
||||
oneOf(transportPropertyManager).getRemoteProperties(transportId);
|
||||
@@ -429,8 +435,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
// Schedule a polling task immediately
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
|
||||
with(MILLISECONDS));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(ioExecutor), with(0L), with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// The plugin is deactivated before the task runs - cancel the task
|
||||
oneOf(future).cancel(false);
|
||||
@@ -454,7 +460,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(clock).currentTimeMillis();
|
||||
will(returnValue(now));
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with((long) pollingInterval), with(MILLISECONDS));
|
||||
with(ioExecutor), with((long) pollingInterval),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
}});
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
e.getPendingContactState() == OFFLINE)));
|
||||
// Capture the poll task
|
||||
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
|
||||
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
|
||||
with(MILLISECONDS));
|
||||
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
|
||||
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
|
||||
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
|
||||
0));
|
||||
}});
|
||||
@@ -159,8 +159,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
e.getPendingContactState() == FAILED)));
|
||||
// Schedule the poll task
|
||||
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
|
||||
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
|
||||
with(MILLISECONDS));
|
||||
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
|
||||
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
|
||||
}});
|
||||
|
||||
rendezvousPoller.startService();
|
||||
@@ -468,8 +468,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(emptyList()));
|
||||
// Capture the poll task
|
||||
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
|
||||
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
|
||||
with(MILLISECONDS));
|
||||
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
|
||||
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
|
||||
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
|
||||
0));
|
||||
}});
|
||||
@@ -545,8 +545,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
e.getPendingContactState() == OFFLINE)));
|
||||
// Capture the poll task
|
||||
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
|
||||
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
|
||||
with(MILLISECONDS));
|
||||
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
|
||||
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
|
||||
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
|
||||
0));
|
||||
}});
|
||||
|
||||
@@ -117,7 +117,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
||||
new TransportKeySet(keySetId, contactId, null, updated)));
|
||||
// Schedule a key update at the start of the next time period
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(timePeriodLength - 1), with(MILLISECONDS));
|
||||
with(dbExecutor), with(timePeriodLength - 1),
|
||||
with(MILLISECONDS));
|
||||
}});
|
||||
|
||||
transportKeyManager.start(txn);
|
||||
@@ -420,7 +421,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
// Schedule a key update at the start of the next time period
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(timePeriodLength), with(MILLISECONDS));
|
||||
with(dbExecutor), with(timePeriodLength),
|
||||
with(MILLISECONDS));
|
||||
will(new RunAction());
|
||||
oneOf(dbExecutor).execute(with(any(Runnable.class)));
|
||||
will(new RunAction());
|
||||
@@ -445,7 +447,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
||||
new TransportKeySet(keySetId, contactId, null, updated)));
|
||||
// Schedule a key update at the start of the next time period
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)),
|
||||
with(timePeriodLength), with(MILLISECONDS));
|
||||
with(dbExecutor), with(timePeriodLength),
|
||||
with(MILLISECONDS));
|
||||
}});
|
||||
|
||||
transportKeyManager.start(txn);
|
||||
|
||||
@@ -146,9 +146,8 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
||||
private void startFeedExecutor() {
|
||||
if (fetcherStarted.getAndSet(true)) return;
|
||||
LOG.info("Tor started, scheduling RSS feed fetcher");
|
||||
Runnable fetcher = () -> ioExecutor.execute(this::fetchFeeds);
|
||||
scheduler.scheduleWithFixedDelay(fetcher, FETCH_DELAY_INITIAL,
|
||||
FETCH_INTERVAL, FETCH_UNIT);
|
||||
scheduler.scheduleWithFixedDelay(this::fetchFeeds, ioExecutor,
|
||||
FETCH_DELAY_INITIAL, FETCH_INTERVAL, FETCH_UNIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,6 +470,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
||||
if (date == null) time = now;
|
||||
else time = Math.max(0, Math.min(date.getTime(), now));
|
||||
String text = getPostText(b.toString());
|
||||
//noinspection TryWithIdenticalCatches
|
||||
try {
|
||||
// create and store post
|
||||
LocalAuthor localAuthor = feed.getLocalAuthor();
|
||||
|
||||
Reference in New Issue
Block a user