mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Switched Roboguice/Guice out for Dagger 2
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package org.briarproject.db;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
@@ -20,11 +17,16 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
public class DatabaseModule extends AbstractModule {
|
||||
@Module
|
||||
public class DatabaseModule {
|
||||
|
||||
private final ExecutorService databaseExecutor;
|
||||
|
||||
@@ -39,30 +41,28 @@ public class DatabaseModule extends AbstractModule {
|
||||
policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@Provides @Singleton
|
||||
Database<Connection> getDatabase(DatabaseConfig config,
|
||||
@Provides
|
||||
@Singleton
|
||||
Database<Connection> provideDatabase(DatabaseConfig config,
|
||||
SecureRandom random, Clock clock) {
|
||||
return new H2Database(config, random, clock);
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
DatabaseComponent getDatabaseComponent(Database<Connection> db,
|
||||
DatabaseComponent provideDatabaseComponent(Database<Connection> db,
|
||||
EventBus eventBus, ShutdownManager shutdown) {
|
||||
return new DatabaseComponentImpl<Connection>(db, Connection.class,
|
||||
eventBus, shutdown);
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseExecutor
|
||||
ExecutorService getDatabaseExecutor(LifecycleManager lifecycleManager) {
|
||||
ExecutorService provideDatabaseExecutorService(LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(databaseExecutor);
|
||||
return databaseExecutor;
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseExecutor
|
||||
Executor getDatabaseExecutor(@DatabaseExecutor ExecutorService dbExecutor) {
|
||||
Executor provideDatabaseExecutor(@DatabaseExecutor ExecutorService dbExecutor) {
|
||||
return dbExecutor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user