mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Register the DatabaseUiExecutor for shutdown by the LifecycleManager.
See issue #3612607.
This commit is contained in:
@@ -16,6 +16,7 @@ import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||
import net.sf.briar.api.android.ReferenceManager;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.plugins.PluginExecutor;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginConfig;
|
||||
@@ -34,22 +35,29 @@ import com.google.inject.Singleton;
|
||||
|
||||
public class AndroidModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(AndroidExecutor.class).to(AndroidExecutorImpl.class);
|
||||
bind(ReferenceManager.class).to(ReferenceManagerImpl.class).in(
|
||||
Singleton.class);
|
||||
private final ExecutorService databaseUiExecutor;
|
||||
|
||||
public AndroidModule() {
|
||||
// The queue is unbounded, so tasks can be dependent
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
// Use a single thread so DB accesses from the UI don't overlap
|
||||
ExecutorService e = new ThreadPoolExecutor(1, 1, 60, SECONDS, queue,
|
||||
databaseUiExecutor = new ThreadPoolExecutor(1, 1, 60, SECONDS, queue,
|
||||
policy);
|
||||
bind(Executor.class).annotatedWith(
|
||||
DatabaseUiExecutor.class).toInstance(e);
|
||||
bind(ExecutorService.class).annotatedWith(
|
||||
DatabaseUiExecutor.class).toInstance(e);
|
||||
}
|
||||
|
||||
protected void configure() {
|
||||
bind(AndroidExecutor.class).to(AndroidExecutorImpl.class);
|
||||
bind(ReferenceManager.class).to(ReferenceManagerImpl.class).in(
|
||||
Singleton.class);
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseUiExecutor
|
||||
Executor getDatabaseUiExecutor(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(databaseUiExecutor);
|
||||
return databaseUiExecutor;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -5,12 +5,10 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static java.util.logging.Level.INFO;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.R;
|
||||
import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||
import roboguice.service.RoboService;
|
||||
import android.app.PendingIntent;
|
||||
@@ -33,7 +31,6 @@ public class BriarService extends RoboService {
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile LifecycleManager lifecycleManager;
|
||||
@Inject private volatile AndroidExecutor androidExecutor;
|
||||
@Inject @DatabaseUiExecutor private volatile ExecutorService dbUiExecutor;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@@ -81,10 +78,7 @@ public class BriarService extends RoboService {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// FIXME: This is ugly - executors should register themselves
|
||||
// with the lifecycle manager
|
||||
androidExecutor.shutdown();
|
||||
dbUiExecutor.shutdown();
|
||||
lifecycleManager.stopServices();
|
||||
}
|
||||
}.start();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.sf.briar.api.android;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@@ -13,6 +14,6 @@ import com.google.inject.BindingAnnotation;
|
||||
* Annotation for injecting the executor for accessing the database from the UI.
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Target({ FIELD, PARAMETER })
|
||||
@Target({ FIELD, METHOD, PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
public @interface DatabaseUiExecutor {}
|
||||
|
||||
Reference in New Issue
Block a user