Developing lightweight computation at the DSG edge

Commit 1f43858f authored by deepthidevaki's avatar deepthidevaki
Browse files

add more methods

parent 984ce7fe
......@@ -19,15 +19,25 @@ public class BookStore {
}
@Command //test command
public int inccounter(String bucket, String key){
public int inc(String bucket, String key){
return DemoCommandsExecutor.incCounter(currentSession, bucket, key);
}
@Command
public int getcounter(String bucket, String key){
return DemoCommandsExecutor.getCounter(currentSession, bucket, key);
}
@Command
public List<String> addtoset(String bucket, String key, String item){
public List<String> additem(String bucket, String key, String item){
return DemoCommandsExecutor.addToSet(currentSession, bucket, key, item);
}
@Command
public List<String> getset(String bucket, String key){
return DemoCommandsExecutor.getSet(currentSession, bucket, key);
}
@Command //connect antidote
public String connect(String host, int port){
currentSession = new AntidoteClient(new Host(host, port));
......@@ -67,8 +77,13 @@ public class BookStore {
return (new BookCommands().borrowBook(fromUser, byUser, book));
}
@Command
public String returnbook(String ToUser, String byUser, String book){
return (new BookCommands().borrowBook(ToUser, byUser, book));
}
public static void main(String[] args) throws IOException {
ShellFactory.createConsoleShell("antidotebookstore", "", new BookStore())
ShellFactory.createConsoleShell("bookstore@antidote"+args[0], "", new BookStore())
.commandLoop();
}
}
......@@ -13,20 +13,32 @@ import eu.antidotedb.client.SetRef;
public class DemoCommandsExecutor {
//increment a counter without wrapping it in a transaction
public static int incCounter(AntidoteClient client, String cbucket, String key){
Bucket<String> bucket = Bucket.create(cbucket);
CounterRef cnt = bucket.counter(key);
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());
}
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());
}
//update a set without wrapping it in a transaction
public static List<String> addToSet(AntidoteClient client, String cbucket, String key, String elem){
Bucket<String> bucket = Bucket.create(cbucket);
SetRef<String> set = bucket.set(key);
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());
}
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());
}
//update and read with in a transaction
public static String addToSetTxn(AntidoteClient client){
......
......@@ -30,7 +30,7 @@ services:
image: java:8
volumes:
- ../bookstore/build/libs:/code
command: "java -jar bookstore.jar"
command: "java -jar bookstore.jar 1"
working_dir: /code
cap_add:
- NET_ADMIN
......@@ -41,7 +41,7 @@ services:
image: java:8
volumes:
- ../bookstore/build/libs:/code
command: "java -jar bookstore.jar"
command: "java -jar bookstore.jar 2"
working_dir: /code
cap_add:
- NET_ADMIN
......
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