From 90d8e2eacb9888735865d8f890d105885959ca65 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 1 Mar 2014 13:47:30 +0100 Subject: [PATCH] Store identities in database. --- src/main/java/net/pterodactylus/sone/core/Core.java | 3 +++ .../java/net/pterodactylus/sone/database/IdentityDatabase.java | 1 + .../net/pterodactylus/sone/database/memory/MemoryDatabase.java | 10 ++++++++++ 3 files changed, 14 insertions(+) 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 -- 2.7.4