Commit f6611daf authored by akwizgran's avatar akwizgran

Replace Client interface with OpenDatabaseHook.

parent 00bc8ac7
package org.briarproject.bramble.api.identity;
import org.briarproject.bramble.api.crypto.CryptoExecutor;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
......@@ -15,17 +17,13 @@ public interface IdentityManager {
LocalAuthor createLocalAuthor(String name);
/**
* Registers the given local identity with the manager. The identity is
* not stored until {@link #storeLocalAuthor()} is called.
* Registers the given local identity with the manager. This method should
* be called before {@link LifecycleManager#startServices(SecretKey)}. The
* identity is stored when {@link LifecycleManager#startServices(SecretKey)}
* is called.
*/
void registerLocalAuthor(LocalAuthor a);
/**
* Stores the local identity registered with
* {@link #registerLocalAuthor(LocalAuthor)}, if any.
*/
void storeLocalAuthor() throws DbException;
/**
* Returns the cached local identity or loads it from the database.
*/
......
......@@ -2,16 +2,17 @@ package org.briarproject.bramble.api.lifecycle;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Client;
import java.util.concurrent.ExecutorService;
/**
* Manages the lifecycle of the app, starting {@link Client Clients}, starting
* and stopping {@link Service Services}, shutting down
* {@link ExecutorService ExecutorServices}, and opening and closing the
* {@link DatabaseComponent}.
* Manages the lifecycle of the app: opening and closing the
* {@link DatabaseComponent} starting and stopping {@link Service Services},
* and shutting down {@link ExecutorService ExecutorServices}.
*/
@NotNullByDefault
public interface LifecycleManager {
......@@ -43,16 +44,17 @@ public interface LifecycleManager {
}
/**
* Registers a {@link Service} to be started and stopped. This method
* should be called before {@link #startServices(SecretKey)}.
* Registers a hook to be called after the database is opened and before
* {@link Service services} are started. This method should be called
* before {@link #startServices(SecretKey)}.
*/
void registerService(Service s);
void registerOpenDatabaseHook(OpenDatabaseHook hook, Priority p);
/**
* Registers a {@link Client} to be started. This method should be called
* before {@link #startServices(SecretKey)}.
* Registers a {@link Service} to be started and stopped. This method
* should be called before {@link #startServices(SecretKey)}.
*/
void registerClient(Client c);
void registerService(Service s);
/**
* Registers an {@link ExecutorService} to be shut down. This method
......@@ -62,7 +64,7 @@ public interface LifecycleManager {
/**
* Opens the {@link DatabaseComponent} using the given key and starts any
* registered {@link Client Clients} and {@link Service Services}.
* registered {@link Service Services}.
*/
StartResult startServices(SecretKey dbKey);
......@@ -80,8 +82,7 @@ public interface LifecycleManager {
/**
* Waits for the {@link DatabaseComponent} to be opened and all registered
* {@link Client Clients} and {@link Service Services} to start before
* returning.
* {@link Service Services} to start before returning.
*/
void waitForStartup() throws InterruptedException;
......@@ -97,4 +98,10 @@ public interface LifecycleManager {
*/
LifecycleState getLifecycleState();
interface OpenDatabaseHook {
enum Priority {EARLY, NORMAL, LATE}
void onDatabaseOpened(Transaction txn) throws DbException;
}
}
\ No newline at end of file
package org.briarproject.bramble.api.sync;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
@NotNullByDefault
public interface Client {
/**
* Called at startup to create any local state needed by the client.
*/
void createLocalState(Transaction txn) throws DbException;
}
......@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.logging.Logger;
......@@ -14,15 +15,16 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logDuration;
import static org.briarproject.bramble.util.LogUtils.now;
@ThreadSafe
@NotNullByDefault
class IdentityManagerImpl implements IdentityManager {
class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
private static final Logger LOG =
Logger.getLogger(IdentityManagerImpl.class.getName());
getLogger(IdentityManagerImpl.class.getName());
private final DatabaseComponent db;
private final AuthorFactory authorFactory;
......@@ -52,13 +54,13 @@ class IdentityManagerImpl implements IdentityManager {
}
@Override
public void storeLocalAuthor() throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
LocalAuthor cached = cachedAuthor;
if (cached == null) {
LOG.info("No local author to store");
return;
}
db.transaction(false, txn -> db.addLocalAuthor(txn, cached));
db.addLocalAuthor(txn, cached);
LOG.info("Local author stored");
}
......@@ -89,5 +91,4 @@ class IdentityManagerImpl implements IdentityManager {
private LocalAuthor loadLocalAuthor(Transaction txn) throws DbException {
return db.getLocalAuthors(txn).iterator().next();
}
}
......@@ -2,6 +2,7 @@ package org.briarproject.bramble.identity;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import javax.inject.Inject;
import javax.inject.Singleton;
......@@ -9,6 +10,8 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority.EARLY;
@Module
public class IdentityModule {
......@@ -24,8 +27,9 @@ public class IdentityModule {
@Provides
@Singleton
IdentityManager provideIdentityManager(
IdentityManager provideIdentityManager(LifecycleManager lifecycleManager,
IdentityManagerImpl identityManager) {
lifecycleManager.registerOpenDatabaseHook(identityManager, EARLY);
return identityManager;
}
}
package org.briarproject.bramble.lifecycle;
import org.briarproject.bramble.api.Pair;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DataTooNewException;
import org.briarproject.bramble.api.db.DataTooOldException;
......@@ -7,14 +8,14 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority;
import org.briarproject.bramble.api.lifecycle.Service;
import org.briarproject.bramble.api.lifecycle.ServiceException;
import org.briarproject.bramble.api.lifecycle.event.LifecycleEvent;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Client;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
......@@ -25,9 +26,11 @@ import java.util.logging.Logger;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static java.util.Collections.sort;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.COMPACTING_DATABASE;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.MIGRATING_DATABASE;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
......@@ -49,14 +52,13 @@ import static org.briarproject.bramble.util.LogUtils.now;
class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
private static final Logger LOG =
Logger.getLogger(LifecycleManagerImpl.class.getName());
getLogger(LifecycleManagerImpl.class.getName());
private final DatabaseComponent db;
private final EventBus eventBus;
private final List<Service> services;
private final List<Client> clients;
private final List<Pair<OpenDatabaseHook, Priority>> openDatabaseHooks;
private final List<ExecutorService> executors;
private final IdentityManager identityManager;
private final Semaphore startStopSemaphore = new Semaphore(1);
private final CountDownLatch dbLatch = new CountDownLatch(1);
private final CountDownLatch startupLatch = new CountDownLatch(1);
......@@ -65,13 +67,11 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
private volatile LifecycleState state = STARTING;
@Inject
LifecycleManagerImpl(DatabaseComponent db, EventBus eventBus,
IdentityManager identityManager) {
LifecycleManagerImpl(DatabaseComponent db, EventBus eventBus) {
this.db = db;
this.eventBus = eventBus;
this.identityManager = identityManager;
services = new CopyOnWriteArrayList<>();
clients = new CopyOnWriteArrayList<>();
openDatabaseHooks = new CopyOnWriteArrayList<>();
executors = new CopyOnWriteArrayList<>();
}
......@@ -83,10 +83,12 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
}
@Override
public void registerClient(Client c) {
if (LOG.isLoggable(INFO))
LOG.info("Registering client " + c.getClass().getSimpleName());
clients.add(c);
public void registerOpenDatabaseHook(OpenDatabaseHook hook, Priority p) {
if (LOG.isLoggable(INFO)) {
LOG.info("Registering open database hook "
+ hook.getClass().getSimpleName());
}
openDatabaseHooks.add(new Pair<>(hook, p));
}
@Override
......@@ -102,28 +104,31 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
return ALREADY_RUNNING;
}
try {
LOG.info("Starting services");
LOG.info("Opening database");
long start = now();
boolean reopened = db.open(dbKey, this);
if (reopened) logDuration(LOG, "Reopening database", start);
else logDuration(LOG, "Creating database", start);
identityManager.storeLocalAuthor();
state = STARTING_SERVICES;
dbLatch.countDown();
eventBus.broadcast(new LifecycleEvent(STARTING_SERVICES));
List<Pair<OpenDatabaseHook, Priority>> hooks =
new ArrayList<>(openDatabaseHooks);
sort(hooks, (a, b) -> a.getSecond().compareTo(b.getSecond()));
db.transaction(false, txn -> {
for (Client c : clients) {
for (Pair<OpenDatabaseHook, Priority> pair : hooks) {
long start1 = now();
c.createLocalState(txn);
OpenDatabaseHook hook = pair.getFirst();
hook.onDatabaseOpened(txn);
if (LOG.isLoggable(FINE)) {
logDuration(LOG, "Starting client "
+ c.getClass().getSimpleName(), start1);
logDuration(LOG, "Calling open database hook "
+ hook.getClass().getSimpleName(), start1);
}
}
});
LOG.info("Starting services");
state = STARTING_SERVICES;
dbLatch.countDown();
eventBus.broadcast(new LifecycleEvent(STARTING_SERVICES));
for (Service s : services) {
start = now();
s.startService();
......
......@@ -15,6 +15,7 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority.NORMAL;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MINOR_VERSION;
......@@ -48,7 +49,8 @@ public class PropertiesModule {
ValidationManager validationManager, ContactManager contactManager,
ClientVersioningManager clientVersioningManager,
TransportPropertyManagerImpl transportPropertyManager) {
lifecycleManager.registerClient(transportPropertyManager);
lifecycleManager.registerOpenDatabaseHook(transportPropertyManager,
NORMAL);
validationManager.registerIncomingMessageHook(CLIENT_ID, MAJOR_VERSION,
transportPropertyManager);
contactManager.registerContactHook(transportPropertyManager);
......
......@@ -13,11 +13,11 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.properties.TransportProperties;
import org.briarproject.bramble.api.properties.TransportPropertyManager;
import org.briarproject.bramble.api.sync.Client;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.Group.Visibility;
import org.briarproject.bramble.api.sync.GroupId;
......@@ -40,7 +40,8 @@ import javax.inject.Inject;
@Immutable
@NotNullByDefault
class TransportPropertyManagerImpl implements TransportPropertyManager,
Client, ContactHook, ClientVersioningHook, IncomingMessageHook {
OpenDatabaseHook, ContactHook, ClientVersioningHook,
IncomingMessageHook {
private final DatabaseComponent db;
private final ClientHelper clientHelper;
......@@ -67,7 +68,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
}
@Override
public void createLocalState(Transaction txn) throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
if (db.containsGroup(txn, localGroup.getId())) return;
db.addGroup(txn, localGroup);
// Set things up for any pre-existing contacts
......
......@@ -12,10 +12,10 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.lifecycle.Service;
import org.briarproject.bramble.api.lifecycle.ServiceException;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Client;
import org.briarproject.bramble.api.sync.ClientId;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.Group.Visibility;
......@@ -53,8 +53,8 @@ import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
@NotNullByDefault
class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
Service, ContactHook, IncomingMessageHook {
class ClientVersioningManagerImpl implements ClientVersioningManager,
Service, OpenDatabaseHook, ContactHook, IncomingMessageHook {
private final DatabaseComponent db;
private final ClientHelper clientHelper;
......@@ -124,7 +124,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
}
@Override
public void createLocalState(Transaction txn) throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
if (db.containsGroup(txn, localGroup.getId())) return;
db.addGroup(txn, localGroup);
// Set things up for any pre-existing contacts
......
......@@ -14,6 +14,7 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority.NORMAL;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.CLIENT_ID;
import static org.briarproject.bramble.api.versioning.ClientVersioningManager.MAJOR_VERSION;
......@@ -34,7 +35,8 @@ public class VersioningModule {
ClientVersioningManagerImpl clientVersioningManager,
LifecycleManager lifecycleManager, ContactManager contactManager,
ValidationManager validationManager) {
lifecycleManager.registerClient(clientVersioningManager);
lifecycleManager.registerOpenDatabaseHook(clientVersioningManager,
NORMAL);
lifecycleManager.registerService(clientVersioningManager);
contactManager.registerContactHook(clientVersioningManager);
validationManager.registerIncomingMessageHook(CLIENT_ID, MAJOR_VERSION,
......
......@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.DbExpectations;
......@@ -27,7 +26,7 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
private final LocalAuthor localAuthor = getLocalAuthor();
private final Collection<LocalAuthor> localAuthors =
singletonList(localAuthor);
private IdentityManager identityManager;
private IdentityManagerImpl identityManager;
@Before
public void setUp() {
......@@ -35,15 +34,20 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
}
@Test
public void testRegisterAndStoreLocalAuthor() throws Exception {
public void testOpenDatabaseHookWithoutLocalAuthorRegistered()
throws Exception {
identityManager.onDatabaseOpened(txn);
}
@Test
public void testOpenDatabaseHookWithLocalAuthorRegistered()
throws Exception {
context.checking(new DbExpectations() {{
oneOf(db).transaction(with(false), withDbRunnable(txn));
oneOf(db).addLocalAuthor(txn, localAuthor);
}});
identityManager.registerLocalAuthor(localAuthor);
assertEquals(localAuthor, identityManager.getLocalAuthor());
identityManager.storeLocalAuthor();
identityManager.onDatabaseOpened(txn);
}
@Test
......
......@@ -115,7 +115,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
1, true, true);
TransportPropertyManagerImpl t = createInstance();
t.createLocalState(txn);
t.onDatabaseOpened(txn);
}
@Test
......@@ -129,7 +129,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
}});
TransportPropertyManagerImpl t = createInstance();
t.createLocalState(txn);
t.onDatabaseOpened(txn);
}
@Test
......
......@@ -3,10 +3,10 @@ package org.briarproject.bramble.test;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority;
import org.briarproject.bramble.api.lifecycle.Service;
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Client;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
......@@ -32,7 +32,8 @@ public class TestLifecycleModule {
}
@Override
public void registerClient(Client c) {
public void registerOpenDatabaseHook(OpenDatabaseHook hook,
Priority p) {
}
@Override
......
......@@ -83,7 +83,7 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
expectAddingContact();
ClientVersioningManagerImpl c = createInstance();
c.createLocalState(txn);
c.onDatabaseOpened(txn);
}
@Test
......@@ -95,7 +95,7 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
}});
ClientVersioningManagerImpl c = createInstance();
c.createLocalState(txn);
c.onDatabaseOpened(txn);
}
@Test
......
......@@ -56,6 +56,7 @@ import dagger.Provides;
import static android.content.Context.MODE_PRIVATE;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority.NORMAL;
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
......@@ -226,7 +227,7 @@ public class AppModule {
@Singleton
RecentEmoji provideRecentEmoji(LifecycleManager lifecycleManager,
RecentEmojiImpl recentEmoji) {
lifecycleManager.registerClient(recentEmoji);
lifecycleManager.registerOpenDatabaseHook(recentEmoji, NORMAL);
return recentEmoji;
}
}
......@@ -8,11 +8,11 @@ import com.vanniktech.emoji.emoji.Emoji;
import org.briarproject.bramble.api.db.DatabaseExecutor;
import org.briarproject.bramble.api.db.DbException;
import org.briarproject.bramble.api.db.Transaction;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.bramble.api.settings.Settings;
import org.briarproject.bramble.api.settings.SettingsManager;
import org.briarproject.bramble.api.sync.Client;
import org.briarproject.bramble.api.system.AndroidExecutor;
import org.briarproject.bramble.util.StringUtils;
......@@ -30,7 +30,7 @@ import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_
@MethodsNotNullByDefault
@ParametersNotNullByDefault
class RecentEmojiImpl implements RecentEmoji, Client {
class RecentEmojiImpl implements RecentEmoji, OpenDatabaseHook {
private static final Logger LOG =
Logger.getLogger(RecentEmojiImpl.class.getName());
......@@ -72,7 +72,7 @@ class RecentEmojiImpl implements RecentEmoji, Client {
}
@Override
public void createLocalState(Transaction txn) throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
Settings settings =
settingsManager.getSettings(txn, SETTINGS_NAMESPACE);
String serialized = settings.get(EMOJI_LRU_PREFERENCE);
......
......@@ -18,8 +18,8 @@ import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.AuthorInfo;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Client;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.Message;
......@@ -68,7 +68,7 @@ import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
@NotNullByDefault
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
ContactHook, Client {
OpenDatabaseHook, ContactHook {
private final ContactManager contactManager;
private final IdentityManager identityManager;
......@@ -90,7 +90,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
}
@Override
public void createLocalState(Transaction txn) throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
// Create our personal blog if necessary
LocalAuthor a = identityManager.getLocalAuthor(txn);
Blog b = blogFactory.createBlog(a);
......
......@@ -18,6 +18,7 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook.Priority.NORMAL;
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
import static org.briarproject.briar.api.blog.BlogManager.MAJOR_VERSION;
......@@ -36,7 +37,7 @@ public class BlogModule {
BlogManager provideBlogManager(BlogManagerImpl blogManager,
LifecycleManager lifecycleManager, ContactManager contactManager,
ValidationManager validationManager) {
lifecycleManager.registerClient(blogManager);
lifecycleManager.registerOpenDatabaseHook(blogManager, NORMAL);
contactManager.registerContactHook(blogManager);
validationManager.registerIncomingMessageHook(CLIENT_ID, MAJOR_VERSION,
blogManager);
......
......@@ -20,11 +20,11 @@ import org.briarproject.bramble.api.event.Event;
import org.briarproject.bramble.api.event.EventListener;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.lifecycle.IoExecutor;
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TorConstants;
import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
import org.briarproject.bramble.api.sync.Client;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.system.Clock;
......@@ -32,6 +32,7 @@ import org.briarproject.bramble.api.system.Scheduler;
import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.api.blog.Blog;
import org.briarproject.briar.api.blog.BlogManager;
import org.briarproject.briar.api.blog.BlogManager.RemoveBlogHook;
import org.briarproject.briar.api.blog.BlogPost;
import org.briarproject.briar.api.blog.BlogPostFactory;
import org.briarproject.briar.api.feed.Feed;
......@@ -75,8 +76,8 @@ import static org.briarproject.briar.util.HtmlUtils.clean;
@ThreadSafe
@NotNullByDefault
class FeedManagerImpl implements FeedManager, Client, EventListener,
BlogManager.RemoveBlogHook {
class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
RemoveBlogHook {
private static final Logger LOG =
Logger.getLogger(FeedManagerImpl.class.getName());
......@@ -136,7 +137,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
}
@Override
public void createLocalState(Transaction txn) throws DbException {
public void onDatabaseOpened(Transaction txn) throws DbException {
Group g = getLocalGroup();
// Return if we've already set the local group up
if (db.containsGroup(txn, g.getId())) return;
......
......@@ -11,6 +11,8 @@ import javax.inject.Singleton;
import dagger.Module;