Fixed crash caused by using DB too early in lifecycle.

This commit is contained in:
akwizgran
2016-01-20 15:03:10 +00:00
parent 3872a05ddd
commit 3c543b0d62
5 changed files with 23 additions and 8 deletions

View File

@@ -27,5 +27,5 @@ public interface ValidationManager {
}
/** Sets the message validator for the given client. */
void setMessageValidator(ClientId c, MessageValidator v);
void registerMessageValidator(ClientId c, MessageValidator v);
}

View File

@@ -34,7 +34,7 @@ public class ForumModule extends AbstractModule {
ForumPostValidator validator = new ForumPostValidator(crypto,
bdfReaderFactory, bdfWriterFactory, authorReader,
metadataEncoder, clock);
validationManager.setMessageValidator(forumManager.getClientId(),
validationManager.registerMessageValidator(forumManager.getClientId(),
validator);
return validator;
}

View File

@@ -27,7 +27,8 @@ public class MessagingModule extends AbstractModule {
Clock clock) {
PrivateMessageValidator validator = new PrivateMessageValidator(
bdfReaderFactory, metadataEncoder, clock);
validationManager.setMessageValidator(messagingManager.getClientId(),
validationManager.registerMessageValidator(
messagingManager.getClientId(),
validator);
return validator;
}

View File

@@ -7,6 +7,7 @@ import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.sync.MessageFactory;
@@ -48,8 +49,9 @@ public class SyncModule extends AbstractModule {
}
@Provides @Singleton
ValidationManager getValidationManager(EventBus eventBus,
ValidationManagerImpl validationManager) {
ValidationManager getValidationManager(LifecycleManager lifecycleManager,
EventBus eventBus, ValidationManagerImpl validationManager) {
lifecycleManager.register(validationManager);
eventBus.addListener(validationManager);
return validationManager;
}

View File

@@ -13,6 +13,7 @@ import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
@@ -29,7 +30,8 @@ import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.sync.SyncConstants.MESSAGE_HEADER_LENGTH;
class ValidationManagerImpl implements ValidationManager, EventListener {
class ValidationManagerImpl implements ValidationManager, Service,
EventListener {
private static final Logger LOG =
Logger.getLogger(ValidationManagerImpl.class.getName());
@@ -50,9 +52,19 @@ class ValidationManagerImpl implements ValidationManager, EventListener {
}
@Override
public void setMessageValidator(ClientId c, MessageValidator v) {
public boolean start() {
for (ClientId c : validators.keySet()) getMessagesToValidate(c);
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public void registerMessageValidator(ClientId c, MessageValidator v) {
validators.put(c, v);
getMessagesToValidate(c);
}
private void getMessagesToValidate(final ClientId c) {