From: David ‘Bombe’ Roden Date: Sat, 1 Mar 2014 12:47:30 +0000 (+0100) Subject: Store identities in database. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=90d8e2eacb9888735865d8f890d105885959ca65;p=Sone.git Store identities in database. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 5d8e3b2..4bf8a8a 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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 diff --git a/src/main/java/net/pterodactylus/sone/database/IdentityDatabase.java b/src/main/java/net/pterodactylus/sone/database/IdentityDatabase.java index ac4c98b..a9e1837 100644 --- a/src/main/java/net/pterodactylus/sone/database/IdentityDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/IdentityDatabase.java @@ -12,5 +12,6 @@ import com.google.common.base.Optional; public interface IdentityDatabase { Optional getIdentity(String identityId); + void storeIdentity(Identity identitiy); } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 691b604..df39511 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -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> getSone() { return new Function>() { @Override