From 1e2cc037de135a57fd74aabe4422cec69a59f5e5 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Mon, 5 May 2014 10:52:44 +0530 Subject: [PATCH] Synchronization - We were getting some concurrency exceptions because certain data structures were being modified concurrently - Solved the issues by synchronizing the methods modifying the data structures --- src/kademlia/dht/DHT.java | 4 ++-- src/kademlia/dht/StoredContentManager.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/kademlia/dht/DHT.java b/src/kademlia/dht/DHT.java index e5f194c..ae631e1 100644 --- a/src/kademlia/dht/DHT.java +++ b/src/kademlia/dht/DHT.java @@ -80,7 +80,7 @@ public class DHT * * @throws java.io.IOException */ - public boolean store(StorageEntry content) throws IOException + public synchronized boolean store(StorageEntry content) throws IOException { /* Lets check if we have this content and it's the updated version */ if (this.entriesManager.contains(content.getContentMetadata())) @@ -142,7 +142,7 @@ public class DHT } - public boolean store(KadContent content) throws IOException + public synchronized boolean store(KadContent content) throws IOException { return this.store(new StorageEntry(content)); } diff --git a/src/kademlia/dht/StoredContentManager.java b/src/kademlia/dht/StoredContentManager.java index 3d541a5..5eee9bb 100644 --- a/src/kademlia/dht/StoredContentManager.java +++ b/src/kademlia/dht/StoredContentManager.java @@ -69,7 +69,7 @@ class StoredContentManager * * @return boolean */ - public boolean contains(GetParameter param) + public synchronized boolean contains(GetParameter param) { if (this.entries.containsKey(param.getKey())) { @@ -93,7 +93,7 @@ class StoredContentManager /** * Check if a content exist in the DHT */ - public boolean contains(KadContent content) + public synchronized boolean contains(KadContent content) { return this.contains(new GetParameter(content)); } @@ -101,7 +101,7 @@ class StoredContentManager /** * Check if a StorageEntry exist on this DHT */ - public boolean contains(StorageEntryMetadata entry) + public synchronized boolean contains(StorageEntryMetadata entry) { return this.contains(new GetParameter(entry)); }