Developing lightweight computation at the DSG edge
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Roger Pueyo Centelles
antidote-java-tutorial
Commits
1f43858f
Commit
1f43858f
authored
Jul 11, 2017
by
deepthidevaki
Browse files
add more methods
parent
984ce7fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
bookstore/src/main/java/BookStore.java
View file @
1f43858f
...
...
@@ -19,15 +19,25 @@ public class BookStore {
}
@Command
//test command
public
int
inc
counter
(
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
>
add
toset
(
String
bucket
,
String
key
,
String
item
){
public
List
<
String
>
add
item
(
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
(
"
antidote
bookstore
"
,
""
,
new
BookStore
())
ShellFactory
.
createConsoleShell
(
"bookstore
@antidote"
+
args
[
0
]
,
""
,
new
BookStore
())
.
commandLoop
();
}
}
bookstore/src/main/java/DemoCommandsExecutor.java
View file @
1f43858f
...
...
@@ -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
c
bucket
,
String
key
){
Bucket
<
String
>
bucket
=
Bucket
.
create
(
c
bucket
);
CounterRef
cnt
=
bucket
.
counter
(
key
);
public
static
int
incCounter
(
AntidoteClient
client
,
String
bucket
,
String
key
){
Bucket
<
String
>
c
bucket
=
Bucket
.
create
(
bucket
);
CounterRef
cnt
=
c
bucket
.
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
c
bucket
,
String
key
,
String
elem
){
Bucket
<
String
>
bucket
=
Bucket
.
create
(
c
bucket
);
SetRef
<
String
>
set
=
bucket
.
set
(
key
);
public
static
List
<
String
>
addToSet
(
AntidoteClient
client
,
String
bucket
,
String
key
,
String
elem
){
Bucket
<
String
>
c
bucket
=
Bucket
.
create
(
bucket
);
SetRef
<
String
>
set
=
c
bucket
.
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
){
...
...
setup/docker-compose.yml
View file @
1f43858f
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment