mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +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.AuthorId;
|
||||||
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.lifecycle.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
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.ACTIVE;
|
||||||
import static org.briarproject.api.db.StorageStatus.ADDING;
|
|
||||||
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
||||||
|
|
||||||
class ContactManagerImpl implements ContactManager, Service,
|
class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||||
RemoveIdentityHook {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(ContactManagerImpl.class.getName());
|
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final List<AddContactHook> addHooks;
|
private final List<AddContactHook> addHooks;
|
||||||
@@ -44,39 +36,6 @@ class ContactManagerImpl implements ContactManager, Service,
|
|||||||
removeHooks = new CopyOnWriteArrayList<RemoveContactHook>();
|
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
|
@Override
|
||||||
public void registerAddContactHook(AddContactHook hook) {
|
public void registerAddContactHook(AddContactHook hook) {
|
||||||
addHooks.add(hook);
|
addHooks.add(hook);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.google.inject.Provides;
|
|||||||
|
|
||||||
import org.briarproject.api.contact.ContactManager;
|
import org.briarproject.api.contact.ContactManager;
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@@ -15,10 +14,8 @@ public class ContactModule extends AbstractModule {
|
|||||||
protected void configure() {}
|
protected void configure() {}
|
||||||
|
|
||||||
@Provides @Singleton
|
@Provides @Singleton
|
||||||
ContactManager getContactManager(LifecycleManager lifecycleManager,
|
ContactManager getContactManager(IdentityManager identityManager,
|
||||||
IdentityManager identityManager,
|
|
||||||
ContactManagerImpl contactManager) {
|
ContactManagerImpl contactManager) {
|
||||||
lifecycleManager.register(contactManager);
|
|
||||||
identityManager.registerRemoveIdentityHook(contactManager);
|
identityManager.registerRemoveIdentityHook(contactManager);
|
||||||
return contactManager;
|
return contactManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,24 +9,17 @@ import org.briarproject.api.db.Transaction;
|
|||||||
import org.briarproject.api.identity.AuthorId;
|
import org.briarproject.api.identity.AuthorId;
|
||||||
import org.briarproject.api.identity.IdentityManager;
|
import org.briarproject.api.identity.IdentityManager;
|
||||||
import org.briarproject.api.identity.LocalAuthor;
|
import org.briarproject.api.identity.LocalAuthor;
|
||||||
import org.briarproject.api.lifecycle.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
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.ACTIVE;
|
||||||
import static org.briarproject.api.db.StorageStatus.ADDING;
|
|
||||||
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
import static org.briarproject.api.db.StorageStatus.REMOVING;
|
||||||
|
|
||||||
class IdentityManagerImpl implements IdentityManager, Service {
|
class IdentityManagerImpl implements IdentityManager {
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
Logger.getLogger(IdentityManagerImpl.class.getName());
|
|
||||||
|
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final List<AddIdentityHook> addHooks;
|
private final List<AddIdentityHook> addHooks;
|
||||||
@@ -39,39 +32,6 @@ class IdentityManagerImpl implements IdentityManager, Service {
|
|||||||
removeHooks = new CopyOnWriteArrayList<RemoveIdentityHook>();
|
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
|
@Override
|
||||||
public void registerAddIdentityHook(AddIdentityHook hook) {
|
public void registerAddIdentityHook(AddIdentityHook hook) {
|
||||||
addHooks.add(hook);
|
addHooks.add(hook);
|
||||||
|
|||||||
@@ -12,13 +12,12 @@ public class IdentityModule extends AbstractModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(AuthorFactory.class).to(
|
bind(AuthorFactory.class).to(AuthorFactoryImpl.class);
|
||||||
org.briarproject.identity.AuthorFactoryImpl.class);
|
|
||||||
bind(IdentityManager.class).to(IdentityManagerImpl.class);
|
bind(IdentityManager.class).to(IdentityManagerImpl.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ObjectReader<Author> getAuthorReader(AuthorFactory authorFactory) {
|
ObjectReader<Author> getAuthorReader(AuthorFactory authorFactory) {
|
||||||
return new org.briarproject.identity.AuthorReader(authorFactory);
|
return new AuthorReader(authorFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user