10.2. Build the Football Application

The following procedure outlines the steps to build a football manager application as an example of REST, Hot Rod and memcached endpoints in JBoss Data Grid.

Note

JBoss Data Grid does not support deploying applications, therefore this quickstart cannot be installed as a deployment.

Procedure 10.1. Build the Football Application

  1. Add Configurations

    Edit the standalone.xml file (located at $JDG_HOME/standalone/configuration/) to add definitions for the datasource and infinispan subsystems.
    1. Add the following subsystem definition for the datasource:
      <subsystem xmlns="urn:jboss:domain:datasources:1.0"> 
      	<datasources> 
      		<datasource jndi-name="java:jboss/datasources/ExampleDS" 
      			    pool-name="ExampleDS" 
      			    enabled="true" 
      			    use-java-context="true"> 
      			<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url> 
      			<driver>h2</driver> 
      			<security> 
      				<user-name>sa</user-name> 
      				<password>sa</password> 
      			</security> 
      		</datasource> 
      		<drivers> 
      			<driver name="h2" 
      				module="com.h2database.h2"> 
      				<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> 
      			</driver> 
      		</drivers> 
      	</datasources> 
      </subsystem>
      
      
    2. Add the following subsystem definition for infinispan:
      <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="local"> 
      	<cache-container name="local" 
      			 default-cache="memcachedCache" 
      			 listener-executor="infinispan-listener" 
      			 start="EAGER"> 
      		<local-cache name="memcachedCache" 
      			     start="EAGER" 
      			     batching="false" 
      			     indexing="NONE"> 
      			<locking isolation="REPEATABLE_READ" 
      				 acquire-timeout="20000" 
      				 concurrency-level="500" 
      				 striping="false" /> 
      			<transaction mode="NONE" /> 
      			<string-keyed-jdbc-store datasource="java:jboss/datasources/ExampleDS" 
      						 passivation="false" 
      						 preload="false" 
       						 purge="false"> 
      				<property name="databaseType">H2</property> 
      				<string-keyed-table prefix="JDG"> 
      					<id-column name="id" 
      						   type="VARCHAR"/> 
      					<data-column name="datum" 
      						     type="BINARY"/> 
      					<timestamp-column name="version" 
      							  type="BIGINT"/> 
      				</string-keyed-table> 
      			</string-keyed-jdbc-store> 
      		</local-cache> 
      		<local-cache name="teams" 
      			     start="EAGER" 
        			     batching="false" 
      			     indexing="NONE"> 
      			<locking isolation="REPEATABLE_READ" 
      				 acquire-timeout="20000" 
      			 	 concurrency-level="500" 
      				 striping="false" />  
      			<transaction mode="NONE" /> 
      			<string-keyed-jdbc-store datasource="java:jboss/datasources/ExampleDS" 
      						 passivation="false" 
      						 preload="false" 
      						 purge="false"> 
      				<property name="databaseType">H2</property> 
      				<string-keyed-table prefix="JDG"> 
      					<id-column name="id" 
      						   type="VARCHAR"/> 
      					<data-column name="datum" 
      						     type="BINARY"/> 
      					<timestamp-column name="version" 
      							  type="BIGINT"/> 
      				</string-keyed-table> 
      			</string-keyed-jdbc-store> 
      		</local-cache> 
      	</cache-container> 
      </subsystem>
      
      

    Note

    The Hot Rod and REST endpoints use the cache named teams and memcached endpoint uses memcachedCache as a default.
  2. Edit the Submodule Configuration File

    Each submodule (specifically hotrod-endpoint, rest-endpoint and memcached-endpoint) contains a configuration file (located at $JDG_HOME/src/main/resources/jdg.properties). Edit the configuration to specify the values required for your JBoss Data Grid installation. The Hot Rod endpoint requires further configuration, as follows:
    1. Install the Maven Repository

      For initial testing in a small team, the repository can be extracted to a directory on the local file system as follows:
      unzip jboss-datagrid-maven-repository-6.0.0.zip
      
      This creates a Maven repository in a directory called jboss-datagrid-maven-repository-6.0.0.
      For further information about the installation methods available to install the JBoss Data Grid Maven repository, refer to Chapter 4, Install and Use the Maven Repository.
  3. Build the Application

    Use the following command to build the example application in its directory:
    mvn package
    
    This step results in the use of Maven's shade plugin, which bundles all dependencies into a single jar file for ease of use.
  4. Start JBoss Data Grid

    Run the following script to run JBoss Data Grid:
    $JDG_HOME/bin/standalone.sh
    
  5. Run the Application

    Run the example application in its directory.
    1. For the Hot Rod endpoint, run the following command:
      java -jar target/hotrod-endpoint-quickstart.jar
      
    2. For the memcached endpoint, run the following command:
      java -jar target/memcached-endpoint-quickstart.jar
      
    3. For the REST endpoint, run the following command:
      java -jar target/rest-endpoint-quickstart.jar