Developing lightweight computation at the DSG edge

Commit cd656778 authored by Ilyas Toumlilt's avatar Ilyas Toumlilt
Browse files

Update to latest version of antidote java client (0.3.0)

parent c61c0c39
......@@ -24,7 +24,7 @@ dependencies {
compile 'com.google.guava:guava:20.0'
//Antidote java client library
compile group: 'eu.antidotedb', name: 'antidote-java-client', version: '0.0.5'
compile group: 'eu.antidotedb', name: 'antidote-java-client', version: '0.3.0'
//for command line shell
compile files("lib/asg.cliche-110413.jar")
......
......@@ -50,7 +50,7 @@ public class BookCommands {
return null;
}
void not_implemented(){
private void not_implemented(){
throw new RuntimeException("Not Implemented");
}
}
......@@ -2,14 +2,14 @@ import java.io.IOException;
import java.util.List;
import eu.antidotedb.client.AntidoteClient;
import eu.antidotedb.client.Host;
import java.net.InetSocketAddress;
import asg.cliche.Command;
import asg.cliche.ShellFactory;
public class BookStore {
AntidoteClient currentSession;
private AntidoteClient currentSession;
/* *** Demo Commands *** */
......@@ -40,7 +40,7 @@ public class BookStore {
@Command //connect antidote
public String connect(String host, int port){
currentSession = new AntidoteClient(new Host(host, port));
currentSession = new AntidoteClient(new InetSocketAddress(host, port));
return "Connected to " + host+":"+port;
}
......
import java.util.List;
import java.util.Objects;
import eu.antidotedb.client.AntidoteClient;
import eu.antidotedb.client.AntidoteStaticTransaction;
import eu.antidotedb.client.BatchRead;
import eu.antidotedb.client.BatchReadResult;
import eu.antidotedb.client.Bucket;
import eu.antidotedb.client.CounterRef;
import eu.antidotedb.client.InteractiveTransaction;
import eu.antidotedb.client.SetRef;
import eu.antidotedb.client.*;
public class DemoCommandsExecutor {
//increment a counter without wrapping it in a transaction
public static int incCounter(AntidoteClient client, String bucket, String key){
Bucket<String> cbucket = Bucket.create(bucket);
CounterRef cnt = cbucket.counter(key);
cnt.increment(client.noTransaction());
return cnt.read(client.noTransaction());
Bucket cbucket = Bucket.bucket(bucket);
CounterKey cnt = Key.counter(key);
cbucket.update(client.noTransaction(),
cnt.increment(1));
return cbucket.read(client.noTransaction(), cnt);
}
public static int getCounter(AntidoteClient client, String bucket, String key){
Bucket<String> cbucket = Bucket.create(bucket);
CounterRef cnt = cbucket.counter(key);
return cnt.read(client.noTransaction());
Bucket cbucket = Bucket.bucket(bucket);
CounterKey cnt = Key.counter(key);
return cbucket.read(client.noTransaction(), cnt);
}
//update a set without wrapping it in a transaction
public static List<String> addToSet(AntidoteClient client, String bucket, String key, String elem){
Bucket<String> cbucket = Bucket.create(bucket);
SetRef<String> set = cbucket.set(key);
set.add(client.noTransaction(),elem);
return set.read(client.noTransaction());
Bucket cbucket = Bucket.bucket(bucket);
SetKey setKey = Key.set(key);
cbucket.update(client.noTransaction(), setKey.add(elem));
return (List<String>) cbucket.read(client.noTransaction(), setKey);
}
public static List<String> getSet(AntidoteClient client, String bucket, String key){
Bucket<String> cbucket = Bucket.create(bucket);
SetRef<String> set = cbucket.set(key);
return set.read(client.noTransaction());
Bucket cbucket = Bucket.bucket(bucket);
SetKey setKey = Key.set(key);
return (List<String>) cbucket.read(client.noTransaction(),setKey);
}
//update and read with in a transaction
public static String addToSetTxn(AntidoteClient client){
Bucket<String> bucket = Bucket.create("testbucket");
CounterRef cnt = bucket.counter("testcounter");
SetRef<String> set = bucket.set("testset");
Bucket bucket = Bucket.bucket("testbucket");
ValueCoder<Integer> intCoder = ValueCoder.stringCoder(Objects::toString, Integer::valueOf);
CounterKey c = Key.counter("testcounter");
SetKey<Integer> numberSet = Key.set("testset", intCoder);
try (InteractiveTransaction tx = client.startTransaction()) {
cnt.increment(tx);
int i = cnt.read(tx);
set.add(tx, "i:" + i);
tx.commitTransaction();
}
return "ok";
bucket.update(tx, c.increment(1));
int i = bucket.read(tx, c);
bucket.update(tx, numberSet.add(i));
tx.commitTransaction();
}
return "ok";
}
//batch updates and batch reads
public static int batchUpdates(AntidoteClient client){
Bucket<String> bucket = Bucket.create("testbucket");
CounterRef a = bucket.counter("batchcounter1");
CounterRef b = bucket.counter("batchcounter2");
CounterRef c = bucket.counter("batchcounter3");
//increment counters in a batch transaction.
Bucket bucket = Bucket.bucket("testbucket");
CounterKey c1 = Key.counter("c1");
CounterKey c2 = Key.counter("c2");
CounterKey c3 = Key.counter("c3");
//increment counters in a batch transaction.
AntidoteStaticTransaction tx = client.createStaticTransaction();
a.increment(tx);
b.increment(tx);
c.increment(tx);
bucket.update(tx, c1.increment(1));
bucket.update(tx, c2.increment(1));
bucket.update(tx, c3.increment(1));
tx.commitTransaction();
//Read multiple keys in batch read
BatchRead batchRead = client.newBatchRead();
BatchReadResult<Integer> c1val = a.read(batchRead);
BatchReadResult<Integer> c2val = b.read(batchRead);
BatchReadResult<Integer> c3val = c.read(batchRead);
batchRead.commit();
int sum = c1val.get() + c2val.get() + c3val.get();
BatchReadResult<Integer> c1val = bucket.read(batchRead, c1);
BatchReadResult<Integer> c2val = bucket.read(batchRead, c2);
BatchReadResult<Integer> c3val = bucket.read(batchRead, c3);
batchRead.commit(client.noTransaction());
int sum = c1val.get() + c2val.get() + c3val.get();
return sum;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment