Home Example Code Download

Helpful Links:

Sameh's P2P page

 

Copyright © 2009 KTH & SICS, Inc.

 

Site Design by Linus

Introduction

JDHT is a simple Java based Distributed Hash Table (DHT) which implements java.util.Map.
It is therefore very simple and intuitive to use. DHTs are very scalable distributed data structured originated from research on peer-to-peer (P2P) computing.

Under the hood, JDHT uses DKS, which provides a DHT among other things.

JDHT is developed at KTH/Royal Institute of Technology and the Swedish Institute of Computer Science (SICS) in the context of the european project PEPITO.

Example Code


Server sets up a local DHT, adds a string to the DHT, and exports a reference to itself [
JDHTServer.java] :


import org.kth.dks.JDHT;  
import java.io.*;

public class JDHTServer {
	public static void main(String[] arg) {
		try {
			
			// Could declare myDHT as a java.util.Map
			// default port 4440 
			JDHT myDHT = new JDHT();
			
			// Insert data into the DHT
			myDHT.put("myKey", "Hello World!");
			
			// Print a reference to this node
			System.out.println( ((JDHT)myDHT).getReference() );
			
			// Wait for input before exiting
			BufferedReader cin = new BufferedReader( new InputStreamReader(
								System.in) );
			cin.read();
			
			// shut down
			myDHT.close(); 
			
		} catch(Exception ex) { ex.printStackTrace(); }
	}
}



Connects to an existing node in a DHT (using the reference printed by the Server as a command line argument), makes a lookup and prints it [JDHTClient.java]

import org.kth.dks.JDHT;

public class JDHTClient {
	
	/**
	 * @param args contains a reference to an existing node in a DHT 
	 */
	public static void main(String[] args) {
		if (args.length!=1) System.exit(0); 
		try {
			// Start an instance listening on port 5550
			// Connect to an existing node running a DHT at args[0]
			JDHT myDHT = new JDHT(5550, args[0]);
			
			String helloString = (String) myDHT.get("myKey");
			System.out.println(helloString);
			
			myDHT.close();
			
		} catch (Exception e) { e.printStackTrace(); }
		
	}
	
}



Download JDHT

JDHT can be downloaded in a jar: [dks.jar]

JDHT requires Apache Xerces XML parser found in a jar: [xercesImpl.jar]

JDHT JAVADOC can be found here

Once you have downloaded dks.jar and xercesImpl.jar and the Client and Server programs, you can run them by typing:


javac -classpath xercesImpl.jar:dks.jar:. JDHTServer.java JDHTClient.java

java -classpath xercesImpl.jar:dks.jar:. JDHTServer

...

java -classpath xercesImpl.jar:dks.jar:. JDHTClient dksref://192.168.0.1:4440/0/11094/0/1189107