public class Voldemort {
/**
* @param args
*/
public static void main(String[] args) {
instance = new Voldemort("tcp://localhost:6666");
instance.doSomeStuff();
}
public Voldemort(String bootstrapUrl) {
VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
VoldemortServer server = new VoldemortServer(config);
server.start();
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
// create a client that executes operations on a single store
client = factory.getStoreClient(STORE_NAME);
}
private void doSomeStuff() {
// do some random pointless operations
Versioned<String> value = client.get(KEY_BASE);
if (value == null) {
value = new Versioned<String>(TURTLE_1);
System.out.println("Putting new value");
}
else {
value.setObject(TURTLE_1);
System.out.println("Replaceing existing value");
}
client.put(KEY_BASE, value);
value = client.get(KEY_BASE);
assert value.equals(TURTLE_1);
System.out.println("All is good");
}
private static Voldemort instance;
private StoreClient<String, String> client;
private static final String STORE_NAME = "directory_store";
private static final String KEY_BASE = "foo";
private static final String TURTLE_1 = "bar";
private static final Logger LOG = Logger.getLogger(Voldemort.class);
}