mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Annotate methods that should be called with a wake lock.
This commit is contained in:
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ public interface LifecycleManager {
|
|||||||
* Opens the {@link DatabaseComponent} using the given key and starts any
|
* Opens the {@link DatabaseComponent} using the given key and starts any
|
||||||
* registered {@link Service Services}.
|
* registered {@link Service Services}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
StartResult startServices(SecretKey dbKey);
|
StartResult startServices(SecretKey dbKey);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +74,7 @@ public interface LifecycleManager {
|
|||||||
* registered {@link ExecutorService ExecutorServices}, and closes the
|
* registered {@link ExecutorService ExecutorServices}, and closes the
|
||||||
* {@link DatabaseComponent}.
|
* {@link DatabaseComponent}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stopServices();
|
void stopServices();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +107,7 @@ public interface LifecycleManager {
|
|||||||
*
|
*
|
||||||
* @param txn A read-write transaction
|
* @param txn A read-write transaction
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void onDatabaseOpened(Transaction txn) throws DbException;
|
void onDatabaseOpened(Transaction txn) throws DbException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,20 @@
|
|||||||
package org.briarproject.bramble.api.lifecycle;
|
package org.briarproject.bramble.api.lifecycle;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
public interface Service {
|
public interface Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the service.This method must not be called concurrently with
|
* Starts the service. This method must not be called concurrently with
|
||||||
* {@link #stopService()}.
|
* {@link #stopService()}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void startService() throws ServiceException;
|
void startService() throws ServiceException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the service. This method must not be called concurrently with
|
* Stops the service. This method must not be called concurrently with
|
||||||
* {@link #startService()}.
|
* {@link #startService()}.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stopService() throws ServiceException;
|
void stopService() throws ServiceException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.Pair;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@@ -70,11 +71,13 @@ public interface Plugin {
|
|||||||
/**
|
/**
|
||||||
* Starts the plugin.
|
* Starts the plugin.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void start() throws PluginException;
|
void start() throws PluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the plugin.
|
* Stops the plugin.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void stop() throws PluginException;
|
void stop() throws PluginException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,6 +109,7 @@ public interface Plugin {
|
|||||||
* Attempts to create connections using the given transport properties,
|
* Attempts to create connections using the given transport properties,
|
||||||
* passing any created connections to the corresponding handlers.
|
* passing any created connections to the corresponding handlers.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||||
properties);
|
properties);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.plugin.Plugin;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||||
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ public interface DuplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a connection using the given transport
|
* Attempts to create and return a connection using the given transport
|
||||||
* properties. Returns null if a connection cannot be created.
|
* properties. Returns null if a connection cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
DuplexTransportConnection createConnection(TransportProperties p);
|
DuplexTransportConnection createConnection(TransportProperties p);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.briarproject.bramble.api.plugin.Plugin;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ public interface SimplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a reader for the given transport
|
* Attempts to create and return a reader for the given transport
|
||||||
* properties. Returns null if a reader cannot be created.
|
* properties. Returns null if a reader cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
TransportConnectionReader createReader(TransportProperties p);
|
TransportConnectionReader createReader(TransportProperties p);
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ public interface SimplexPlugin extends Plugin {
|
|||||||
* Attempts to create and return a writer for the given transport
|
* Attempts to create and return a writer for the given transport
|
||||||
* properties. Returns null if a writer cannot be created.
|
* properties. Returns null if a writer cannot be created.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
@Nullable
|
@Nullable
|
||||||
TransportConnectionWriter createWriter(TransportProperties p);
|
TransportConnectionWriter createWriter(TransportProperties p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public interface TaskScheduler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Submits the given task to the given executor after the given delay.
|
* Submits the given task to the given executor after the given delay.
|
||||||
|
* <p>
|
||||||
|
* If the platform supports wake locks, a wake lock will be held while
|
||||||
|
* submitting and running the task.
|
||||||
*/
|
*/
|
||||||
Future<?> schedule(Runnable task, Executor executor, long delay,
|
Future<?> schedule(Runnable task, Executor executor, long delay,
|
||||||
TimeUnit unit);
|
TimeUnit unit);
|
||||||
@@ -22,6 +25,9 @@ public interface TaskScheduler {
|
|||||||
* Submits the given task to the given executor after the given delay,
|
* Submits the given task to the given executor after the given delay,
|
||||||
* and then repeatedly with the given interval between executions
|
* and then repeatedly with the given interval between executions
|
||||||
* (measured from the end of one execution to the beginning of the next).
|
* (measured from the end of one execution to the beginning of the next).
|
||||||
|
* <p>
|
||||||
|
* If the platform supports wake locks, a wake lock will be held while
|
||||||
|
* submitting and running the task.
|
||||||
*/
|
*/
|
||||||
Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
Future<?> scheduleWithFixedDelay(Runnable task, Executor executor,
|
||||||
long delay, long interval, TimeUnit unit);
|
long delay, long interval, TimeUnit unit);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.briarproject.bramble.api.system;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation for methods that must be called while holding a wake lock, if
|
||||||
|
* the platform supports wake locks.
|
||||||
|
*/
|
||||||
|
@Qualifier
|
||||||
|
@Target(METHOD)
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface Wakeful {
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.io.TimeoutMonitor;
|
|||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -75,6 +76,7 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
|
@Wakeful
|
||||||
private void checkTimeouts() {
|
private void checkTimeouts() {
|
||||||
List<TimeoutInputStream> snapshot;
|
List<TimeoutInputStream> snapshot;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@IoExecutor
|
@IoExecutor
|
||||||
|
@Wakeful
|
||||||
public void run() {
|
public void run() {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedE
|
|||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -205,6 +206,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worker
|
// Worker
|
||||||
|
@Wakeful
|
||||||
private void poll() {
|
private void poll() {
|
||||||
removeExpiredPendingContacts();
|
removeExpiredPendingContacts();
|
||||||
for (PluginState ps : pluginStates.values()) poll(ps);
|
for (PluginState ps : pluginStates.values()) poll(ps);
|
||||||
@@ -235,6 +237,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worker
|
// Worker
|
||||||
|
@Wakeful
|
||||||
private void poll(PluginState ps) {
|
private void poll(PluginState ps) {
|
||||||
if (ps.endpoints.isEmpty()) return;
|
if (ps.endpoints.isEmpty()) return;
|
||||||
TransportId t = ps.plugin.getId();
|
TransportId t = ps.plugin.getId();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.KeySetId;
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
@@ -203,6 +204,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
|
@Wakeful
|
||||||
private void updateKeys() {
|
private void updateKeys() {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, this::updateKeys);
|
db.transaction(false, this::updateKeys);
|
||||||
@@ -441,6 +443,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DatabaseExecutor
|
||||||
|
@Wakeful
|
||||||
private void updateKeys(Transaction txn) throws DbException {
|
private void updateKeys(Transaction txn) throws DbException {
|
||||||
long now = clock.currentTimeMillis();
|
long now = clock.currentTimeMillis();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import org.briarproject.bramble.api.sync.Group;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
import org.briarproject.bramble.api.system.Wakeful;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
@@ -284,7 +285,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called periodically from a background service.
|
* This method is called periodically by the task scheduler.
|
||||||
* It fetches all available feeds and posts new entries to the respective
|
* It fetches all available feeds and posts new entries to the respective
|
||||||
* blog.
|
* blog.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -292,6 +293,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
* because fetching can take a long time
|
* because fetching can take a long time
|
||||||
* and we can not block the database that long.
|
* and we can not block the database that long.
|
||||||
*/
|
*/
|
||||||
|
@Wakeful
|
||||||
void fetchFeeds() {
|
void fetchFeeds() {
|
||||||
if (!torActive) return;
|
if (!torActive) return;
|
||||||
LOG.info("Updating RSS feeds...");
|
LOG.info("Updating RSS feeds...");
|
||||||
|
|||||||
Reference in New Issue
Block a user