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; ...@@ -4,73 +4,73 @@ import java.net.InetSocketAddress;
public class BookCommands { public class BookCommands {
public static String userBucket = "userbucket"; public static String userBucket = "userbucket";
public static final RegisterKey<String> emailMapField = Key.register("email"); public static final RegisterKey<String> emailMapField = Key.register("email");
public static final SetKey<String> ownBooksMapField = Key.set("ownbooks"); public static final SetKey<String> ownBooksMapField = Key.set("ownbooks");
public static final SetKey<String> borrowedBooksMapField = Key.set("borrowedbooks"); public static final SetKey<String> borrowedBooksMapField = Key.set("borrowedbooks");
public AntidoteClient connect(String host, int port) { public AntidoteClient connect(String host, int port) {
not_implemented(); not_implemented();
return null; return null;
} }
public void assignToRegister(AntidoteClient client, String bucket, String key, String value) { public void assignToRegister(AntidoteClient client, String bucket, String key, String value) {
not_implemented(); not_implemented();
} }
public void updateMapRegister(AntidoteClient client, String bucket, String key, String mapKey, String value) { public void updateMapRegister(AntidoteClient client, String bucket, String key, String mapKey, String value) {
not_implemented(); not_implemented();
} }
public void getUserInfo(AntidoteClient client, String username){ public void getUserInfo(AntidoteClient client, String username){
System.out.println("User: " + username); System.out.println("User: " + username);
System.out.println("Email: " + getEmail(client, username)); System.out.println("Email: " + getEmail(client, username));
System.out.println("Owned Books: " + getOwnedBooks(client, username)); System.out.println("Owned Books: " + getOwnedBooks(client, username));
System.out.println("Borrowed Books: " + getBorrowedBooks(client, username)); System.out.println("Borrowed Books: " + getBorrowedBooks(client, username));
} }
public String addUser(AntidoteClient client, String username, String userEmail){ public String addUser(AntidoteClient client, String username, String userEmail){
not_implemented(); not_implemented();
return null; return null;
} }
public String getEmail(AntidoteClient client, String username){ public String getEmail(AntidoteClient client, String username){
not_implemented(); not_implemented();
return null; return null;
} }
public String addOwnedBooks(AntidoteClient client, String username, String book){ public String addOwnedBooks(AntidoteClient client, String username, String book){
not_implemented(); not_implemented();
return null; return null;
} }
public List<String> getOwnedBooks(AntidoteClient client, String username){ public List<String> getOwnedBooks(AntidoteClient client, String username){
not_implemented(); not_implemented();
return null; return null;
} }
public String removeOwnedBook(AntidoteClient client, String username, String book){ public String removeOwnedBook(AntidoteClient client, String username, String book){
not_implemented(); not_implemented();
return null; return null;
} }
public String borrowBook(AntidoteClient client, String fromUser, String byUser, String book){ public String borrowBook(AntidoteClient client, String fromUser, String byUser, String book){
not_implemented(); not_implemented();
return null; return null;
} }
public String returnBook(AntidoteClient client, String fromUser, String toUser, String book){ public String returnBook(AntidoteClient client, String fromUser, String toUser, String book){
not_implemented(); not_implemented();
return null; return null;
} }
public List<String> getBorrowedBooks(AntidoteClient client, String username) { public List<String> getBorrowedBooks(AntidoteClient client, String username) {
not_implemented(); not_implemented();
return null; return null;
} }
private void not_implemented(){ private void not_implemented(){
throw new RuntimeException("Not Implemented"); throw new RuntimeException("Not Implemented");
} }
} }
...@@ -14,106 +14,106 @@ import org.apache.commons.cli.Options; ...@@ -14,106 +14,106 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException; import org.apache.commons.cli.ParseException;
public class BookStore { public class BookStore {
private AntidoteClient currentSession; private AntidoteClient currentSession;
/* *** Demo Commands *** */ /* *** Demo Commands *** */
@Command @Command
public String hello() { public String hello() {
return "Hello, World!"; return "Hello, World!";
} }
@Command //test command @Command //test command
public int inc(String bucket, String key){ public int inc(String bucket, String key){
return DemoCommandsExecutor.incCounter(currentSession, bucket, key); return DemoCommandsExecutor.incCounter(currentSession, bucket, key);
} }
@Command @Command
public int getcounter(String bucket, String key){ public int getcounter(String bucket, String key){
return DemoCommandsExecutor.getCounter(currentSession, bucket, key); return DemoCommandsExecutor.getCounter(currentSession, bucket, key);
} }
@Command @Command
public List<String> additem(String bucket, String key, String item){ public List<String> additem(String bucket, String key, String item){
return DemoCommandsExecutor.addToSet(currentSession, bucket, key, item); return DemoCommandsExecutor.addToSet(currentSession, bucket, key, item);
} }
@Command @Command
public List<String> getset(String bucket, String key){ public List<String> getset(String bucket, String key){
return DemoCommandsExecutor.getSet(currentSession, bucket, key); return DemoCommandsExecutor.getSet(currentSession, bucket, key);
} }
@Command //connect antidote @Command //connect antidote
public String connect(String host, int port){ public String connect(String host, int port){
currentSession = new AntidoteClient(new InetSocketAddress(host, port)); currentSession = new AntidoteClient(new InetSocketAddress(host, port));
return "Connected to " + host+":"+port; return "Connected to " + host+":"+port;
} }
@Command //exit shell @Command //exit shell
public void quit(){ public void quit(){
System.out.println("Exiting app..."); System.out.println("Exiting app...");
System.exit(0); System.exit(0);
} }
/* *** BookStore commands *** */ /* *** BookStore commands *** */
@Command @Command
public void userinfo(String username){ public void userinfo(String username){
new BookCommands().getUserInfo(currentSession, username); new BookCommands().getUserInfo(currentSession, username);
} }
@Command @Command
public String adduser(String username, String userEmail){ public String adduser(String username, String userEmail){
return (new BookCommands().addUser(currentSession, username, userEmail)); return (new BookCommands().addUser(currentSession, username, userEmail));
} }
@Command @Command
public String ownbook(String username, String book){ public String ownbook(String username, String book){
return (new BookCommands().addOwnedBooks(currentSession, username, book)); return (new BookCommands().addOwnedBooks(currentSession, username, book));
} }
@Command @Command
public List<String> getownedbook(String username){ public List<String> getownedbook(String username){
return (new BookCommands().getOwnedBooks(currentSession, username)); return (new BookCommands().getOwnedBooks(currentSession, username));
} }
@Command @Command
public String removeownedbook(String username, String book){ public String removeownedbook(String username, String book){
return (new BookCommands().removeOwnedBook(currentSession, username, book)); return (new BookCommands().removeOwnedBook(currentSession, username, book));
} }
@Command @Command
public String borrowbook(String fromUser, String byUser, String book){ public String borrowbook(String fromUser, String byUser, String book){
return (new BookCommands().borrowBook(currentSession, fromUser, byUser, book)); return (new BookCommands().borrowBook(currentSession, fromUser, byUser, book));
} }
@Command @Command
public List<String> getborrowedbook(String username){ public List<String> getborrowedbook(String username){
return (new BookCommands().getBorrowedBooks(currentSession, username)); return (new BookCommands().getBorrowedBooks(currentSession, username));
} }
@Command @Command
public String returnbook(String fromUser, String toUser, String book){ public String returnbook(String fromUser, String toUser, String book){
return (new BookCommands().returnBook(currentSession, fromUser, toUser, book)); return (new BookCommands().returnBook(currentSession, fromUser, toUser, book));
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Options options = new Options(); Options options = new Options();
options.addOption("t", false, "run the tutorial mode"); options.addOption("t", false, "run the tutorial mode");
CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new DefaultParser();
CommandLine cmd = null; CommandLine cmd = null;
try { try {
cmd = parser.parse(options, args); cmd = parser.parse(options, args);
} catch (ParseException e) { } catch (ParseException e) {
System.out.println(e); System.out.println(e);
System.exit(0); System.exit(0);
} }
if (cmd.hasOption("t")) { if (cmd.hasOption("t")) {
Tester tutorial = new Tester(); Tester tutorial = new Tester();
tutorial.test(); tutorial.test();
} else } else
ShellFactory.createConsoleShell("bookstore@antidote"+args[0], "", new BookStore()) ShellFactory.createConsoleShell("bookstore@antidote"+args[0], "", new BookStore())
.commandLoop(); .commandLoop();
} }
} }
...@@ -4,73 +4,73 @@ import java.util.Objects; ...@@ -4,73 +4,73 @@ import java.util.Objects;
import eu.antidotedb.client.*; import eu.antidotedb.client.*;
public class DemoCommandsExecutor { 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 //increment a counter without wrapping it in a transaction
public static List<String> addToSet(AntidoteClient client, String bucket, String key, String elem){ public static int incCounter(AntidoteClient client, String bucket, String key){
Bucket cbucket = Bucket.bucket(bucket); Bucket cbucket = Bucket.bucket(bucket);
SetKey<String> setKey = Key.set(key); CounterKey cnt = Key.counter(key);
cbucket.update(client.noTransaction(), setKey.add(elem)); cbucket.update(client.noTransaction(),
return cbucket.read(client.noTransaction(), setKey); cnt.increment(1));
} return cbucket.read(client.noTransaction(), cnt);
}
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. public static int getCounter(AntidoteClient client, String bucket, String key){
AntidoteStaticTransaction tx = client.createStaticTransaction(); Bucket cbucket = Bucket.bucket(bucket);
bucket.update(tx, c1.increment(1)); CounterKey cnt = Key.counter(key);
bucket.update(tx, c2.increment(1)); return cbucket.read(client.noTransaction(), cnt);
bucket.update(tx, c3.increment(1)); }
tx.commitTransaction();
//Read multiple keys in batch read //update a set without wrapping it in a transaction
BatchRead batchRead = client.newBatchRead(); public static List<String> addToSet(AntidoteClient client, String bucket, String key, String elem){
BatchReadResult<Integer> c1val = bucket.read(batchRead, c1); Bucket cbucket = Bucket.bucket(bucket);
BatchReadResult<Integer> c2val = bucket.read(batchRead, c2); SetKey<String> setKey = Key.set(key);
BatchReadResult<Integer> c3val = bucket.read(batchRead, c3); cbucket.update(client.noTransaction(), setKey.add(elem));
batchRead.commit(client.noTransaction()); return cbucket.read(client.noTransaction(), setKey);
int sum = c1val.get() + c2val.get() + c3val.get(); }
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;
}
} }
This diff is collapsed.
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