Home

Awesome

AntidoteDB Java Tutorial

This is a sample application to demonstrate how to build applications that use AntidoteDB as backend database.

This tutorial is made for Antidote Bookstore Tutorial

What you need

Clone source code

git clone https://github.com/AntidoteDB/antidote-java-tutorial

Getting started

This repository is divided into two source directories:

Note: make sure you have the software requirements listed above before following next steps.

Step 1 : Starting antidote nodes

The following script starts two antidote docker containers and set up the inter-dc replication.

# in setup/
./start_antidote.sh

Step 2 : Interactive Tutorial / Game

The interactive tutorial is an executable that presents a series of tasks/challenges. Each task has an outcome, SUCCESS or FAIL. Solving a task allows you to try out the next task. To try the interactive tutorial:

Open a new shell:

# in setup/
./tutorial_setup.sh
# build the tutorial
root@tutorial$ ./gradlew build
# run the tutorial executable
root@tutorial$ ./tutorial.sh

In case you want to reset your progress:

# in setup/
./stop_antidote.sh
./start_antidote.sh
Note: Solving the interactive tutorial is equivalent to following steps 3, 4 and 5 bellow. Alternatively, you can skip this step and go directly to step 3.

Step 3 : Starting the application

Open two shells:

# in setup/
./app1_setup.sh
# build the app code
root@app1$ ./gradlew build
# and start the app
root@app1$ ./app1.sh
# then connect the app to Antidote instance 1:
bookstore@antidote1 > connect antidote1 8087
# in setup/
./app2_setup.sh
# build the app code
root@app2$ ./gradlew build
# and start the app
root@app2$ ./app2.sh
# then connect the app to Antidote instance 2:
bookstore@antidote2 > connect antidote2 8087

We have now deployed this configuration:

Tutorial Figure

Step 4 : Try the following app commands

Some commands are already implemented in the app, lets try them:

bookstore@antidote> inc testbucket mycounter
bookstore@antidote> getcounter testbucket mycounter
bookstore@antidote> additem testbucket myset newitem
bookstore@antidote> getset testbucket myset

To stop the app:

bookstore@antidote> quit

You can also try to disconnect Antidote servers to simulate network partitions, commit some concurrent updates, then reconnect to merge CRDTs:

# in setup/
./disconnect.sh #to disrupt communication between Antidote1 and Antidote2 nodes

#then update objects while disconnected

./connect.sh #connect Antidote nodes back

To stop the two Antidote Nodes:

# in setup/
./stop_antidote.sh

Step 5 : Hands On!!!

We now want to build our Bookstore app. The provided sources are divided into 3 files (located in bookstore/src/main/):

The main method is located at bookstore/src/main/java/BookStore.java.

To re-build the app after modifying the source code:

some_docker_container$ ./gradlew build

where some_docker_container may be:

Resources:

Some useful references:

License

View license information for the software contained in this image.