Terracotta Framework Library > Samples > Strategy

Distributed Strategy Pattern

About

This sample is a part of the Terracotta Framework Library - tclib. More information is available from the Terracotta Framework Library readme.html.

This application implements a distributed strategy pattern. One node (worker) registers itself to listen for strategies to be sent (aka commands). The other node (master) looks up the list of nodes that are registered and sends the first node in the list a command.

Build Instructions

This sample application requires Maven 2 and Java 5. First download and install Maven 2. Then perform these steps:

  1. Step up into the parent tclib directory cd ../..
  2. Invoke mvn install to install the tclib library
  3. Step back into the spider sample directory
  4. Invoke mvn package to build the application.

Run Instructions

  1. Start a TC Server:

    $ mvn tc:start

  2. Start a worker to listen for commands:

    $ mvn -DactiveNodes=worker tc:run

  3. Invoke a main method to send a "say" command:

    $ mvn -DactiveNodes=say tc:run

  4. Start another worker to listen for commands:

    $ mvn -DactiveNodes=worker tc:run

  5. Invoke another "say" command. Notice it sends to only to one worker:

    $ mvn -DactiveNodes=say tc:run

  6. Invoke a "say" command on all nodes. Notice it sends the command to all workers:

    $ mvn -DactiveNodes=sayAll tc:run