mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 23:29:52 +01:00
Moved lifecycle management into briar-core and reconfigured executors.
CryptoExecutor and DatabaseExecutor now use bounded thread pools with unbounded queues, since running too many tasks in parallel is likely to harm performance; IncomingConnectionExecutor, PluginExecutor and ReliabilityExecutor use unbounded thread pools with direct handoff, since their tasks may run indefinitely. There are no longer any bounded executors, and all executors discard tasks when shutting down, which fixes issue #3612189. Responsibility for starting and stopping services has been moved from BriarService in briar-android to LifecycleManagerImpl in briar-core. However, BriarService is still responsible for stopping the Android-specific executors, which is ugly. It would be better if executors registered themselves with LifecycleManager.
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
package net.sf.briar.android;
|
package net.sf.briar.android;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import net.sf.briar.api.android.AndroidExecutor;
|
import net.sf.briar.api.android.AndroidExecutor;
|
||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
@@ -34,15 +39,22 @@ public class AndroidModule extends AbstractModule {
|
|||||||
bind(AndroidExecutor.class).to(AndroidExecutorImpl.class);
|
bind(AndroidExecutor.class).to(AndroidExecutorImpl.class);
|
||||||
bind(ReferenceManager.class).to(ReferenceManagerImpl.class).in(
|
bind(ReferenceManager.class).to(ReferenceManagerImpl.class).in(
|
||||||
Singleton.class);
|
Singleton.class);
|
||||||
// Use a single thread so DB accesses from the UI don't overlap, with
|
// The queue is unbounded, so tasks can be dependent
|
||||||
// an unbounded queue so submissions don't block
|
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||||
bind(Executor.class).annotatedWith(DatabaseUiExecutor.class).toInstance(
|
// Discard tasks that are submitted during shutdown
|
||||||
Executors.newSingleThreadExecutor());
|
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,
|
||||||
|
policy);
|
||||||
|
bind(Executor.class).annotatedWith(
|
||||||
|
DatabaseUiExecutor.class).toInstance(e);
|
||||||
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
DatabaseUiExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
SimplexPluginConfig getSimplexPluginConfig(
|
SimplexPluginConfig getSimplexPluginConfig() {
|
||||||
@PluginExecutor ExecutorService pluginExecutor) {
|
|
||||||
return new SimplexPluginConfig() {
|
return new SimplexPluginConfig() {
|
||||||
public Collection<SimplexPluginFactory> getFactories() {
|
public Collection<SimplexPluginFactory> getFactories() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -52,7 +64,7 @@ public class AndroidModule extends AbstractModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
DuplexPluginConfig getDuplexPluginConfig(
|
DuplexPluginConfig getDuplexPluginConfig(
|
||||||
@PluginExecutor ExecutorService pluginExecutor,
|
@PluginExecutor Executor pluginExecutor,
|
||||||
AndroidExecutor androidExecutor, Context appContext,
|
AndroidExecutor androidExecutor, Context appContext,
|
||||||
CryptoComponent crypto, ShutdownManager shutdownManager) {
|
CryptoComponent crypto, ShutdownManager shutdownManager) {
|
||||||
DuplexPluginFactory droidtooth = new DroidtoothPluginFactory(
|
DuplexPluginFactory droidtooth = new DroidtoothPluginFactory(
|
||||||
|
|||||||
@@ -3,18 +3,15 @@ package net.sf.briar.android;
|
|||||||
import static android.app.PendingIntent.FLAG_ONE_SHOT;
|
import static android.app.PendingIntent.FLAG_ONE_SHOT;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.api.crypto.KeyManager;
|
import net.sf.briar.api.android.AndroidExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseConfig;
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.db.DbException;
|
|
||||||
import net.sf.briar.api.plugins.PluginManager;
|
|
||||||
import roboguice.service.RoboService;
|
import roboguice.service.RoboService;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -31,15 +28,12 @@ public class BriarService extends RoboService {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BriarService.class.getName());
|
Logger.getLogger(BriarService.class.getName());
|
||||||
|
|
||||||
private final CountDownLatch dbLatch = new CountDownLatch(1);
|
|
||||||
private final CountDownLatch startupLatch = new CountDownLatch(1);
|
|
||||||
private final CountDownLatch shutdownLatch = new CountDownLatch(1);
|
|
||||||
private final Binder binder = new BriarBinder();
|
private final Binder binder = new BriarBinder();
|
||||||
|
|
||||||
@Inject private DatabaseConfig databaseConfig = null;
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private DatabaseComponent db = null;
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
@Inject private KeyManager keyManager = null;
|
@Inject private volatile AndroidExecutor androidExecutor;
|
||||||
@Inject private PluginManager pluginManager = null;
|
@Inject @DatabaseUiExecutor private volatile ExecutorService dbUiExecutor;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@@ -63,7 +57,7 @@ public class BriarService extends RoboService {
|
|||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
startServices();
|
lifecycleManager.startServices();
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
@@ -71,11 +65,11 @@ public class BriarService extends RoboService {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Started");
|
if(LOG.isLoggable(INFO)) LOG.info("Started");
|
||||||
return START_STICKY;
|
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Bound");
|
||||||
return binder;
|
return binder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,71 +81,38 @@ public class BriarService extends RoboService {
|
|||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
stopServices();
|
// FIXME: This is ugly - executors should register themselves
|
||||||
|
// with the lifecycle manager
|
||||||
|
androidExecutor.shutdown();
|
||||||
|
dbUiExecutor.shutdown();
|
||||||
|
lifecycleManager.stopServices();
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startServices() {
|
/** Waits for the database to be opened before returning. */
|
||||||
if(databaseConfig.getEncryptionKey() == null)
|
|
||||||
throw new IllegalStateException();
|
|
||||||
try {
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Starting");
|
|
||||||
boolean reopened = db.open();
|
|
||||||
if(LOG.isLoggable(INFO)) {
|
|
||||||
if(reopened) LOG.info("Database reopened");
|
|
||||||
else LOG.info("Database created");
|
|
||||||
}
|
|
||||||
dbLatch.countDown();
|
|
||||||
keyManager.start();
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Key manager started");
|
|
||||||
int pluginsStarted = pluginManager.start();
|
|
||||||
if(LOG.isLoggable(INFO))
|
|
||||||
LOG.info(pluginsStarted + " plugins started");
|
|
||||||
startupLatch.countDown();
|
|
||||||
} catch(DbException e) {
|
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
} catch(IOException e) {
|
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopServices() {
|
|
||||||
try {
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Shutting down");
|
|
||||||
int pluginsStopped = pluginManager.stop();
|
|
||||||
if(LOG.isLoggable(INFO))
|
|
||||||
LOG.info(pluginsStopped + " plugins stopped");
|
|
||||||
keyManager.stop();
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Key manager stopped");
|
|
||||||
db.close();
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Database closed");
|
|
||||||
shutdownLatch.countDown();
|
|
||||||
} catch(DbException e) {
|
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
} catch(IOException e) {
|
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void waitForDatabase() throws InterruptedException {
|
public void waitForDatabase() throws InterruptedException {
|
||||||
dbLatch.await();
|
lifecycleManager.waitForDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Waits for all services to start before returning. */
|
||||||
public void waitForStartup() throws InterruptedException {
|
public void waitForStartup() throws InterruptedException {
|
||||||
startupLatch.await();
|
lifecycleManager.waitForStartup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Waits for all services to stop before returning. */
|
||||||
public void waitForShutdown() throws InterruptedException {
|
public void waitForShutdown() throws InterruptedException {
|
||||||
shutdownLatch.await();
|
lifecycleManager.waitForShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Starts the shutdown process. */
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
stopSelf();
|
stopSelf(); // This will call onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BriarBinder extends Binder {
|
public class BriarBinder extends Binder {
|
||||||
|
|
||||||
|
/** Returns the bound service. */
|
||||||
public BriarService getService() {
|
public BriarService getService() {
|
||||||
return BriarService.this;
|
return BriarService.this;
|
||||||
}
|
}
|
||||||
@@ -170,19 +131,10 @@ public class BriarService extends RoboService {
|
|||||||
|
|
||||||
public void onServiceDisconnected(ComponentName name) {}
|
public void onServiceDisconnected(ComponentName name) {}
|
||||||
|
|
||||||
|
/** Waits for the service to connect and returns its binder. */
|
||||||
public IBinder waitForBinder() throws InterruptedException {
|
public IBinder waitForBinder() throws InterruptedException {
|
||||||
binderLatch.await();
|
binderLatch.await();
|
||||||
return binder;
|
return binder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void waitForDatabase() throws InterruptedException {
|
|
||||||
waitForBinder();
|
|
||||||
((BriarBinder) binder).getService().waitForDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void waitForStartup() throws InterruptedException {
|
|
||||||
waitForBinder();
|
|
||||||
((BriarBinder) binder).getService().waitForStartup();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import net.sf.briar.api.crypto.CryptoExecutor;
|
|||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DatabaseConfig;
|
import net.sf.briar.api.db.DatabaseConfig;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.util.StringUtils;
|
import net.sf.briar.util.StringUtils;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -70,18 +71,19 @@ public class HomeScreenActivity extends RoboActivity {
|
|||||||
private final BriarServiceConnection serviceConnection =
|
private final BriarServiceConnection serviceConnection =
|
||||||
new BriarServiceConnection();
|
new BriarServiceConnection();
|
||||||
|
|
||||||
@Inject private ReferenceManager referenceManager = null;
|
@Inject private ReferenceManager referenceManager;
|
||||||
@Inject private DatabaseConfig databaseConfig = null;
|
@Inject private DatabaseConfig databaseConfig;
|
||||||
@Inject @DatabaseUiExecutor private Executor dbUiExecutor = null;
|
@Inject @DatabaseUiExecutor private Executor dbUiExecutor;
|
||||||
@Inject @CryptoExecutor private Executor cryptoExecutor = null;
|
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||||
private boolean bound = false;
|
private boolean bound = false;
|
||||||
private TextView enterPassword = null;
|
private TextView enterPassword = null;
|
||||||
private Button continueButton = null;
|
private Button continueButton = null;
|
||||||
private ProgressBar progress = null;
|
private ProgressBar progress = null;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db = null;
|
@Inject private volatile CryptoComponent crypto;
|
||||||
@Inject private volatile CryptoComponent crypto = null;
|
@Inject private volatile DatabaseComponent db;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -136,7 +138,7 @@ public class HomeScreenActivity extends RoboActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// Wait for the service to be bound and started
|
// Wait for the service to finish starting up
|
||||||
IBinder binder = serviceConnection.waitForBinder();
|
IBinder binder = serviceConnection.waitForBinder();
|
||||||
BriarService service = ((BriarBinder) binder).getService();
|
BriarService service = ((BriarBinder) binder).getService();
|
||||||
service.waitForStartup();
|
service.waitForStartup();
|
||||||
@@ -146,7 +148,7 @@ public class HomeScreenActivity extends RoboActivity {
|
|||||||
service.waitForShutdown();
|
service.waitForShutdown();
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Interrupted while waiting for database");
|
LOG.info("Interrupted while waiting for service");
|
||||||
}
|
}
|
||||||
// Finish the activity and kill the JVM
|
// Finish the activity and kill the JVM
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -164,7 +166,7 @@ public class HomeScreenActivity extends RoboActivity {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addLocalAuthor(a);
|
db.addLocalAuthor(a);
|
||||||
db.setRating(a.getId(), GOOD);
|
db.setRating(a.getId(), GOOD);
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.AscendingHeaderComparator;
|
import net.sf.briar.android.AscendingHeaderComparator;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
import net.sf.briar.api.Author;
|
import net.sf.briar.api.Author;
|
||||||
@@ -33,6 +31,7 @@ import net.sf.briar.api.db.event.GroupMessageAddedEvent;
|
|||||||
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
||||||
import net.sf.briar.api.db.event.RatingChangedEvent;
|
import net.sf.briar.api.db.event.RatingChangedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -53,9 +52,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BlogActivity.class.getName());
|
Logger.getLogger(BlogActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private String groupName = null;
|
private String groupName = null;
|
||||||
private boolean postable = false;
|
private boolean postable = false;
|
||||||
private BlogAdapter adapter = null;
|
private BlogAdapter adapter = null;
|
||||||
@@ -65,6 +61,7 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile GroupId groupId = null;
|
private volatile GroupId groupId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,10 +104,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
layout.addView(composeButton);
|
layout.addView(composeButton);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,7 +117,7 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getGroupMessageHeaders(groupId);
|
db.getGroupMessageHeaders(groupId);
|
||||||
@@ -196,12 +189,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof GroupMessageAddedEvent) {
|
if(e instanceof GroupMessageAddedEvent) {
|
||||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
@@ -38,6 +36,7 @@ import net.sf.briar.api.db.event.MessageExpiredEvent;
|
|||||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.GroupStatus;
|
import net.sf.briar.api.messaging.GroupStatus;
|
||||||
@@ -61,9 +60,6 @@ OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(BlogListActivity.class.getName());
|
Logger.getLogger(BlogListActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private BlogListAdapter adapter = null;
|
private BlogListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
@@ -73,6 +69,7 @@ OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -126,10 +123,6 @@ OnItemClickListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -144,7 +137,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Set<GroupId> local = new HashSet<GroupId>();
|
Set<GroupId> local = new HashSet<GroupId>();
|
||||||
for(Group g : db.getLocalGroups()) local.add(g.getId());
|
for(Group g : db.getLocalGroups()) local.add(g.getId());
|
||||||
@@ -252,12 +245,6 @@ OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof GroupMessageAddedEvent) {
|
if(e instanceof GroupMessageAddedEvent) {
|
||||||
Group g = ((GroupMessageAddedEvent) e).getGroup();
|
Group g = ((GroupMessageAddedEvent) e).getGroup();
|
||||||
@@ -292,7 +279,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getGroupMessageHeaders(g.getId());
|
db.getGroupMessageHeaders(g.getId());
|
||||||
@@ -333,7 +320,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
int available = 0;
|
int available = 0;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(GroupStatus s : db.getAvailableGroups()) {
|
for(GroupStatus s : db.getAvailableGroups()) {
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.contact.SelectContactsDialog;
|
import net.sf.briar.android.contact.SelectContactsDialog;
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.messages.NoContactsDialog;
|
import net.sf.briar.android.messages.NoContactsDialog;
|
||||||
@@ -25,6 +23,7 @@ import net.sf.briar.api.ContactId;
|
|||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -48,9 +47,6 @@ SelectContactsDialog.Listener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConfigureBlogActivity.class.getName());
|
Logger.getLogger(ConfigureBlogActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private boolean subscribed = false;
|
private boolean subscribed = false;
|
||||||
private CheckBox subscribeCheckBox = null;
|
private CheckBox subscribeCheckBox = null;
|
||||||
private RadioGroup radioGroup = null;
|
private RadioGroup radioGroup = null;
|
||||||
@@ -61,6 +57,7 @@ SelectContactsDialog.Listener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile Group group = null;
|
private volatile Group group = null;
|
||||||
private volatile Collection<ContactId> selected = Collections.emptyList();
|
private volatile Collection<ContactId> selected = Collections.emptyList();
|
||||||
|
|
||||||
@@ -127,16 +124,6 @@ SelectContactsDialog.Listener {
|
|||||||
layout.addView(progress);
|
layout.addView(progress);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@@ -164,7 +151,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -208,7 +195,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if(subscribe) {
|
if(subscribe) {
|
||||||
if(!wasSubscribed) db.subscribe(group);
|
if(!wasSubscribed) db.subscribe(group);
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.contact.SelectContactsDialog;
|
import net.sf.briar.android.contact.SelectContactsDialog;
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.messages.NoContactsDialog;
|
import net.sf.briar.android.messages.NoContactsDialog;
|
||||||
@@ -33,6 +31,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.crypto.CryptoExecutor;
|
import net.sf.briar.api.crypto.CryptoExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupFactory;
|
import net.sf.briar.api.messaging.GroupFactory;
|
||||||
import net.sf.briar.api.messaging.LocalGroup;
|
import net.sf.briar.api.messaging.LocalGroup;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -60,9 +59,6 @@ SelectContactsDialog.Listener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CreateBlogActivity.class.getName());
|
Logger.getLogger(CreateBlogActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||||
private EditText nameEntry = null;
|
private EditText nameEntry = null;
|
||||||
private RadioGroup radioGroup = null;
|
private RadioGroup radioGroup = null;
|
||||||
@@ -75,6 +71,7 @@ SelectContactsDialog.Listener {
|
|||||||
@Inject private volatile GroupFactory groupFactory;
|
@Inject private volatile GroupFactory groupFactory;
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile Collection<ContactId> selected = Collections.emptyList();
|
private volatile Collection<ContactId> selected = Collections.emptyList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,10 +132,6 @@ SelectContactsDialog.Listener {
|
|||||||
layout.addView(progress);
|
layout.addView(progress);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableOrDisableCreateButton() {
|
private void enableOrDisableCreateButton() {
|
||||||
@@ -149,12 +142,6 @@ SelectContactsDialog.Listener {
|
|||||||
createButton.setEnabled(nameNotEmpty && visibilitySelected);
|
createButton.setEnabled(nameNotEmpty && visibilitySelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||||
validateName();
|
validateName();
|
||||||
return true;
|
return true;
|
||||||
@@ -197,7 +184,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -240,7 +227,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addLocalGroup(g);
|
db.addLocalGroup(g);
|
||||||
db.subscribe(g);
|
db.subscribe(g);
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import java.util.List;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
@@ -24,6 +22,7 @@ import net.sf.briar.api.db.event.DatabaseListener;
|
|||||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupStatus;
|
import net.sf.briar.api.messaging.GroupStatus;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -42,9 +41,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ManageBlogsActivity.class.getName());
|
Logger.getLogger(ManageBlogsActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private ManageBlogsAdapter adapter = null;
|
private ManageBlogsAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
@@ -52,6 +48,7 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -66,10 +63,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
// Show a progress bar while the list is loading
|
// Show a progress bar while the list is loading
|
||||||
loading = new ListLoadingProgressBar(this);
|
loading = new ListLoadingProgressBar(this);
|
||||||
setContentView(loading);
|
setContentView(loading);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +76,7 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
List<GroupStatus> available = new ArrayList<GroupStatus>();
|
List<GroupStatus> available = new ArrayList<GroupStatus>();
|
||||||
for(GroupStatus s : db.getAvailableGroups())
|
for(GroupStatus s : db.getAvailableGroups())
|
||||||
@@ -125,12 +118,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
|
|||||||
@@ -19,14 +19,13 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.NoSuchMessageException;
|
import net.sf.briar.api.db.NoSuchMessageException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.MessageId;
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
import net.sf.briar.api.messaging.Rating;
|
import net.sf.briar.api.messaging.Rating;
|
||||||
@@ -55,9 +54,6 @@ implements OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ReadBlogPostActivity.class.getName());
|
Logger.getLogger(ReadBlogPostActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private GroupId groupId = null;
|
private GroupId groupId = null;
|
||||||
private boolean postable = false;
|
private boolean postable = false;
|
||||||
private Rating rating = UNRATED;
|
private Rating rating = UNRATED;
|
||||||
@@ -70,6 +66,7 @@ implements OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile MessageId messageId = null;
|
private volatile MessageId messageId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -196,17 +193,13 @@ implements OnClickListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReadInDatabase(final boolean read) {
|
private void setReadInDatabase(final boolean read) {
|
||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.setReadFlag(messageId, read);
|
db.setReadFlag(messageId, read);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -239,7 +232,7 @@ implements OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] body = db.getMessageBody(messageId);
|
byte[] body = db.getMessageBody(messageId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -278,12 +271,6 @@ implements OnClickListener {
|
|||||||
state.putBoolean("net.sf.briar.READ", read);
|
state.putBoolean("net.sf.briar.READ", read);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(view == readButton) {
|
if(view == readButton) {
|
||||||
setReadInDatabase(!read);
|
setReadInDatabase(!read);
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.identity.CreateIdentityActivity;
|
import net.sf.briar.android.identity.CreateIdentityActivity;
|
||||||
import net.sf.briar.android.identity.LocalAuthorItem;
|
import net.sf.briar.android.identity.LocalAuthorItem;
|
||||||
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
||||||
@@ -31,6 +29,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.crypto.KeyParser;
|
import net.sf.briar.api.crypto.KeyParser;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.LocalGroup;
|
import net.sf.briar.api.messaging.LocalGroup;
|
||||||
import net.sf.briar.api.messaging.Message;
|
import net.sf.briar.api.messaging.Message;
|
||||||
@@ -58,9 +57,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(WriteBlogPostActivity.class.getName());
|
Logger.getLogger(WriteBlogPostActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject private CryptoComponent crypto;
|
@Inject private CryptoComponent crypto;
|
||||||
@Inject private MessageFactory messageFactory;
|
@Inject private MessageFactory messageFactory;
|
||||||
private LocalAuthorSpinnerAdapter fromAdapter = null;
|
private LocalAuthorSpinnerAdapter fromAdapter = null;
|
||||||
@@ -74,6 +70,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile LocalAuthor localAuthor = null;
|
private volatile LocalAuthor localAuthor = null;
|
||||||
private volatile LocalGroup localGroup = null;
|
private volatile LocalGroup localGroup = null;
|
||||||
private volatile MessageId parentId = null;
|
private volatile MessageId parentId = null;
|
||||||
@@ -152,10 +149,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
layout.addView(content);
|
layout.addView(content);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,7 +162,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -216,7 +209,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<LocalGroup> groups = db.getLocalGroups();
|
Collection<LocalGroup> groups = db.getLocalGroups();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -269,12 +262,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||||
long id) {
|
long id) {
|
||||||
if(parent == fromSpinner) {
|
if(parent == fromSpinner) {
|
||||||
@@ -350,7 +337,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addLocalGroupMessage(m);
|
db.addLocalGroupMessage(m);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
@@ -37,6 +35,7 @@ import net.sf.briar.api.db.event.ContactAddedEvent;
|
|||||||
import net.sf.briar.api.db.event.ContactRemovedEvent;
|
import net.sf.briar.api.db.event.ContactRemovedEvent;
|
||||||
import net.sf.briar.api.db.event.DatabaseEvent;
|
import net.sf.briar.api.db.event.DatabaseEvent;
|
||||||
import net.sf.briar.api.db.event.DatabaseListener;
|
import net.sf.briar.api.db.event.DatabaseListener;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.transport.ConnectionListener;
|
import net.sf.briar.api.transport.ConnectionListener;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
@@ -60,9 +59,6 @@ ConnectionListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ContactListActivity.class.getName());
|
Logger.getLogger(ContactListActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject private ConnectionRegistry connectionRegistry;
|
@Inject private ConnectionRegistry connectionRegistry;
|
||||||
private ContactListAdapter adapter = null;
|
private ContactListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
@@ -72,6 +68,7 @@ ConnectionListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -118,10 +115,6 @@ ConnectionListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -136,7 +129,7 @@ ConnectionListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
Map<ContactId, Long> times = db.getLastConnected();
|
Map<ContactId, Long> times = db.getLastConnected();
|
||||||
@@ -182,12 +175,6 @@ ConnectionListener {
|
|||||||
connectionRegistry.removeListener(this);
|
connectionRegistry.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(view == addContactButton) {
|
if(view == addContactButton) {
|
||||||
startActivity(new Intent(this, AddContactActivity.class));
|
startActivity(new Intent(this, AddContactActivity.class));
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.contact.SelectContactsDialog;
|
import net.sf.briar.android.contact.SelectContactsDialog;
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.messages.NoContactsDialog;
|
import net.sf.briar.android.messages.NoContactsDialog;
|
||||||
@@ -25,6 +23,7 @@ import net.sf.briar.api.ContactId;
|
|||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -48,9 +47,6 @@ SelectContactsDialog.Listener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConfigureGroupActivity.class.getName());
|
Logger.getLogger(ConfigureGroupActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private boolean subscribed = false;
|
private boolean subscribed = false;
|
||||||
private CheckBox subscribeCheckBox = null;
|
private CheckBox subscribeCheckBox = null;
|
||||||
private RadioGroup radioGroup = null;
|
private RadioGroup radioGroup = null;
|
||||||
@@ -61,6 +57,7 @@ SelectContactsDialog.Listener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile Group group = null;
|
private volatile Group group = null;
|
||||||
private volatile Collection<ContactId> selected = Collections.emptyList();
|
private volatile Collection<ContactId> selected = Collections.emptyList();
|
||||||
|
|
||||||
@@ -125,16 +122,6 @@ SelectContactsDialog.Listener {
|
|||||||
layout.addView(progress);
|
layout.addView(progress);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@@ -162,7 +149,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -206,7 +193,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if(subscribe) {
|
if(subscribe) {
|
||||||
if(!wasSubscribed) db.subscribe(group);
|
if(!wasSubscribed) db.subscribe(group);
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.contact.SelectContactsDialog;
|
import net.sf.briar.android.contact.SelectContactsDialog;
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.messages.NoContactsDialog;
|
import net.sf.briar.android.messages.NoContactsDialog;
|
||||||
@@ -30,6 +28,7 @@ import net.sf.briar.api.ContactId;
|
|||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupFactory;
|
import net.sf.briar.api.messaging.GroupFactory;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -57,9 +56,6 @@ SelectContactsDialog.Listener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CreateGroupActivity.class.getName());
|
Logger.getLogger(CreateGroupActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private EditText nameEntry = null;
|
private EditText nameEntry = null;
|
||||||
private RadioGroup radioGroup = null;
|
private RadioGroup radioGroup = null;
|
||||||
private RadioButton visibleToAll = null, visibleToSome = null;
|
private RadioButton visibleToAll = null, visibleToSome = null;
|
||||||
@@ -70,6 +66,7 @@ SelectContactsDialog.Listener {
|
|||||||
@Inject private volatile GroupFactory groupFactory;
|
@Inject private volatile GroupFactory groupFactory;
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile Collection<ContactId> selected = Collections.emptyList();
|
private volatile Collection<ContactId> selected = Collections.emptyList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -129,10 +126,6 @@ SelectContactsDialog.Listener {
|
|||||||
layout.addView(progress);
|
layout.addView(progress);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableOrDisableCreateButton() {
|
private void enableOrDisableCreateButton() {
|
||||||
@@ -143,12 +136,6 @@ SelectContactsDialog.Listener {
|
|||||||
createButton.setEnabled(nameNotEmpty && visibilitySelected);
|
createButton.setEnabled(nameNotEmpty && visibilitySelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||||
validateName();
|
validateName();
|
||||||
return true;
|
return true;
|
||||||
@@ -172,7 +159,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
Group g = groupFactory.createGroup(name);
|
Group g = groupFactory.createGroup(name);
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.subscribe(g);
|
db.subscribe(g);
|
||||||
@@ -206,7 +193,7 @@ SelectContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.AscendingHeaderComparator;
|
import net.sf.briar.android.AscendingHeaderComparator;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
import net.sf.briar.api.Author;
|
import net.sf.briar.api.Author;
|
||||||
@@ -33,6 +31,7 @@ import net.sf.briar.api.db.event.GroupMessageAddedEvent;
|
|||||||
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
||||||
import net.sf.briar.api.db.event.RatingChangedEvent;
|
import net.sf.briar.api.db.event.RatingChangedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -53,9 +52,6 @@ OnClickListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(GroupActivity.class.getName());
|
Logger.getLogger(GroupActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private String groupName = null;
|
private String groupName = null;
|
||||||
private GroupAdapter adapter = null;
|
private GroupAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
@@ -64,6 +60,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile GroupId groupId = null;
|
private volatile GroupId groupId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,10 +102,6 @@ OnClickListener, OnItemClickListener {
|
|||||||
layout.addView(composeButton);
|
layout.addView(composeButton);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,7 +115,7 @@ OnClickListener, OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getGroupMessageHeaders(groupId);
|
db.getGroupMessageHeaders(groupId);
|
||||||
@@ -194,12 +187,6 @@ OnClickListener, OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof GroupMessageAddedEvent) {
|
if(e instanceof GroupMessageAddedEvent) {
|
||||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
@@ -36,6 +34,7 @@ import net.sf.briar.api.db.event.MessageExpiredEvent;
|
|||||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.GroupStatus;
|
import net.sf.briar.api.messaging.GroupStatus;
|
||||||
@@ -59,9 +58,6 @@ OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(GroupListActivity.class.getName());
|
Logger.getLogger(GroupListActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private GroupListAdapter adapter = null;
|
private GroupListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
@@ -71,6 +67,7 @@ OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -124,10 +121,6 @@ OnItemClickListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -142,7 +135,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
int available = 0;
|
int available = 0;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(GroupStatus s : db.getAvailableGroups()) {
|
for(GroupStatus s : db.getAvailableGroups()) {
|
||||||
@@ -247,12 +240,6 @@ OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof GroupMessageAddedEvent) {
|
if(e instanceof GroupMessageAddedEvent) {
|
||||||
Group g = ((GroupMessageAddedEvent) e).getGroup();
|
Group g = ((GroupMessageAddedEvent) e).getGroup();
|
||||||
@@ -287,7 +274,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<GroupMessageHeader> headers =
|
Collection<GroupMessageHeader> headers =
|
||||||
db.getGroupMessageHeaders(g.getId());
|
db.getGroupMessageHeaders(g.getId());
|
||||||
@@ -327,7 +314,7 @@ OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
int available = 0;
|
int available = 0;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(GroupStatus s : db.getAvailableGroups()) {
|
for(GroupStatus s : db.getAvailableGroups()) {
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import java.util.List;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
@@ -24,6 +22,7 @@ import net.sf.briar.api.db.event.DatabaseListener;
|
|||||||
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
import net.sf.briar.api.db.event.RemoteSubscriptionsUpdatedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
import net.sf.briar.api.db.event.SubscriptionAddedEvent;
|
||||||
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
import net.sf.briar.api.db.event.SubscriptionRemovedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupStatus;
|
import net.sf.briar.api.messaging.GroupStatus;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
@@ -42,9 +41,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ManageGroupsActivity.class.getName());
|
Logger.getLogger(ManageGroupsActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private ManageGroupsAdapter adapter = null;
|
private ManageGroupsAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
@@ -52,6 +48,7 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -66,10 +63,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
// Show a progress bar while the list is loading
|
// Show a progress bar while the list is loading
|
||||||
loading = new ListLoadingProgressBar(this);
|
loading = new ListLoadingProgressBar(this);
|
||||||
setContentView(loading);
|
setContentView(loading);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +76,7 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
List<GroupStatus> available = new ArrayList<GroupStatus>();
|
List<GroupStatus> available = new ArrayList<GroupStatus>();
|
||||||
for(GroupStatus s : db.getAvailableGroups())
|
for(GroupStatus s : db.getAvailableGroups())
|
||||||
@@ -125,12 +118,6 @@ implements DatabaseListener, OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
import net.sf.briar.api.AuthorId;
|
import net.sf.briar.api.AuthorId;
|
||||||
@@ -28,6 +26,7 @@ import net.sf.briar.api.android.DatabaseUiExecutor;
|
|||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.NoSuchMessageException;
|
import net.sf.briar.api.db.NoSuchMessageException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.MessageId;
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
import net.sf.briar.api.messaging.Rating;
|
import net.sf.briar.api.messaging.Rating;
|
||||||
@@ -56,9 +55,6 @@ implements OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ReadGroupPostActivity.class.getName());
|
Logger.getLogger(ReadGroupPostActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private GroupId groupId = null;
|
private GroupId groupId = null;
|
||||||
private Rating rating = UNRATED;
|
private Rating rating = UNRATED;
|
||||||
private boolean read;
|
private boolean read;
|
||||||
@@ -71,6 +67,7 @@ implements OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile MessageId messageId = null;
|
private volatile MessageId messageId = null;
|
||||||
private volatile AuthorId authorId = null;
|
private volatile AuthorId authorId = null;
|
||||||
|
|
||||||
@@ -220,17 +217,13 @@ implements OnClickListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReadInDatabase(final boolean read) {
|
private void setReadInDatabase(final boolean read) {
|
||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.setReadFlag(messageId, read);
|
db.setReadFlag(messageId, read);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -263,7 +256,7 @@ implements OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] body = db.getMessageBody(messageId);
|
byte[] body = db.getMessageBody(messageId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -302,12 +295,6 @@ implements OnClickListener {
|
|||||||
state.putBoolean("net.sf.briar.READ", read);
|
state.putBoolean("net.sf.briar.READ", read);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(view == goodButton) {
|
if(view == goodButton) {
|
||||||
if(rating == BAD) setRatingInDatabase(UNRATED);
|
if(rating == BAD) setRatingInDatabase(UNRATED);
|
||||||
@@ -337,7 +324,7 @@ implements OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.setRating(authorId, r);
|
db.setRating(authorId, r);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.identity.CreateIdentityActivity;
|
import net.sf.briar.android.identity.CreateIdentityActivity;
|
||||||
import net.sf.briar.android.identity.LocalAuthorItem;
|
import net.sf.briar.android.identity.LocalAuthorItem;
|
||||||
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
||||||
@@ -34,6 +32,7 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.crypto.KeyParser;
|
import net.sf.briar.api.crypto.KeyParser;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
import net.sf.briar.api.messaging.GroupId;
|
||||||
import net.sf.briar.api.messaging.Message;
|
import net.sf.briar.api.messaging.Message;
|
||||||
@@ -61,9 +60,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(WriteGroupPostActivity.class.getName());
|
Logger.getLogger(WriteGroupPostActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject private CryptoComponent crypto;
|
@Inject private CryptoComponent crypto;
|
||||||
@Inject private MessageFactory messageFactory;
|
@Inject private MessageFactory messageFactory;
|
||||||
private LocalAuthorSpinnerAdapter fromAdapter = null;
|
private LocalAuthorSpinnerAdapter fromAdapter = null;
|
||||||
@@ -77,6 +73,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile LocalAuthor localAuthor = null;
|
private volatile LocalAuthor localAuthor = null;
|
||||||
private volatile Group group = null;
|
private volatile Group group = null;
|
||||||
private volatile MessageId parentId = null;
|
private volatile MessageId parentId = null;
|
||||||
@@ -155,10 +152,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
layout.addView(content);
|
layout.addView(content);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -172,7 +165,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -219,7 +212,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
List<Group> groups = new ArrayList<Group>();
|
List<Group> groups = new ArrayList<Group>();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(Group g : db.getSubscriptions())
|
for(Group g : db.getSubscriptions())
|
||||||
@@ -274,12 +267,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||||
long id) {
|
long id) {
|
||||||
if(parent == fromSpinner) {
|
if(parent == fromSpinner) {
|
||||||
@@ -352,7 +339,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addLocalGroupMessage(m);
|
db.addLocalGroupMessage(m);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.api.AuthorFactory;
|
import net.sf.briar.api.AuthorFactory;
|
||||||
import net.sf.briar.api.LocalAuthor;
|
import net.sf.briar.api.LocalAuthor;
|
||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
@@ -29,8 +27,8 @@ import net.sf.briar.api.crypto.CryptoComponent;
|
|||||||
import net.sf.briar.api.crypto.CryptoExecutor;
|
import net.sf.briar.api.crypto.CryptoExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -51,9 +49,6 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(CreateIdentityActivity.class.getName());
|
Logger.getLogger(CreateIdentityActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
@Inject @CryptoExecutor private Executor cryptoExecutor;
|
||||||
private EditText nicknameEntry = null;
|
private EditText nicknameEntry = null;
|
||||||
private Button createButton = null;
|
private Button createButton = null;
|
||||||
@@ -64,6 +59,7 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
@Inject private volatile AuthorFactory authorFactory;
|
@Inject private volatile AuthorFactory authorFactory;
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -109,16 +105,6 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
layout.addView(progress);
|
layout.addView(progress);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||||
@@ -154,7 +140,7 @@ implements OnEditorActionListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addLocalAuthor(a);
|
db.addLocalAuthor(a);
|
||||||
db.setRating(a.getId(), GOOD);
|
db.setRating(a.getId(), GOOD);
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import java.util.Collection;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.identity.LocalAuthorItem;
|
import net.sf.briar.android.identity.LocalAuthorItem;
|
||||||
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
import net.sf.briar.android.identity.LocalAuthorItemComparator;
|
||||||
import net.sf.briar.android.identity.LocalAuthorSpinnerAdapter;
|
import net.sf.briar.android.identity.LocalAuthorSpinnerAdapter;
|
||||||
@@ -28,6 +26,7 @@ import net.sf.briar.api.invitation.InvitationListener;
|
|||||||
import net.sf.briar.api.invitation.InvitationState;
|
import net.sf.briar.api.invitation.InvitationState;
|
||||||
import net.sf.briar.api.invitation.InvitationTask;
|
import net.sf.briar.api.invitation.InvitationTask;
|
||||||
import net.sf.briar.api.invitation.InvitationTaskFactory;
|
import net.sf.briar.api.invitation.InvitationTaskFactory;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -46,9 +45,6 @@ implements InvitationListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AddContactActivity.class.getName());
|
Logger.getLogger(AddContactActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
@Inject private CryptoComponent crypto;
|
@Inject private CryptoComponent crypto;
|
||||||
@Inject private InvitationTaskFactory invitationTaskFactory;
|
@Inject private InvitationTaskFactory invitationTaskFactory;
|
||||||
@Inject private ReferenceManager referenceManager;
|
@Inject private ReferenceManager referenceManager;
|
||||||
@@ -69,6 +65,7 @@ implements InvitationListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -159,10 +156,6 @@ implements InvitationListener {
|
|||||||
if(info.getNetworkId() != -1) networkName = info.getSSID();
|
if(info.getNetworkId() != -1) networkName = info.getSSID();
|
||||||
}
|
}
|
||||||
view.wifiStateChanged();
|
view.wifiStateChanged();
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,7 +183,6 @@ implements InvitationListener {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if(task != null) task.removeListener(this);
|
if(task != null) task.removeListener(this);
|
||||||
unregisterReceiver(receiver);
|
unregisterReceiver(receiver);
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setView(AddContactView view) {
|
void setView(AddContactView view) {
|
||||||
@@ -216,7 +208,7 @@ implements InvitationListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.AscendingHeaderComparator;
|
import net.sf.briar.android.AscendingHeaderComparator;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
import net.sf.briar.api.AuthorId;
|
import net.sf.briar.api.AuthorId;
|
||||||
@@ -31,6 +29,7 @@ import net.sf.briar.api.db.event.DatabaseEvent;
|
|||||||
import net.sf.briar.api.db.event.DatabaseListener;
|
import net.sf.briar.api.db.event.DatabaseListener;
|
||||||
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
||||||
import net.sf.briar.api.db.event.PrivateMessageAddedEvent;
|
import net.sf.briar.api.db.event.PrivateMessageAddedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -50,9 +49,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConversationActivity.class.getName());
|
Logger.getLogger(ConversationActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private String contactName = null;
|
private String contactName = null;
|
||||||
private ConversationAdapter adapter = null;
|
private ConversationAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
@@ -61,6 +57,7 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
private volatile AuthorId localAuthorId = null;
|
private volatile AuthorId localAuthorId = null;
|
||||||
|
|
||||||
@@ -106,10 +103,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
layout.addView(composeButton);
|
layout.addView(composeButton);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,7 +116,7 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<PrivateMessageHeader> headers =
|
Collection<PrivateMessageHeader> headers =
|
||||||
db.getPrivateMessageHeaders(contactId);
|
db.getPrivateMessageHeaders(contactId);
|
||||||
@@ -196,12 +189,6 @@ implements DatabaseListener, OnClickListener, OnItemClickListener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventOccurred(DatabaseEvent e) {
|
public void eventOccurred(DatabaseEvent e) {
|
||||||
if(e instanceof ContactRemovedEvent) {
|
if(e instanceof ContactRemovedEvent) {
|
||||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.invitation.AddContactActivity;
|
import net.sf.briar.android.invitation.AddContactActivity;
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
import net.sf.briar.android.widgets.ListLoadingProgressBar;
|
||||||
@@ -32,6 +30,7 @@ import net.sf.briar.api.db.event.DatabaseEvent;
|
|||||||
import net.sf.briar.api.db.event.DatabaseListener;
|
import net.sf.briar.api.db.event.DatabaseListener;
|
||||||
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
import net.sf.briar.api.db.event.MessageExpiredEvent;
|
||||||
import net.sf.briar.api.db.event.PrivateMessageAddedEvent;
|
import net.sf.briar.api.db.event.PrivateMessageAddedEvent;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import roboguice.activity.RoboFragmentActivity;
|
import roboguice.activity.RoboFragmentActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -49,9 +48,6 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ConversationListActivity.class.getName());
|
Logger.getLogger(ConversationListActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private ConversationListAdapter adapter = null;
|
private ConversationListAdapter adapter = null;
|
||||||
private ListView list = null;
|
private ListView list = null;
|
||||||
private ListLoadingProgressBar loading = null;
|
private ListLoadingProgressBar loading = null;
|
||||||
@@ -59,6 +55,7 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
@@ -90,10 +87,6 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
layout.addView(composeButton);
|
layout.addView(composeButton);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,7 +101,7 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for(Contact c : db.getContacts()) {
|
for(Contact c : db.getContacts()) {
|
||||||
try {
|
try {
|
||||||
@@ -191,12 +184,6 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
db.removeListener(this);
|
db.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(adapter.isEmpty()) {
|
if(adapter.isEmpty()) {
|
||||||
NoContactsDialog dialog = new NoContactsDialog();
|
NoContactsDialog dialog = new NoContactsDialog();
|
||||||
@@ -225,7 +212,7 @@ implements OnClickListener, DatabaseListener, NoContactsDialog.Listener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Contact contact = db.getContact(c);
|
Contact contact = db.getContact(c);
|
||||||
Collection<PrivateMessageHeader> headers =
|
Collection<PrivateMessageHeader> headers =
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.widgets.HorizontalBorder;
|
import net.sf.briar.android.widgets.HorizontalBorder;
|
||||||
import net.sf.briar.android.widgets.HorizontalSpace;
|
import net.sf.briar.android.widgets.HorizontalSpace;
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
@@ -28,6 +26,7 @@ import net.sf.briar.api.android.DatabaseUiExecutor;
|
|||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.db.NoSuchMessageException;
|
import net.sf.briar.api.db.NoSuchMessageException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.MessageId;
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
import net.sf.briar.api.messaging.Rating;
|
import net.sf.briar.api.messaging.Rating;
|
||||||
import roboguice.activity.RoboActivity;
|
import roboguice.activity.RoboActivity;
|
||||||
@@ -55,9 +54,6 @@ implements OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ReadPrivateMessageActivity.class.getName());
|
Logger.getLogger(ReadPrivateMessageActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private ContactId contactId = null;
|
private ContactId contactId = null;
|
||||||
private Rating rating = UNRATED;
|
private Rating rating = UNRATED;
|
||||||
private boolean read;
|
private boolean read;
|
||||||
@@ -68,6 +64,7 @@ implements OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
private volatile MessageId messageId = null;
|
private volatile MessageId messageId = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -190,17 +187,13 @@ implements OnClickListener {
|
|||||||
layout.addView(footer);
|
layout.addView(footer);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReadInDatabase(final boolean read) {
|
private void setReadInDatabase(final boolean read) {
|
||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.setReadFlag(messageId, read);
|
db.setReadFlag(messageId, read);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -233,7 +226,7 @@ implements OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
byte[] body = db.getMessageBody(messageId);
|
byte[] body = db.getMessageBody(messageId);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -272,12 +265,6 @@ implements OnClickListener {
|
|||||||
state.putBoolean("net.sf.briar.READ", read);
|
state.putBoolean("net.sf.briar.READ", read);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(view == readButton) {
|
if(view == readButton) {
|
||||||
setReadInDatabase(!read);
|
setReadInDatabase(!read);
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.R;
|
import net.sf.briar.R;
|
||||||
import net.sf.briar.android.BriarService;
|
|
||||||
import net.sf.briar.android.BriarService.BriarServiceConnection;
|
|
||||||
import net.sf.briar.android.contact.ContactItem;
|
import net.sf.briar.android.contact.ContactItem;
|
||||||
import net.sf.briar.android.contact.ContactItemComparator;
|
import net.sf.briar.android.contact.ContactItemComparator;
|
||||||
import net.sf.briar.android.contact.ContactSpinnerAdapter;
|
import net.sf.briar.android.contact.ContactSpinnerAdapter;
|
||||||
@@ -31,6 +29,7 @@ import net.sf.briar.api.LocalAuthor;
|
|||||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.messaging.Message;
|
import net.sf.briar.api.messaging.Message;
|
||||||
import net.sf.briar.api.messaging.MessageFactory;
|
import net.sf.briar.api.messaging.MessageFactory;
|
||||||
import net.sf.briar.api.messaging.MessageId;
|
import net.sf.briar.api.messaging.MessageId;
|
||||||
@@ -56,9 +55,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(WritePrivateMessageActivity.class.getName());
|
Logger.getLogger(WritePrivateMessageActivity.class.getName());
|
||||||
|
|
||||||
private final BriarServiceConnection serviceConnection =
|
|
||||||
new BriarServiceConnection();
|
|
||||||
|
|
||||||
private TextView from = null;
|
private TextView from = null;
|
||||||
private ContactSpinnerAdapter adapter = null;
|
private ContactSpinnerAdapter adapter = null;
|
||||||
private Spinner spinner = null;
|
private Spinner spinner = null;
|
||||||
@@ -68,6 +64,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject private volatile DatabaseComponent db;
|
@Inject private volatile DatabaseComponent db;
|
||||||
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
@Inject @DatabaseUiExecutor private volatile Executor dbUiExecutor;
|
||||||
|
@Inject private volatile LifecycleManager lifecycleManager;
|
||||||
@Inject private volatile MessageFactory messageFactory;
|
@Inject private volatile MessageFactory messageFactory;
|
||||||
private volatile LocalAuthor localAuthor = null;
|
private volatile LocalAuthor localAuthor = null;
|
||||||
private volatile ContactId contactId = null;
|
private volatile ContactId contactId = null;
|
||||||
@@ -139,10 +136,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
layout.addView(content);
|
layout.addView(content);
|
||||||
|
|
||||||
setContentView(layout);
|
setContentView(layout);
|
||||||
|
|
||||||
// Bind to the service so we can wait for it to start
|
|
||||||
bindService(new Intent(BriarService.class.getName()),
|
|
||||||
serviceConnection, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -155,7 +148,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Collection<Contact> contacts = db.getContacts();
|
Collection<Contact> contacts = db.getContacts();
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -201,12 +194,6 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
state.putInt("net.sf.briar.CONTACT_ID", contactId.getInt());
|
state.putInt("net.sf.briar.CONTACT_ID", contactId.getInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(serviceConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||||
long id) {
|
long id) {
|
||||||
ContactItem item = adapter.getItem(position);
|
ContactItem item = adapter.getItem(position);
|
||||||
@@ -227,7 +214,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
localAuthor = db.getLocalAuthor(a);
|
localAuthor = db.getLocalAuthor(a);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
@@ -277,7 +264,7 @@ implements OnItemSelectedListener, OnClickListener {
|
|||||||
dbUiExecutor.execute(new Runnable() {
|
dbUiExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
serviceConnection.waitForDatabase();
|
lifecycleManager.waitForDatabase();
|
||||||
Message m = messageFactory.createPrivateMessage(parentId,
|
Message m = messageFactory.createPrivateMessage(parentId,
|
||||||
"text/plain", body);
|
"text/plain", body);
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.sf.briar.api.lifecycle;
|
||||||
|
|
||||||
|
public interface LifecycleManager {
|
||||||
|
|
||||||
|
/** Starts any services that need to be started at startup. */
|
||||||
|
public void startServices();
|
||||||
|
|
||||||
|
/** Stops any services that need to be stopped at shutdown. */
|
||||||
|
public void stopServices();
|
||||||
|
|
||||||
|
/** Waits for the database to be opened before returning. */
|
||||||
|
public void waitForDatabase() throws InterruptedException;
|
||||||
|
|
||||||
|
/** Waits for all services to start before returning. */
|
||||||
|
public void waitForStartup() throws InterruptedException;
|
||||||
|
|
||||||
|
/** Waits for all services to stop before returning. */
|
||||||
|
public void waitForShutdown() throws InterruptedException;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.reliability;
|
package net.sf.briar.api.reliability;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.PARAMETER;
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
@@ -12,4 +12,4 @@ import com.google.inject.BindingAnnotation;
|
|||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
@Target({ PARAMETER })
|
@Target({ PARAMETER })
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@interface ReliabilityExecutor {}
|
public @interface ReliabilityExecutor {}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.api.transport;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.PARAMETER;
|
import static java.lang.annotation.ElementType.PARAMETER;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
@@ -14,4 +14,4 @@ import com.google.inject.BindingAnnotation;
|
|||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
@Target({ PARAMETER })
|
@Target({ PARAMETER })
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@interface IncomingConnectionExecutor {}
|
public @interface IncomingConnectionExecutor {}
|
||||||
@@ -1,27 +1,22 @@
|
|||||||
package net.sf.briar.crypto;
|
package net.sf.briar.crypto;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.crypto.CryptoExecutor;
|
import net.sf.briar.api.crypto.CryptoExecutor;
|
||||||
import net.sf.briar.util.BoundedExecutor;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
public class CryptoModule extends AbstractModule {
|
public class CryptoModule extends AbstractModule {
|
||||||
|
|
||||||
// FIXME: Determine suitable values for these constants empirically
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum number of tasks that can be queued for execution before
|
|
||||||
* submitting another task will block.
|
|
||||||
*/
|
|
||||||
private static final int MAX_QUEUED_EXECUTOR_TASKS = 10;
|
|
||||||
|
|
||||||
/** The minimum number of executor threads to keep in the pool. */
|
|
||||||
private static final int MIN_EXECUTOR_THREADS = 1;
|
|
||||||
|
|
||||||
/** The maximum number of executor threads. */
|
/** The maximum number of executor threads. */
|
||||||
private static final int MAX_EXECUTOR_THREADS =
|
private static final int MAX_EXECUTOR_THREADS =
|
||||||
Runtime.getRuntime().availableProcessors();
|
Runtime.getRuntime().availableProcessors();
|
||||||
@@ -30,9 +25,16 @@ public class CryptoModule extends AbstractModule {
|
|||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(CryptoComponent.class).to(
|
bind(CryptoComponent.class).to(
|
||||||
CryptoComponentImpl.class).in(Singleton.class);
|
CryptoComponentImpl.class).in(Singleton.class);
|
||||||
// The executor is bounded, so tasks must be independent and short-lived
|
// The queue is unbounded, so tasks can be dependent
|
||||||
bind(Executor.class).annotatedWith(CryptoExecutor.class).toInstance(
|
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||||
new BoundedExecutor(MAX_QUEUED_EXECUTOR_TASKS,
|
// Discard tasks that are submitted during shutdown
|
||||||
MIN_EXECUTOR_THREADS, MAX_EXECUTOR_THREADS));
|
RejectedExecutionHandler policy =
|
||||||
|
new ThreadPoolExecutor.DiscardPolicy();
|
||||||
|
// Create a limited # of threads and keep them in the pool for 60 secs
|
||||||
|
ExecutorService e = new ThreadPoolExecutor(0, MAX_EXECUTOR_THREADS,
|
||||||
|
60, SECONDS, queue, policy);
|
||||||
|
bind(Executor.class).annotatedWith(CryptoExecutor.class).toInstance(e);
|
||||||
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
CryptoExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package net.sf.briar.db;
|
package net.sf.briar.db;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import net.sf.briar.api.clock.Clock;
|
import net.sf.briar.api.clock.Clock;
|
||||||
@@ -21,24 +23,24 @@ import com.google.inject.Singleton;
|
|||||||
|
|
||||||
public class DatabaseModule extends AbstractModule {
|
public class DatabaseModule extends AbstractModule {
|
||||||
|
|
||||||
/**
|
/** The maximum number of executor threads. */
|
||||||
* The maximum number of database threads. When a task is submitted to the
|
private static final int MAX_EXECUTOR_THREADS = 10;
|
||||||
* database executor and no thread is available to run it, the task will be
|
|
||||||
* queued.
|
|
||||||
*/
|
|
||||||
private static final int MAX_DB_THREADS = 10;
|
|
||||||
|
|
||||||
/** How many milliseconds to keep idle threads alive. */
|
|
||||||
private static final int DB_KEEPALIVE = 60 * 1000;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(DatabaseCleaner.class).to(DatabaseCleanerImpl.class);
|
bind(DatabaseCleaner.class).to(DatabaseCleanerImpl.class);
|
||||||
// Use an unbounded queue to prevent deadlock between submitted tasks
|
// The queue is unbounded, so tasks can be dependent
|
||||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||||
bind(Executor.class).annotatedWith(DatabaseExecutor.class).toInstance(
|
// Discard tasks that are submitted during shutdown
|
||||||
new ThreadPoolExecutor(MAX_DB_THREADS, MAX_DB_THREADS,
|
RejectedExecutionHandler policy =
|
||||||
DB_KEEPALIVE, MILLISECONDS, queue));
|
new ThreadPoolExecutor.DiscardPolicy();
|
||||||
|
// Create a limited # of threads and keep them in the pool for 60 secs
|
||||||
|
ExecutorService e = new ThreadPoolExecutor(0, MAX_EXECUTOR_THREADS,
|
||||||
|
60, SECONDS, queue, policy);
|
||||||
|
bind(Executor.class).annotatedWith(
|
||||||
|
DatabaseExecutor.class).toInstance(e);
|
||||||
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
DatabaseExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
116
briar-core/src/net/sf/briar/lifecycle/LifecycleManagerImpl.java
Normal file
116
briar-core/src/net/sf/briar/lifecycle/LifecycleManagerImpl.java
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
package net.sf.briar.lifecycle;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.sf.briar.api.crypto.CryptoExecutor;
|
||||||
|
import net.sf.briar.api.crypto.KeyManager;
|
||||||
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
|
import net.sf.briar.api.db.DatabaseExecutor;
|
||||||
|
import net.sf.briar.api.db.DbException;
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
|
import net.sf.briar.api.plugins.PluginManager;
|
||||||
|
import net.sf.briar.api.reliability.ReliabilityExecutor;
|
||||||
|
import net.sf.briar.api.transport.IncomingConnectionExecutor;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
class LifecycleManagerImpl implements LifecycleManager {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(LifecycleManagerImpl.class.getName());
|
||||||
|
|
||||||
|
private final DatabaseComponent db;
|
||||||
|
private final KeyManager keyManager;
|
||||||
|
private final PluginManager pluginManager;
|
||||||
|
private final ExecutorService cryptoExecutor;
|
||||||
|
private final ExecutorService dbExecutor;
|
||||||
|
private final ExecutorService connExecutor;
|
||||||
|
private final ExecutorService pluginExecutor;
|
||||||
|
private final ExecutorService reliabilityExecutor;
|
||||||
|
private final CountDownLatch dbLatch = new CountDownLatch(1);
|
||||||
|
private final CountDownLatch startupLatch = new CountDownLatch(1);
|
||||||
|
private final CountDownLatch shutdownLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LifecycleManagerImpl(DatabaseComponent db, KeyManager keyManager,
|
||||||
|
PluginManager pluginManager,
|
||||||
|
@CryptoExecutor ExecutorService cryptoExecutor,
|
||||||
|
@DatabaseExecutor ExecutorService dbExecutor,
|
||||||
|
@IncomingConnectionExecutor ExecutorService connExecutor,
|
||||||
|
@PluginExecutor ExecutorService pluginExecutor,
|
||||||
|
@ReliabilityExecutor ExecutorService reliabilityExecutor) {
|
||||||
|
this.db = db;
|
||||||
|
this.keyManager = keyManager;
|
||||||
|
this.pluginManager = pluginManager;
|
||||||
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
|
this.dbExecutor = dbExecutor;
|
||||||
|
this.connExecutor = connExecutor;
|
||||||
|
this.pluginExecutor = pluginExecutor;
|
||||||
|
this.reliabilityExecutor = reliabilityExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startServices() {
|
||||||
|
try {
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Starting");
|
||||||
|
boolean reopened = db.open();
|
||||||
|
if(LOG.isLoggable(INFO)) {
|
||||||
|
if(reopened) LOG.info("Database reopened");
|
||||||
|
else LOG.info("Database created");
|
||||||
|
}
|
||||||
|
dbLatch.countDown();
|
||||||
|
keyManager.start();
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Key manager started");
|
||||||
|
int pluginsStarted = pluginManager.start();
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info(pluginsStarted + " plugins started");
|
||||||
|
startupLatch.countDown();
|
||||||
|
} catch(DbException e) {
|
||||||
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
} catch(IOException e) {
|
||||||
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopServices() {
|
||||||
|
try {
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Shutting down");
|
||||||
|
int pluginsStopped = pluginManager.stop();
|
||||||
|
if(LOG.isLoggable(INFO))
|
||||||
|
LOG.info(pluginsStopped + " plugins stopped");
|
||||||
|
keyManager.stop();
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Key manager stopped");
|
||||||
|
db.close();
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Database closed");
|
||||||
|
cryptoExecutor.shutdownNow();
|
||||||
|
dbExecutor.shutdownNow();
|
||||||
|
connExecutor.shutdownNow();
|
||||||
|
pluginExecutor.shutdownNow();
|
||||||
|
reliabilityExecutor.shutdownNow();
|
||||||
|
if(LOG.isLoggable(INFO)) LOG.info("Executors shut down");
|
||||||
|
shutdownLatch.countDown();
|
||||||
|
} catch(DbException e) {
|
||||||
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
} catch(IOException e) {
|
||||||
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitForDatabase() throws InterruptedException {
|
||||||
|
dbLatch.await();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitForStartup() throws InterruptedException {
|
||||||
|
startupLatch.await();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void waitForShutdown() throws InterruptedException {
|
||||||
|
shutdownLatch.await();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
package net.sf.briar.lifecycle;
|
package net.sf.briar.lifecycle;
|
||||||
|
|
||||||
|
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||||
import net.sf.briar.util.OsUtils;
|
import net.sf.briar.util.OsUtils;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
public class LifecycleModule extends AbstractModule {
|
public class LifecycleModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
bind(LifecycleManager.class).to(LifecycleManagerImpl.class).in(
|
||||||
|
Singleton.class);
|
||||||
if(OsUtils.isWindows())
|
if(OsUtils.isWindows())
|
||||||
bind(ShutdownManager.class).to(WindowsShutdownManagerImpl.class);
|
bind(ShutdownManager.class).to(WindowsShutdownManagerImpl.class);
|
||||||
else bind(ShutdownManager.class).to(ShutdownManagerImpl.class);
|
else bind(ShutdownManager.class).to(ShutdownManagerImpl.class);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.sf.briar.plugins;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||||
@@ -28,7 +28,7 @@ public class JavaSePluginsModule extends AbstractModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
SimplexPluginConfig getSimplexPluginConfig(
|
SimplexPluginConfig getSimplexPluginConfig(
|
||||||
@PluginExecutor ExecutorService pluginExecutor) {
|
@PluginExecutor Executor pluginExecutor) {
|
||||||
SimplexPluginFactory removable =
|
SimplexPluginFactory removable =
|
||||||
new RemovableDrivePluginFactory(pluginExecutor);
|
new RemovableDrivePluginFactory(pluginExecutor);
|
||||||
final Collection<SimplexPluginFactory> factories =
|
final Collection<SimplexPluginFactory> factories =
|
||||||
@@ -42,7 +42,7 @@ public class JavaSePluginsModule extends AbstractModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
DuplexPluginConfig getDuplexPluginConfig(
|
DuplexPluginConfig getDuplexPluginConfig(
|
||||||
@PluginExecutor ExecutorService pluginExecutor,
|
@PluginExecutor Executor pluginExecutor,
|
||||||
CryptoComponent crypto, ReliabilityLayerFactory reliabilityFactory,
|
CryptoComponent crypto, ReliabilityLayerFactory reliabilityFactory,
|
||||||
ShutdownManager shutdownManager) {
|
ShutdownManager shutdownManager) {
|
||||||
DuplexPluginFactory bluetooth = new BluetoothPluginFactory(
|
DuplexPluginFactory bluetooth = new BluetoothPluginFactory(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -19,7 +19,6 @@ import net.sf.briar.api.ContactId;
|
|||||||
import net.sf.briar.api.TransportConfig;
|
import net.sf.briar.api.TransportConfig;
|
||||||
import net.sf.briar.api.TransportId;
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.TransportProperties;
|
import net.sf.briar.api.TransportProperties;
|
||||||
import net.sf.briar.api.android.AndroidExecutor;
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.db.DbException;
|
import net.sf.briar.api.db.DbException;
|
||||||
import net.sf.briar.api.plugins.Plugin;
|
import net.sf.briar.api.plugins.Plugin;
|
||||||
@@ -49,8 +48,7 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(PluginManagerImpl.class.getName());
|
Logger.getLogger(PluginManagerImpl.class.getName());
|
||||||
|
|
||||||
private final ExecutorService pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final AndroidExecutor androidExecutor;
|
|
||||||
private final SimplexPluginConfig simplexPluginConfig;
|
private final SimplexPluginConfig simplexPluginConfig;
|
||||||
private final DuplexPluginConfig duplexPluginConfig;
|
private final DuplexPluginConfig duplexPluginConfig;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
@@ -61,14 +59,12 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
private final List<DuplexPlugin> duplexPlugins;
|
private final List<DuplexPlugin> duplexPlugins;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PluginManagerImpl(@PluginExecutor ExecutorService pluginExecutor,
|
PluginManagerImpl(@PluginExecutor Executor pluginExecutor,
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
SimplexPluginConfig simplexPluginConfig,
|
SimplexPluginConfig simplexPluginConfig,
|
||||||
DuplexPluginConfig duplexPluginConfig, DatabaseComponent db,
|
DuplexPluginConfig duplexPluginConfig, DatabaseComponent db,
|
||||||
Poller poller, ConnectionDispatcher dispatcher,
|
Poller poller, ConnectionDispatcher dispatcher,
|
||||||
UiCallback uiCallback) {
|
UiCallback uiCallback) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.androidExecutor = androidExecutor;
|
|
||||||
this.simplexPluginConfig = simplexPluginConfig;
|
this.simplexPluginConfig = simplexPluginConfig;
|
||||||
this.duplexPluginConfig = duplexPluginConfig;
|
this.duplexPluginConfig = duplexPluginConfig;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -144,10 +140,6 @@ class PluginManagerImpl implements PluginManager {
|
|||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Shut down the executors
|
|
||||||
if(LOG.isLoggable(INFO)) LOG.info("Stopping executors");
|
|
||||||
pluginExecutor.shutdown();
|
|
||||||
androidExecutor.shutdown();
|
|
||||||
// Return the number of plugins successfully stopped
|
// Return the number of plugins successfully stopped
|
||||||
return stopped.get();
|
return stopped.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package net.sf.briar.plugins;
|
package net.sf.briar.plugins;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import net.sf.briar.api.plugins.PluginExecutor;
|
import net.sf.briar.api.plugins.PluginExecutor;
|
||||||
import net.sf.briar.api.plugins.PluginManager;
|
import net.sf.briar.api.plugins.PluginManager;
|
||||||
@@ -13,12 +19,19 @@ public class PluginsModule extends AbstractModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// The executor is unbounded, so tasks can be dependent or long-lived
|
|
||||||
ExecutorService e = Executors.newCachedThreadPool();
|
|
||||||
bind(ExecutorService.class).annotatedWith(
|
|
||||||
PluginExecutor.class).toInstance(e);
|
|
||||||
bind(PluginManager.class).to(
|
bind(PluginManager.class).to(
|
||||||
PluginManagerImpl.class).in(Singleton.class);
|
PluginManagerImpl.class).in(Singleton.class);
|
||||||
bind(Poller.class).to(PollerImpl.class);
|
bind(Poller.class).to(PollerImpl.class);
|
||||||
|
// The thread pool is unbounded, so use direct handoff
|
||||||
|
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
|
||||||
|
// Discard tasks that are submitted during shutdown
|
||||||
|
RejectedExecutionHandler policy =
|
||||||
|
new ThreadPoolExecutor.DiscardPolicy();
|
||||||
|
// Create threads as required and keep them in the pool for 60 seconds
|
||||||
|
ExecutorService e = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||||
|
60, SECONDS, queue, policy);
|
||||||
|
bind(Executor.class).annotatedWith(PluginExecutor.class).toInstance(e);
|
||||||
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
PluginExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import static java.util.logging.Level.INFO;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
@@ -21,13 +21,13 @@ class PollerImpl implements Poller, Runnable {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(PollerImpl.class.getName());
|
Logger.getLogger(PollerImpl.class.getName());
|
||||||
|
|
||||||
private final ExecutorService pluginExecutor;
|
private final Executor pluginExecutor;
|
||||||
private final ConnectionRegistry connRegistry;
|
private final ConnectionRegistry connRegistry;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final SortedSet<PollTime> pollTimes;
|
private final SortedSet<PollTime> pollTimes;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PollerImpl(@PluginExecutor ExecutorService pluginExecutor,
|
PollerImpl(@PluginExecutor Executor pluginExecutor,
|
||||||
ConnectionRegistry connRegistry, Clock clock) {
|
ConnectionRegistry connRegistry, Clock clock) {
|
||||||
this.pluginExecutor = pluginExecutor;
|
this.pluginExecutor = pluginExecutor;
|
||||||
this.connRegistry = connRegistry;
|
this.connRegistry = connRegistry;
|
||||||
@@ -71,7 +71,7 @@ class PollerImpl implements Poller, Runnable {
|
|||||||
connRegistry.getConnectedContacts(p.plugin.getId());
|
connRegistry.getConnectedContacts(p.plugin.getId());
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Polling " + p.plugin.getClass().getName());
|
LOG.info("Polling " + p.plugin.getClass().getName());
|
||||||
pluginExecutor.submit(new Runnable() {
|
pluginExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
p.plugin.poll(connected);
|
p.plugin.poll(connected);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import net.sf.briar.api.clock.Clock;
|
import net.sf.briar.api.clock.Clock;
|
||||||
import net.sf.briar.api.clock.SystemClock;
|
import net.sf.briar.api.clock.SystemClock;
|
||||||
|
import net.sf.briar.api.reliability.ReliabilityExecutor;
|
||||||
import net.sf.briar.api.reliability.ReliabilityLayer;
|
import net.sf.briar.api.reliability.ReliabilityLayer;
|
||||||
import net.sf.briar.api.reliability.ReliabilityLayerFactory;
|
import net.sf.briar.api.reliability.ReliabilityLayerFactory;
|
||||||
import net.sf.briar.api.reliability.WriteHandler;
|
import net.sf.briar.api.reliability.WriteHandler;
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
package net.sf.briar.reliability;
|
package net.sf.briar.reliability;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
|
import net.sf.briar.api.reliability.ReliabilityExecutor;
|
||||||
import net.sf.briar.api.reliability.ReliabilityLayerFactory;
|
import net.sf.briar.api.reliability.ReliabilityLayerFactory;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
@@ -11,11 +18,19 @@ public class ReliabilityModule extends AbstractModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
// The executor is unbounded - tasks are expected to be long-lived
|
|
||||||
Executor e = Executors.newCachedThreadPool();
|
|
||||||
bind(Executor.class).annotatedWith(
|
|
||||||
ReliabilityExecutor.class).toInstance(e);
|
|
||||||
bind(ReliabilityLayerFactory.class).to(
|
bind(ReliabilityLayerFactory.class).to(
|
||||||
ReliabilityLayerFactoryImpl.class);
|
ReliabilityLayerFactoryImpl.class);
|
||||||
|
// The thread pool is unbounded, so use direct handoff
|
||||||
|
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
|
||||||
|
// Discard tasks that are submitted during shutdown
|
||||||
|
RejectedExecutionHandler policy =
|
||||||
|
new ThreadPoolExecutor.DiscardPolicy();
|
||||||
|
// Create threads as required and keep them in the pool for 60 seconds
|
||||||
|
ExecutorService e = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||||
|
60, SECONDS, queue, policy);
|
||||||
|
bind(Executor.class).annotatedWith(
|
||||||
|
ReliabilityExecutor.class).toInstance(e);
|
||||||
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
ReliabilityExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
|
|||||||
import net.sf.briar.api.transport.ConnectionContext;
|
import net.sf.briar.api.transport.ConnectionContext;
|
||||||
import net.sf.briar.api.transport.ConnectionDispatcher;
|
import net.sf.briar.api.transport.ConnectionDispatcher;
|
||||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||||
|
import net.sf.briar.api.transport.IncomingConnectionExecutor;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package net.sf.briar.transport;
|
package net.sf.briar.transport;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
import net.sf.briar.api.crypto.KeyManager;
|
import net.sf.briar.api.crypto.KeyManager;
|
||||||
import net.sf.briar.api.transport.ConnectionDispatcher;
|
import net.sf.briar.api.transport.ConnectionDispatcher;
|
||||||
@@ -9,6 +15,7 @@ import net.sf.briar.api.transport.ConnectionReaderFactory;
|
|||||||
import net.sf.briar.api.transport.ConnectionRecogniser;
|
import net.sf.briar.api.transport.ConnectionRecogniser;
|
||||||
import net.sf.briar.api.transport.ConnectionRegistry;
|
import net.sf.briar.api.transport.ConnectionRegistry;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
|
import net.sf.briar.api.transport.IncomingConnectionExecutor;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -25,10 +32,18 @@ public class TransportModule extends AbstractModule {
|
|||||||
bind(ConnectionRegistry.class).toInstance(new ConnectionRegistryImpl());
|
bind(ConnectionRegistry.class).toInstance(new ConnectionRegistryImpl());
|
||||||
bind(ConnectionWriterFactory.class).to(
|
bind(ConnectionWriterFactory.class).to(
|
||||||
ConnectionWriterFactoryImpl.class);
|
ConnectionWriterFactoryImpl.class);
|
||||||
// The executor is unbounded, so tasks can be dependent or long-lived
|
bind(KeyManager.class).to(KeyManagerImpl.class).in(Singleton.class);
|
||||||
Executor e = Executors.newCachedThreadPool();
|
// The thread pool is unbounded, so use direct handoff
|
||||||
|
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
|
||||||
|
// Discard tasks that are submitted during shutdown
|
||||||
|
RejectedExecutionHandler policy =
|
||||||
|
new ThreadPoolExecutor.DiscardPolicy();
|
||||||
|
// Create threads as required and keep them in the pool for 60 seconds
|
||||||
|
ExecutorService e = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||||
|
60, SECONDS, queue, policy);
|
||||||
bind(Executor.class).annotatedWith(
|
bind(Executor.class).annotatedWith(
|
||||||
IncomingConnectionExecutor.class).toInstance(e);
|
IncomingConnectionExecutor.class).toInstance(e);
|
||||||
bind(KeyManager.class).to(KeyManagerImpl.class).in(Singleton.class);
|
bind(ExecutorService.class).annotatedWith(
|
||||||
|
IncomingConnectionExecutor.class).toInstance(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
package net.sf.briar.util;
|
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
|
||||||
import static java.util.logging.Level.INFO;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
|
||||||
import java.util.concurrent.Semaphore;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An executor that limits the number of concurrently executing tasks and the
|
|
||||||
* number of tasks queued for execution.
|
|
||||||
*/
|
|
||||||
public class BoundedExecutor implements Executor {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(BoundedExecutor.class.getName());
|
|
||||||
|
|
||||||
private final Semaphore semaphore;
|
|
||||||
private final BlockingQueue<Runnable> queue;
|
|
||||||
private final Executor executor;
|
|
||||||
|
|
||||||
public BoundedExecutor(int maxQueued, int minThreads, int maxThreads) {
|
|
||||||
semaphore = new Semaphore(maxQueued + maxThreads);
|
|
||||||
queue = new LinkedBlockingQueue<Runnable>();
|
|
||||||
executor = new ThreadPoolExecutor(minThreads, maxThreads, 60, SECONDS,
|
|
||||||
queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(final Runnable r) {
|
|
||||||
try {
|
|
||||||
semaphore.acquire();
|
|
||||||
executor.execute(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
r.run();
|
|
||||||
} finally {
|
|
||||||
semaphore.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch(InterruptedException e) {
|
|
||||||
if(LOG.isLoggable(INFO))
|
|
||||||
LOG.info("Interrupted while queueing task");
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw new RejectedExecutionException();
|
|
||||||
} catch(RejectedExecutionException e) {
|
|
||||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
|
||||||
semaphore.release();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -48,6 +48,9 @@ import net.sf.briar.lifecycle.LifecycleModule;
|
|||||||
import net.sf.briar.messaging.MessagingModule;
|
import net.sf.briar.messaging.MessagingModule;
|
||||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||||
import net.sf.briar.messaging.simplex.SimplexMessagingModule;
|
import net.sf.briar.messaging.simplex.SimplexMessagingModule;
|
||||||
|
import net.sf.briar.plugins.JavaSePluginsModule;
|
||||||
|
import net.sf.briar.plugins.PluginsModule;
|
||||||
|
import net.sf.briar.reliability.ReliabilityModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -79,9 +82,11 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
|||||||
public ProtocolIntegrationTest() throws Exception {
|
public ProtocolIntegrationTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
Injector i = Guice.createInjector(new TestDatabaseModule(),
|
||||||
new ClockModule(), new CryptoModule(), new DatabaseModule(),
|
new TestUiModule(), new ClockModule(), new CryptoModule(),
|
||||||
new LifecycleModule(), new MessagingModule(),
|
new DatabaseModule(), new LifecycleModule(),
|
||||||
new DuplexMessagingModule(), new SimplexMessagingModule(),
|
new MessagingModule(), new DuplexMessagingModule(),
|
||||||
|
new SimplexMessagingModule(), new PluginsModule(),
|
||||||
|
new JavaSePluginsModule(), new ReliabilityModule(),
|
||||||
new SerialModule(), new TransportModule());
|
new SerialModule(), new TransportModule());
|
||||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
|
|||||||
24
briar-tests/src/net/sf/briar/TestUiModule.java
Normal file
24
briar-tests/src/net/sf/briar/TestUiModule.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package net.sf.briar;
|
||||||
|
|
||||||
|
import net.sf.briar.api.ui.UiCallback;
|
||||||
|
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
|
|
||||||
|
public class TestUiModule extends AbstractModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
bind(UiCallback.class).toInstance(new UiCallback() {
|
||||||
|
|
||||||
|
public int showChoice(String[] options, String... message) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showConfirmationMessage(String... message) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showMessage(String... message) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import net.sf.briar.BriarTestCase;
|
import net.sf.briar.BriarTestCase;
|
||||||
import net.sf.briar.TestDatabaseModule;
|
import net.sf.briar.TestDatabaseModule;
|
||||||
|
import net.sf.briar.TestUiModule;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.Author;
|
import net.sf.briar.api.Author;
|
||||||
import net.sf.briar.api.AuthorId;
|
import net.sf.briar.api.AuthorId;
|
||||||
@@ -38,6 +39,9 @@ import net.sf.briar.lifecycle.LifecycleModule;
|
|||||||
import net.sf.briar.messaging.MessagingModule;
|
import net.sf.briar.messaging.MessagingModule;
|
||||||
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
import net.sf.briar.messaging.duplex.DuplexMessagingModule;
|
||||||
import net.sf.briar.plugins.ImmediateExecutor;
|
import net.sf.briar.plugins.ImmediateExecutor;
|
||||||
|
import net.sf.briar.plugins.JavaSePluginsModule;
|
||||||
|
import net.sf.briar.plugins.PluginsModule;
|
||||||
|
import net.sf.briar.reliability.ReliabilityModule;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
import net.sf.briar.transport.TransportModule;
|
import net.sf.briar.transport.TransportModule;
|
||||||
|
|
||||||
@@ -80,11 +84,13 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Injector createInjector(File dir) {
|
private Injector createInjector(File dir) {
|
||||||
return Guice.createInjector(new ClockModule(), new CryptoModule(),
|
return Guice.createInjector(new TestDatabaseModule(dir),
|
||||||
|
new TestUiModule(), new ClockModule(), new CryptoModule(),
|
||||||
new DatabaseModule(), new LifecycleModule(),
|
new DatabaseModule(), new LifecycleModule(),
|
||||||
new MessagingModule(), new SerialModule(),
|
new MessagingModule(), new DuplexMessagingModule(),
|
||||||
new TestDatabaseModule(dir), new SimplexMessagingModule(),
|
new SimplexMessagingModule(), new PluginsModule(),
|
||||||
new TransportModule(), new DuplexMessagingModule());
|
new JavaSePluginsModule(), new ReliabilityModule(),
|
||||||
|
new SerialModule(), new TransportModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package net.sf.briar.plugins;
|
package net.sf.briar.plugins;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import net.sf.briar.BriarTestCase;
|
import net.sf.briar.BriarTestCase;
|
||||||
import net.sf.briar.TestUtils;
|
import net.sf.briar.TestUtils;
|
||||||
import net.sf.briar.api.TransportId;
|
import net.sf.briar.api.TransportId;
|
||||||
import net.sf.briar.api.android.AndroidExecutor;
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
import net.sf.briar.api.db.DatabaseComponent;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||||
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
|
||||||
@@ -29,9 +28,7 @@ public class PluginManagerImplTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testStartAndStop() throws Exception {
|
public void testStartAndStop() throws Exception {
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
final ExecutorService pluginExecutor = Executors.newCachedThreadPool();
|
final Executor pluginExecutor = Executors.newCachedThreadPool();
|
||||||
final AndroidExecutor androidExecutor =
|
|
||||||
context.mock(AndroidExecutor.class);
|
|
||||||
final SimplexPluginConfig simplexPluginConfig =
|
final SimplexPluginConfig simplexPluginConfig =
|
||||||
context.mock(SimplexPluginConfig.class);
|
context.mock(SimplexPluginConfig.class);
|
||||||
final DuplexPluginConfig duplexPluginConfig =
|
final DuplexPluginConfig duplexPluginConfig =
|
||||||
@@ -119,12 +116,10 @@ public class PluginManagerImplTest extends BriarTestCase {
|
|||||||
// Stop the plugins
|
// Stop the plugins
|
||||||
oneOf(simplexPlugin).stop();
|
oneOf(simplexPlugin).stop();
|
||||||
oneOf(duplexPlugin).stop();
|
oneOf(duplexPlugin).stop();
|
||||||
// Shut down the executor
|
|
||||||
oneOf(androidExecutor).shutdown();
|
|
||||||
}});
|
}});
|
||||||
PluginManagerImpl p = new PluginManagerImpl(pluginExecutor,
|
PluginManagerImpl p = new PluginManagerImpl(pluginExecutor,
|
||||||
androidExecutor, simplexPluginConfig, duplexPluginConfig, db,
|
simplexPluginConfig, duplexPluginConfig, db, poller,
|
||||||
poller, dispatcher, uiCallback);
|
dispatcher, uiCallback);
|
||||||
// Two plugins should be started and stopped
|
// Two plugins should be started and stopped
|
||||||
assertEquals(2, p.start());
|
assertEquals(2, p.start());
|
||||||
assertEquals(2, p.stop());
|
assertEquals(2, p.stop());
|
||||||
|
|||||||
Reference in New Issue
Block a user