mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Contact and identity managers don't need to be services.
This commit is contained in:
@@ -13,25 +13,17 @@ import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.db.StorageStatus.ACTIVE;
|
||||
import static org.briarproject.api.db.StorageStatus.ADDING;
|
||||
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
||||
|
||||
class ContactManagerImpl implements ContactManager, Service,
|
||||
RemoveIdentityHook {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ContactManagerImpl.class.getName());
|
||||
class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final List<AddContactHook> addHooks;
|
||||
@@ -44,39 +36,6 @@ class ContactManagerImpl implements ContactManager, Service,
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveContactHook>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// Finish adding/removing any partly added/removed contacts
|
||||
try {
|
||||
Transaction txn = db.startTransaction();
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
if (c.getStatus().equals(ADDING)) {
|
||||
for (AddContactHook hook : addHooks)
|
||||
hook.addingContact(txn, c);
|
||||
db.setContactStatus(txn, c.getId(), ACTIVE);
|
||||
} else if (c.getStatus().equals(REMOVING)) {
|
||||
for (RemoveContactHook hook : removeHooks)
|
||||
hook.removingContact(txn, c);
|
||||
db.removeContact(txn, c.getId());
|
||||
}
|
||||
}
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return true;
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAddContactHook(AddContactHook hook) {
|
||||
addHooks.add(hook);
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.google.inject.Provides;
|
||||
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@@ -15,10 +14,8 @@ public class ContactModule extends AbstractModule {
|
||||
protected void configure() {}
|
||||
|
||||
@Provides @Singleton
|
||||
ContactManager getContactManager(LifecycleManager lifecycleManager,
|
||||
IdentityManager identityManager,
|
||||
ContactManager getContactManager(IdentityManager identityManager,
|
||||
ContactManagerImpl contactManager) {
|
||||
lifecycleManager.register(contactManager);
|
||||
identityManager.registerRemoveIdentityHook(contactManager);
|
||||
return contactManager;
|
||||
}
|
||||
|
||||
@@ -9,24 +9,17 @@ import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.db.StorageStatus.ACTIVE;
|
||||
import static org.briarproject.api.db.StorageStatus.ADDING;
|
||||
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
||||
|
||||
class IdentityManagerImpl implements IdentityManager, Service {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(IdentityManagerImpl.class.getName());
|
||||
class IdentityManagerImpl implements IdentityManager {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
private final List<AddIdentityHook> addHooks;
|
||||
@@ -39,39 +32,6 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveIdentityHook>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// Finish adding/removing any partly added/removed pseudonyms
|
||||
try {
|
||||
Transaction txn = db.startTransaction();
|
||||
try {
|
||||
for (LocalAuthor a : db.getLocalAuthors(txn)) {
|
||||
if (a.getStatus().equals(ADDING)) {
|
||||
for (AddIdentityHook hook : addHooks)
|
||||
hook.addingIdentity(txn, a);
|
||||
db.setLocalAuthorStatus(txn, a.getId(), ACTIVE);
|
||||
} else if (a.getStatus().equals(REMOVING)) {
|
||||
for (RemoveIdentityHook hook : removeHooks)
|
||||
hook.removingIdentity(txn, a);
|
||||
db.removeLocalAuthor(txn, a.getId());
|
||||
}
|
||||
}
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return true;
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAddIdentityHook(AddIdentityHook hook) {
|
||||
addHooks.add(hook);
|
||||
|
||||
@@ -12,13 +12,12 @@ public class IdentityModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(AuthorFactory.class).to(
|
||||
org.briarproject.identity.AuthorFactoryImpl.class);
|
||||
bind(AuthorFactory.class).to(AuthorFactoryImpl.class);
|
||||
bind(IdentityManager.class).to(IdentityManagerImpl.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
ObjectReader<Author> getAuthorReader(AuthorFactory authorFactory) {
|
||||
return new org.briarproject.identity.AuthorReader(authorFactory);
|
||||
return new AuthorReader(authorFactory);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user