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
This commit is contained in:
Joshua Kissoon 2014-05-05 10:52:44 +05:30
parent cb42c507de
commit 1e2cc037de
2 changed files with 5 additions and 5 deletions

View File

@ -80,7 +80,7 @@ public class DHT
* *
* @throws java.io.IOException * @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 */ /* Lets check if we have this content and it's the updated version */
if (this.entriesManager.contains(content.getContentMetadata())) 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)); return this.store(new StorageEntry(content));
} }

View File

@ -69,7 +69,7 @@ class StoredContentManager
* *
* @return boolean * @return boolean
*/ */
public boolean contains(GetParameter param) public synchronized boolean contains(GetParameter param)
{ {
if (this.entries.containsKey(param.getKey())) if (this.entries.containsKey(param.getKey()))
{ {
@ -93,7 +93,7 @@ class StoredContentManager
/** /**
* Check if a content exist in the DHT * 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)); return this.contains(new GetParameter(content));
} }
@ -101,7 +101,7 @@ class StoredContentManager
/** /**
* Check if a StorageEntry exist on this DHT * 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)); return this.contains(new GetParameter(entry));
} }