-public class IdentityManager extends AbstractService {
-
- /** The logger. */
- private static final Logger logger = Logging.getLogger(IdentityManager.class);
-
- /** The event bus. */
- private final EventBus eventBus;
-
- private final IdentityLoader identityLoader;
-
- /** The Web of Trust connector. */
- private final WebOfTrustConnector webOfTrustConnector;
-
- /** The currently known own identities. */
- private final Set<OwnIdentity> currentOwnIdentities = Sets.newHashSet();
-
- /**
- * Creates a new identity manager.
- *
- * @param eventBus
- * The event bus
- * @param webOfTrustConnector
- * The Web of Trust connector
- * @param context
- * The context to focus on (may be {@code null} to ignore
- * contexts)
- */
- @Inject
- public IdentityManager(EventBus eventBus, WebOfTrustConnector webOfTrustConnector, @Named("WebOfTrustContext") String context) {
- super("Sone Identity Manager", false);
- this.eventBus = eventBus;
- this.webOfTrustConnector = webOfTrustConnector;
- this.identityLoader = new IdentityLoader(webOfTrustConnector, fromNullable(context));
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns whether the Web of Trust plugin could be reached during the last
- * try.
- *
- * @return {@code true} if the Web of Trust plugin is connected,
- * {@code false} otherwise
- */
- public boolean isConnected() {
- try {
- webOfTrustConnector.ping();
- return true;
- } catch (PluginException pe1) {
- /* not connected, ignore. */
- return false;
- }
- }
-
- /**
- * Returns all own identities.
- *
- * @return All own identities
- */
- public Set<OwnIdentity> getAllOwnIdentities() {
- synchronized (currentOwnIdentities) {
- return new HashSet<OwnIdentity>(currentOwnIdentities);
- }
- }
-
- //
- // SERVICE METHODS
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void serviceRun() {
- Multimap<OwnIdentity, Identity> oldIdentities = create();
-
- while (!shouldStop()) {
- try {
- Multimap<OwnIdentity, Identity> currentIdentities = identityLoader.loadIdentities();
-
- IdentityChangeEventSender identityChangeEventSender = new IdentityChangeEventSender(eventBus, oldIdentities);
- identityChangeEventSender.detectChanges(currentIdentities);
-
- oldIdentities = currentIdentities;
-
- synchronized (currentOwnIdentities) {
- currentOwnIdentities.clear();
- currentOwnIdentities.addAll(currentIdentities.keySet());
- }
- } catch (WebOfTrustException wote1) {
- logger.log(Level.WARNING, "WoT has disappeared!", wote1);
- }