Simple terracotta interaction

The purpose of the tutorial is to give you an insight in how SemiSpace is intended to work together with Terracotta. Terracotta needs to be configured as explained in the installation chapter.

Running the sources

Presumably, you have the sources downloaded and and installed. Perform:

cd semispace-tutorials/semispace-tutorial
mvn clean install
mvn assembly:assembly
cd target
unzip tutorial.zip 
chmod a+x *.sh

Start the Terracotta server as explained in the Terracotta chapter. Run the java program in order to insert a value into the space:

 ./insert.sh something value

You should see a message at the bottom similar to:

Element inserted successfully: something=value

Then try to retieve it:

 ./take.sh something

This should render:

Element found: something=value

Try to run the take.sh script again. This should not find another instance, and the output should be (after a waiting time, due to 1 minute timeout in wait):

Could not find an element with name something

If you get any errors, it is likely that you have not configured the environment correct, i.e. forgotten the TC_INSTALL_DIR variable.

The take.sh script performs a take instead of a read, the difference being that the element is removed from the space.

Trying notification

This program only works when distributed with Terracotta. This is as notification is not exposed over webservices. Furthermore, as this program hangs in an endless loop, you must press CTRL-C to stop it.

The program will use notify, and subscribe to all objects of type Element. This means that you get an output every time you perform an insert into the space. Start the program with notify.sh.

When using the notify.sh, the insert.sh program may report an error. If it does, it is just because it is shutting down at the moment the event is being distributed.

What can you use this to do

This simple example lets you experiment with the Terracotta configuration. Let's say you want to test Terracotta failover. Perform the following steps:

  • Modify the Terracotta "servers" configuration to include two different servers.
  • Start Terracotta on both servers
  • Run an "insert" (with insert.sh)
  • Stop one of the Terracotta instances
  • If applicable, modify your TC_CONFIG_PATH value
  • Run a "take": Expect everything to still work.
  • If you are running the "notify" program, you should get an output for all elements added.