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
cd656778
Commit
cd656778
authored
Jan 07, 2019
by
Ilyas Toumlilt
Browse files
Update to latest version of antidote java client (0.3.0)
parent
c61c0c39
Changes
4
Hide whitespace changes
Inline
Side-by-side
bookstore/build.gradle
View file @
cd656778
...
...
@@ -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"
)
...
...
bookstore/src/main/java/BookCommands.java
View file @
cd656778
...
...
@@ -50,7 +50,7 @@ public class BookCommands {
return
null
;
}
void
not_implemented
(){
private
void
not_implemented
(){
throw
new
RuntimeException
(
"Not Implemented"
);
}
}
bookstore/src/main/java/BookStore.java
View file @
cd656778
...
...
@@ -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
;
}
...
...
bookstore/src/main/java/DemoCommandsExecutor.java
View file @
cd656778
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
);
Counter
Ref
cnt
=
cbucket
.
counter
(
key
);
return
c
n
t
.
read
(
client
.
noTransaction
());
Bucket
cbucket
=
Bucket
.
bucket
(
bucket
);
Counter
Key
cnt
=
Key
.
counter
(
key
);
return
c
bucke
t
.
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
);
Set
Ref
<
String
>
set
=
cbucket
.
set
(
key
);
set
.
add
(
client
.
noTransaction
(),
elem
);
return
s
et
.
read
(
client
.
noTransaction
());
Bucket
cbucket
=
Bucket
.
bucket
(
bucket
);
Set
Key
setKey
=
Key
.
set
(
key
);
cbucket
.
update
(
client
.
noTransaction
(),
setKey
.
add
(
elem
)
)
;
return
(
List
<
String
>)
cbuck
et
.
read
(
client
.
noTransaction
()
,
setKey
);
}
public
static
List
<
String
>
getSet
(
AntidoteClient
client
,
String
bucket
,
String
key
){
Bucket
<
String
>
cbucket
=
Bucket
.
create
(
bucket
);
Set
Ref
<
String
>
set
=
cbucket
.
set
(
key
);
return
s
et
.
read
(
client
.
noTransaction
());
Bucket
cbucket
=
Bucket
.
bucket
(
bucket
);
Set
Key
setKey
=
Key
.
set
(
key
);
return
(
List
<
String
>)
cbuck
et
.
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
=
cn
t
.
read
(
tx
);
set
.
add
(
tx
,
"i:"
+
i
);
tx
.
commitTransaction
();
}
return
"ok"
;
bucket
.
update
(
tx
,
c
.
increment
(
1
)
);
int
i
=
bucke
t
.
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"
);
Counter
Ref
a
=
bucket
.
counter
(
"batchcounter
1"
);
Counter
Ref
b
=
bucket
.
counter
(
"batchcounter
2"
);
Counter
Ref
c
=
bucket
.
counter
(
"
batchcounter
3"
);
//increment counters in a batch transaction.
Bucket
bucket
=
Bucket
.
bucket
(
"testbucket"
);
Counter
Key
c1
=
Key
.
counter
(
"c
1"
);
Counter
Key
c2
=
Key
.
counter
(
"c
2"
);
Counter
Key
c
3
=
Key
.
counter
(
"
c
3"
);
//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
)
);
b
ucket
.
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
;
}
}
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