Chapter 15. The Hello World Quickstart

15.1. The Hello World Quickstart

Hello World is a simple quickstart that illustrates how to store and retrieve data from a cache using Red Hat JBoss Data Grid. For this quickstart, users can access the cache in two ways:

  • from a servlet.
  • from a JSF page using request scoped beans.

All libraries (JAR files) bundles with the application are deployed to JBoss Enterprise Application Platform 7.x. JBoss Data Grid’s Library mode only allows local access to a single node in a distributed cluster. This mode also allows the application to access the data grid functionality within a virtual machine in the target container.

Important

The Hello World quickstart works only in JBoss Data Grid’s Library mode.

Location

JBoss Data Grid’s Hello World quickstart is available at the following location: jboss-datagrid-{VERSION}-quickstarts/

15.2. Quickstart Prerequisites

The prerequisites for this quickstart are as follows:

  • Java 8.0 (Java SDK 1.8) or better
  • JBoss Enterprise Application Platform 7.x or JBoss Enterprise Web Server 2.x
  • Maven 3.0 or better
  • Configure the Maven Repository. For details, see Install and Use the Maven Repositories.

15.3. Start Two Application Server Instances

Before deploying the Hello World quickstart, start two instances of your application server (JBoss Enterprise Application Platform 7.x).

Start the First Application Server Instance

  1. Navigate to the Root Directory

    In the command line terminal, navigate to the root for your JBoss server directory.

  2. Start the First Application Server

    Depending on your operating system, use the appropriate command from the following to start the first instance of your selected application server:

    1. For Linux:

      $JBOSS_HOME/bin/standalone.sh
    2. For Windows:

      $JBOSS_HOME\bin\standalone.bat

Start the Second Application Server Instance

  1. Clone the Application Server

    Create a copy of the selected JBoss Server to create a second instance.

  2. Navigate to the Root Directory

    In the command line terminal, navigate to the root for your JBoss server directory.

  3. Start the Second Application Server

    Use the appropriate command for your operating system from the following commands. This command starts the server with the provided port offset to ensure that both the server instances run on the same host.

    1. For Linux:

      $JBOSS_HOME2/bin/standalone.sh -Djboss.socket.binding.port-offset=100
    2. For Windows:

      $JBOSS_HOME2\bin\standalone.bat -Djboss.socket.binding.port-offset=100

15.4. Build and Deploy the Hello World Quickstart

Before building and deploying the quickstart, ensure that all the listed prerequisites are met and that the two application server instances are running (see for details).

Build and Deploy the Hello World Quickstart

  1. Navigate to the Required Directory

    In the command line terminal, navigate to the root directory of the quickstart on the command line interface.

  2. Build and Deploy to the First Application Server Instance

    Use the following command to build and deploy the quickstart to the first application server instance as follows:

    # mvn clean package wildfly:deploy

    This command deploys target/[path]jboss-helloworld-jdg.war to the first running server instance.

  3. Build and Deploy the Second Application Server Instance

    Use the following command to build and deploy the quickstart to the second application server instance with the specified ports as follows:

    # mvn clean package wildfly:deploy -Dwildfly.port=10090

    This command deploys target/[path]jboss-helloworld-jdg.war to the second running server instance.

15.5. Access the Running Application

The Hello World quickstart application runs on the following URLs:

15.6. Test Replication on the Application

Use the following instructions to test that cache entries are replicating from the first server instance to the second as desired.

Test Replication on the Application

  1. Access the First Server

    Access the first application server and enter the key and value.

    1. Access the first application server in a browser window using the following URL:

      http://localhost:8080/jboss-helloworld-jdg
    2. Insert the key foo.
    3. Insert the value bar.
  2. Access the Second Server

    Access the second application server and enter the key and value.

    1. Access the second application server in a browser window using the following URL:

      http://localhost:8180/jboss-helloworld-jdg
    2. Click Get Some.
    3. Get the key foo.
    4. Click Put Some More.
    5. Insert the key mykey.
    6. Insert the value myvalue.
  3. Get All Keys and Values

    Access the first server and request all keys.

    1. Access the first application server in a browser window using the following URL:

      http://localhost:8080/jboss-helloworld-jdg
    2. Click Get Some.
    3. Click Get All to request all key and values.

As the results of the last step show, all the data added at each server has been replicated to the other server.

Note

Entries expire after 60 seconds from the most recent update.

Directly Access Keys in the Cache

To interact with predefined servlets or to directly store and retrieve keys from the cache, use the following URLs:

http://localhost:8080/jboss-helloworld-jdg/TestServletPut
http://localhost:8180/jboss-helloworld-jdg/TestServletGet

15.7. Remove the Application

Use the following procedure to remove the Hello World application:

Remove the Application

  1. Start the Application Servers

    Ensure that both server instances are running.

  2. Navigate to the Root

    In the command line terminal, navigate to the root directory of the quickstart.

  3. Remove the Archive

    Use the following commands to remove the archive from both the server instances.

    1. Remove the archive from the first server as follows:

      mvn wildfly:undeploy
    2. Remove the archive from the second server as follows:

      mvn wildfly:undeploy -Dwildfly.port=10090