Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.briarproject.android.controller;
import org.briarproject.api.db.DatabaseExecutor;
import org.briarproject.api.lifecycle.LifecycleManager;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
public class DBControllerImpl implements DBController {
private static final Logger LOG =
Logger.getLogger(BriarControllerImpl.class.getName());
// Fields that are accessed from background threads must be volatile
@Inject
@DatabaseExecutor
protected volatile Executor dbExecutor;
@Inject
protected volatile LifecycleManager lifecycleManager;
@Inject
public DBControllerImpl() {
}
@Override
public void runOnDbThread(final Runnable task) {
dbExecutor.execute(new Runnable() {
@Override
public void run() {
try {
lifecycleManager.waitForDatabase();
task.run();
} catch (InterruptedException e) {
LOG.warning("Interrupted while waiting for database");
Thread.currentThread().interrupt();
}
}
});
}
}