Started working on the ContentRefreshOperation

- Setup a method to get all storage entries for the different content
	- Started setting up the content refresh operation functionality
This commit is contained in:
Joshua Kissoon 2014-03-06 20:42:30 +05:30
parent 689a35b7bf
commit a97905e431
6 changed files with 65 additions and 13 deletions

View File

@ -79,8 +79,8 @@ public class Kademlia
{ {
try try
{ {
/* Runs a RefreshOperation to refresh K-Buckets and stored content */ /* Runs a DHT RefreshOperation */
new BucketRefreshOperation(server, localNode).execute(); Kademlia.this.refresh();
} }
catch (IOException e) catch (IOException e)
{ {
@ -182,7 +182,7 @@ public class Kademlia
*/ */
public void refresh() throws IOException public void refresh() throws IOException
{ {
new KadRefreshOperation(server, localNode).execute(); new KadRefreshOperation(this.server, this.localNode, this.dht).execute();
} }
/** /**

View File

@ -7,6 +7,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import kademlia.core.Configuration; import kademlia.core.Configuration;
import kademlia.core.GetParameter; import kademlia.core.GetParameter;
@ -77,12 +78,12 @@ public class DHT
} }
/** /**
* Get the List<StorageEntry> for the content if any exist, * Get the StorageEntry for the content if any exist,
* retrieve the content from the storage system and return it * retrieve the KadContent from the storage system and return it
* *
* @param param The parameters used to filter the content needed * @param param The parameters used to filter the content needed
* *
* @return List<KadContent> A list with the content found on the DHT satisfying the given criteria * @return KadContent A KadContent found on the DHT satisfying the given criteria
* *
* @throws java.io.IOException * @throws java.io.IOException
*/ */
@ -142,4 +143,12 @@ public class DHT
return mainStorageFolder + File.separator + folderName; return mainStorageFolder + File.separator + folderName;
} }
/**
* @return A List of all StorageEntries for this node
*/
public List<StorageEntry> getStorageEntries()
{
return entriesManager.getAllEntries();
}
} }

View File

@ -99,4 +99,21 @@ public class StorageEntryManager
} }
} }
/**
* @return A list of all storage entries
*/
public List<StorageEntry> getAllEntries()
{
List<StorageEntry> entriesRet = new ArrayList<>();
for (List<StorageEntry> entrySet : this.entries.values())
{
if (entrySet.size() > 0)
{
entriesRet.addAll(entrySet);
}
}
return entriesRet;
}
} }

View File

@ -50,8 +50,7 @@ public class BucketRefreshOperation implements Operation
{ {
try try
{ {
System.out.println("Distance: " + localNode.getNodeId().getDistance(current) + " - ID: " + current); //System.out.println("Distance: " + localNode.getNodeId().getDistance(current) + " - ID: " + current);
new NodeLookupOperation(server, localNode, localNode.getNodeId()).execute(); new NodeLookupOperation(server, localNode, localNode.getNodeId()).execute();
} }
catch (IOException e) catch (IOException e)

View File

@ -1,19 +1,42 @@
package kademlia.operation; package kademlia.operation;
import kademlia.core.KadServer;
import kademlia.dht.DHT;
import kademlia.node.Node;
/** /**
* Refresh the data on this node by sending the data to the K-Closest nodes to the data * Refresh/Restore the data on this node by sending the data to the K-Closest nodes to the data
* *
* @author Joshua Kissoon * @author Joshua Kissoon
* @since 20140306 * @since 20140306
*/ */
public class ContentRefreshOperation public class ContentRefreshOperation implements Operation
{ {
private final KadServer server;
private final Node localNode;
private final DHT dht;
public ContentRefreshOperation(KadServer server, Node localNode, DHT dht)
{
this.server = server;
this.localNode = localNode;
this.dht = dht;
}
/**
* For each content stored on this DHT, distribute it to the K closest nodes
* Also delete the content if this node is no longer one of the K closest nodes
*
* We assume that our RoutingTable is updated, and we can get the K closest nodes from that table
*/
@Override
public void execute() public void execute()
{ {
/** /**
* @todo Delete any content on this node that this node is not one of the K-Closest nodes to * @todo Delete any content on this node that this node is not one of the K-Closest nodes to
* @todo Delete any expired content
*/ */
} }
} }

View File

@ -2,6 +2,7 @@ package kademlia.operation;
import java.io.IOException; import java.io.IOException;
import kademlia.core.KadServer; import kademlia.core.KadServer;
import kademlia.dht.DHT;
import kademlia.node.Node; import kademlia.node.Node;
/** /**
@ -15,11 +16,13 @@ public class KadRefreshOperation implements Operation
private final KadServer server; private final KadServer server;
private final Node localNode; private final Node localNode;
private final DHT dht;
public KadRefreshOperation(KadServer server, Node localNode) public KadRefreshOperation(KadServer server, Node localNode, DHT dht)
{ {
this.server = server; this.server = server;
this.localNode = localNode; this.localNode = localNode;
this.dht = dht;
} }
@Override @Override
@ -29,5 +32,6 @@ public class KadRefreshOperation implements Operation
new BucketRefreshOperation(server, localNode).execute(); new BucketRefreshOperation(server, localNode).execute();
/* After buckets have been refreshed, we refresh content */ /* After buckets have been refreshed, we refresh content */
new ContentRefreshOperation(server, localNode, dht).execute();
} }
} }