heaphach heaphach - 5 months ago 162
Java Question

Distributed Hashmap in java or distributed information storage

Does someone knows a good java framework for distributed hashmaps (DHT)?

Some time ago I worked with Overlay Weaver, but a good documentation is missing here, so I only used it for an prototype with ugly hacks..., but now I need reliable code. Or does someone found a good docu for OverlayWeaver?

It would be perfect if the dht framework supports Chord or Kademlia and can be called inside my java application.

Or does someone knows a better approach to save reliable and failuresafe short string data in distibuted systems?

Answer

I think that Hazelcast works fine for this type of situation. It practically requires no setup (more than that you need to add the dependencies to the Hazelcast jars). The following code sample shows how to setup a shared Map.

// Code in process 1
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
Map<Integer, String> sharedData = instance.getMap("shared");
sharedData.put(1, "This is shared data");

// Code in process 2
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
Map<Integer, String> sharedData = instance.getMap("shared");
String theSharedString = sharedData.get(1);

Hazelcast support various shared data structures including Map, Queue, List, AtomicLong, IdGenerator etc. The documentation is good and in my experience the implementation is solid.

If your are using a sane build environment (e.g. Maven) the following dependency is all that is needed to get started:

<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast</artifactId>
    <version>3.4</version>
</dependency>
Comments