Store identities in database.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Mar 2014 12:47:30 +0000 (13:47 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 1 Mar 2014 12:47:30 +0000 (13:47 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/database/IdentityDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index 5d8e3b2..4bf8a8a 100644 (file)
@@ -1646,6 +1646,7 @@ public class Core extends AbstractService implements SoneProvider {
                OwnIdentity ownIdentity = ownIdentityAddedEvent.ownIdentity();
                logger.log(Level.FINEST, String.format("Adding OwnIdentity: %s", ownIdentity));
                if (ownIdentity.hasContext("Sone")) {
+                       database.storeIdentity(ownIdentity);
                        addLocalSone(ownIdentity);
                }
        }
@@ -1674,6 +1675,7 @@ public class Core extends AbstractService implements SoneProvider {
                Identity identity = identityAddedEvent.identity();
                logger.log(Level.FINEST, String.format("Adding Identity: %s", identity));
                trustedIdentities.put(identityAddedEvent.ownIdentity(), identity);
+               database.storeIdentity(identity);
                addRemoteSone(identity);
        }
 
@@ -1686,6 +1688,7 @@ public class Core extends AbstractService implements SoneProvider {
        @Subscribe
        public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) {
                final Identity identity = identityUpdatedEvent.identity();
+               database.storeIdentity(identity);
                soneDownloaders.execute(new Runnable() {
 
                        @Override
index ac4c98b..a9e1837 100644 (file)
@@ -12,5 +12,6 @@ import com.google.common.base.Optional;
 public interface IdentityDatabase {
 
        Optional<Identity> getIdentity(String identityId);
+       void storeIdentity(Identity identitiy);
 
 }
index 691b604..df39511 100644 (file)
@@ -178,6 +178,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        @Override
+       public void storeIdentity(Identity identitiy) {
+               lock.writeLock().lock();
+               try {
+                       identities.put(identitiy.getId(), identitiy);
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       @Override
        public Function<String, Optional<Sone>> getSone() {
                return new Function<String, Optional<Sone>>() {
                        @Override