Developing lightweight computation at the DSG edge

Commit f1e444fe authored by Peter Zeller's avatar Peter Zeller
Browse files

unify indentation to use 4 spaces

parent 28810435
# This file is for unifying the coding style for different editors and IDEs
# See editorconfig.org
root = true
[*.java]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
......@@ -4,73 +4,73 @@ import java.net.InetSocketAddress;
public class BookCommands {
public static String userBucket = "userbucket";
public static final RegisterKey<String> emailMapField = Key.register("email");
public static final SetKey<String> ownBooksMapField = Key.set("ownbooks");
public static final SetKey<String> borrowedBooksMapField = Key.set("borrowedbooks");
public AntidoteClient connect(String host, int port) {
not_implemented();
return null;
}
public void assignToRegister(AntidoteClient client, String bucket, String key, String value) {
not_implemented();
}
public void updateMapRegister(AntidoteClient client, String bucket, String key, String mapKey, String value) {
not_implemented();
}
public void getUserInfo(AntidoteClient client, String username){
System.out.println("User: " + username);
System.out.println("Email: " + getEmail(client, username));
System.out.println("Owned Books: " + getOwnedBooks(client, username));
System.out.println("Borrowed Books: " + getBorrowedBooks(client, username));
}
public String addUser(AntidoteClient client, String username, String userEmail){
not_implemented();
return null;
}
public String getEmail(AntidoteClient client, String username){
not_implemented();
return null;
}
public String addOwnedBooks(AntidoteClient client, String username, String book){
not_implemented();
return null;
}
public List<String> getOwnedBooks(AntidoteClient client, String username){
not_implemented();
return null;
}
public String removeOwnedBook(AntidoteClient client, String username, String book){
not_implemented();
return null;
}
public String borrowBook(AntidoteClient client, String fromUser, String byUser, String book){
not_implemented();
return null;
}
public String returnBook(AntidoteClient client, String fromUser, String toUser, String book){
not_implemented();
return null;
}
public List<String> getBorrowedBooks(AntidoteClient client, String username) {
not_implemented();
return null;
}
private void not_implemented(){
throw new RuntimeException("Not Implemented");
}
public static String userBucket = "userbucket";
public static final RegisterKey<String> emailMapField = Key.register("email");
public static final SetKey<String> ownBooksMapField = Key.set("ownbooks");
public static final SetKey<String> borrowedBooksMapField = Key.set("borrowedbooks");
public AntidoteClient connect(String host, int port) {
not_implemented();
return null;
}
public void assignToRegister(AntidoteClient client, String bucket, String key, String value) {
not_implemented();
}
public void updateMapRegister(AntidoteClient client, String bucket, String key, String mapKey, String value) {
not_implemented();
}
public void getUserInfo(AntidoteClient client, String username){
System.out.println("User: " + username);
System.out.println("Email: " + getEmail(client, username));
System.out.println("Owned Books: " + getOwnedBooks(client, username));
System.out.println("Borrowed Books: " + getBorrowedBooks(client, username));
}
public String addUser(AntidoteClient client, String username, String userEmail){
not_implemented();
return null;
}
public String getEmail(AntidoteClient client, String username){
not_implemented();
return null;
}
public String addOwnedBooks(AntidoteClient client, String username, String book){
not_implemented();
return null;
}
public List<String> getOwnedBooks(AntidoteClient client, String username){
not_implemented();
return null;
}
public String removeOwnedBook(AntidoteClient client, String username, String book){
not_implemented();
return null;
}
public String borrowBook(AntidoteClient client, String fromUser, String byUser, String book){
not_implemented();
return null;
}
public String returnBook(AntidoteClient client, String fromUser, String toUser, String book){
not_implemented();
return null;
}
public List<String> getBorrowedBooks(AntidoteClient client, String username) {
not_implemented();
return null;
}
private void not_implemented(){
throw new RuntimeException("Not Implemented");
}
}
......@@ -14,106 +14,106 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public class BookStore {
private AntidoteClient currentSession;
/* *** Demo Commands *** */
@Command
public String hello() {
return "Hello, World!";
}
@Command //test command
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> 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 InetSocketAddress(host, port));
return "Connected to " + host+":"+port;
}
@Command //exit shell
public void quit(){
System.out.println("Exiting app...");
System.exit(0);
}
/* *** BookStore commands *** */
@Command
public void userinfo(String username){
new BookCommands().getUserInfo(currentSession, username);
}
@Command
public String adduser(String username, String userEmail){
return (new BookCommands().addUser(currentSession, username, userEmail));
}
@Command
public String ownbook(String username, String book){
return (new BookCommands().addOwnedBooks(currentSession, username, book));
}
@Command
public List<String> getownedbook(String username){
return (new BookCommands().getOwnedBooks(currentSession, username));
}
@Command
public String removeownedbook(String username, String book){
return (new BookCommands().removeOwnedBook(currentSession, username, book));
}
@Command
public String borrowbook(String fromUser, String byUser, String book){
return (new BookCommands().borrowBook(currentSession, fromUser, byUser, book));
}
@Command
public List<String> getborrowedbook(String username){
return (new BookCommands().getBorrowedBooks(currentSession, username));
}
@Command
public String returnbook(String fromUser, String toUser, String book){
return (new BookCommands().returnBook(currentSession, fromUser, toUser, book));
}
public static void main(String[] args) throws IOException {
Options options = new Options();
options.addOption("t", false, "run the tutorial mode");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e);
System.exit(0);
}
if (cmd.hasOption("t")) {
Tester tutorial = new Tester();
tutorial.test();
} else
ShellFactory.createConsoleShell("bookstore@antidote"+args[0], "", new BookStore())
.commandLoop();
}
private AntidoteClient currentSession;
/* *** Demo Commands *** */
@Command
public String hello() {
return "Hello, World!";
}
@Command //test command
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> 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 InetSocketAddress(host, port));
return "Connected to " + host+":"+port;
}
@Command //exit shell
public void quit(){
System.out.println("Exiting app...");
System.exit(0);
}
/* *** BookStore commands *** */
@Command
public void userinfo(String username){
new BookCommands().getUserInfo(currentSession, username);
}
@Command
public String adduser(String username, String userEmail){
return (new BookCommands().addUser(currentSession, username, userEmail));
}
@Command
public String ownbook(String username, String book){
return (new BookCommands().addOwnedBooks(currentSession, username, book));
}
@Command
public List<String> getownedbook(String username){
return (new BookCommands().getOwnedBooks(currentSession, username));
}
@Command
public String removeownedbook(String username, String book){
return (new BookCommands().removeOwnedBook(currentSession, username, book));
}
@Command
public String borrowbook(String fromUser, String byUser, String book){
return (new BookCommands().borrowBook(currentSession, fromUser, byUser, book));
}
@Command
public List<String> getborrowedbook(String username){
return (new BookCommands().getBorrowedBooks(currentSession, username));
}
@Command
public String returnbook(String fromUser, String toUser, String book){
return (new BookCommands().returnBook(currentSession, fromUser, toUser, book));
}
public static void main(String[] args) throws IOException {
Options options = new Options();
options.addOption("t", false, "run the tutorial mode");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e);
System.exit(0);
}
if (cmd.hasOption("t")) {
Tester tutorial = new Tester();
tutorial.test();
} else
ShellFactory.createConsoleShell("bookstore@antidote"+args[0], "", new BookStore())
.commandLoop();
}
}
......@@ -4,73 +4,73 @@ import java.util.Objects;
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 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 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 cbucket = Bucket.bucket(bucket);
SetKey<String> setKey = Key.set(key);
cbucket.update(client.noTransaction(), setKey.add(elem));
return cbucket.read(client.noTransaction(), setKey);
}
public static List<String> getSet(AntidoteClient client, String bucket, String key){
Bucket cbucket = Bucket.bucket(bucket);
SetKey<String> setKey = Key.set(key);
return cbucket.read(client.noTransaction(),setKey);
}
//update and read with in a transaction
public static String addToSetTxn(AntidoteClient client){
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()) {
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 bucket = Bucket.bucket("testbucket");
CounterKey c1 = Key.counter("c1");
CounterKey c2 = Key.counter("c2");
CounterKey c3 = Key.counter("c3");
//increment a counter without wrapping it in a transaction
public static int incCounter(AntidoteClient client, String bucket, String key){
Bucket cbucket = Bucket.bucket(bucket);
CounterKey cnt = Key.counter(key);
cbucket.update(client.noTransaction(),
cnt.increment(1));
return cbucket.read(client.noTransaction(), cnt);
}
//increment counters in a batch transaction.
AntidoteStaticTransaction tx = client.createStaticTransaction();
bucket.update(tx, c1.increment(1));
bucket.update(tx, c2.increment(1));
bucket.update(tx, c3.increment(1));
tx.commitTransaction();
public static int getCounter(AntidoteClient client, String bucket, String key){
Bucket cbucket = Bucket.bucket(bucket);
CounterKey cnt = Key.counter(key);
return cbucket.read(client.noTransaction(), cnt);
}
//Read multiple keys in batch read
BatchRead batchRead = client.newBatchRead();
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();
//update a set without wrapping it in a transaction
public static List<String> addToSet(AntidoteClient client, String bucket, String key, String elem){
Bucket cbucket = Bucket.bucket(bucket);
SetKey<String> setKey = Key.set(key);
cbucket.update(client.noTransaction(), setKey.add(elem));
return cbucket.read(client.noTransaction(), setKey);
}
return sum;
}
public static List<String> getSet(AntidoteClient client, String bucket, String key){
Bucket cbucket = Bucket.bucket(bucket);
SetKey<String> setKey = Key.set(key);
return cbucket.read(client.noTransaction(),setKey);
}
//update and read with in a transaction
public static String addToSetTxn(AntidoteClient client){
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()) {
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 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();
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 = 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;
}
}
......@@ -10,377 +10,377 @@ import eu.antidotedb.client.*;
public class Tester {
final private String stateBucket = "tutorial";
final private int taskNum = 11;
private String saveObject;
private AntidoteClient tutorialStateSession1;
private AntidoteClient tutorialStateSession2;
private AntidoteClient taskSession;
final private String task4Host="antidote1";
final private int task4Port = 8087;
final private String tutBucket = "tutorial_buck";
final private String task1Counter = "task1_counter";
final private String task1Set = "task1_counter_set";
final private String user1 = "Bob";
final private String user2 = "Alice";
final private String bookTitle = "book1";
public void test() throws IOException {
saveObject = "save_" + System.getenv("ANTIDOTE_TUTORIAL_SAVE");
tutorialStateSession1 = new AntidoteClient(new InetSocketAddress("antidote1", 8087));
tutorialStateSession2 = new AntidoteClient(new InetSocketAddress("antidote2", 8087));
int state = 0; boolean passed;
while (state < taskNum) {
passed = false;
state = getSavedState();
switch (state) {
case 0:
welcome();
advanceSavedState();
System.exit(0);
break;
case 1:
printTask01();
passed = testTask01();
break;
case 2:
printTask02();
passed = testTask02();
break;
case 3:
printTask03();
passed = testTask03();
break;
case 4:
printTask04();
passed = testTask04();
break;
case 5:
printTask05();
passed = testTask05();
break;
case 6:
printTask06();
passed = testTask06();
break;
case 7:
printTask07();
passed = testTask07();
break;
case 8:
printTask08();
passed = testTask08();
break;
case 9:
printTask09();
passed = testTask09();
break;
case 10:
printTask10();
passed = testTask10();
break;
case taskNum:
finished();
break;
default: