第16章 The CarMart Quickstarts
16.1. About the CarMart Quickstart
Red Hat JBoss Data Grid includes a transactional and non-transactional CarMart quickstart. The CarMart quickstart is a simple web application that uses JBoss Data Grid instead of a relational database. Information about each car is stored in a cache. Caches are configured declaratively or programmatically depending on the usage mode.
Features
The CarMart quickstart offers the following features:
- List all cars
- Add new cars
- Remove cars
- View statistics for caches, such as hits, stores, and retrievals
Usage Modes
The CarMart quickstart can be used in the following JBoss Data Grid usage modes:
- Remote Client-Server Mode, where the application includes the Hot Rod client to communicate with a remote JBoss Data Grid server.
-
Library Mode, where all libraries are bundled with the application in the form of
jar
files.
Location
JBoss Data Grid’s CarMart quickstart is available at the following location: jboss-datagrid-{VERSION}-quickstarts/
16.2. About the CarMart Transactional Quickstart
The transactional version of the CarMart quickstart is a simple web application that uses Red Hat JBoss Data Grid instead of a relational database. Information about each car is stored in a cache. Caches are configured declaratively or programmatically (depending on the usage mode) and run in the same Java Virtual Machine (JVM) as the web application.
Features
The Transactional CarMart Quickstart offers the following features:
- List all cars
- Add new cars
- Add new cars with rollback
- Remove cars
- View statistics for caches, such as hits, stores, and retrievals
Usage Modes
The Transactional CarMart Quickstart can only be used in JBoss Data Grid’s Library mode. A standalone transaction manager from JBoss Transactions is used when the Transactional CarMart Quickstart is run in Red Hat JBoss Enterprise Web Server 2.x.
Location
JBoss Data Grid’s Transactional CarMart Quickstart can be found at the following location: jboss-datagrid-{VERSION}-quickstarts/carmart-tx
16.3. Differences Between the CarMart and Transactional Quickstarts
Despite the similarity in steps to build, deploy and remove the transactional and non-transactional CarMart quickstarts, some differences must be noted. The following is a list of such differences:
- CarMart is available for both Remote Client-Server Mode and Library Mode. Transactional CarMart is only available in Library Mode because transactions are not available in Remote Client-Server Mode.
- The Transactional Quickstart also displays how a transaction rollback occurs. Use the Add car with rollback button to view the rollback. The CarMart example has a simple Add car button instead.
16.4. The (Non-transactional) CarMart Quickstart Using JBoss EAP
16.4.1. The CarMart Quickstart Using JBoss EAP
The Carmart (non-transactional) quickstart is supported for JBoss Data Grid’s Library Mode with the JBoss EAP container.
16.4.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.
16.4.3. Build and Deploy the CarMart Quickstart to JBoss EAP
The following procedure provides directions to build and deploy the CarMart application to JBoss EAP.
Prerequisites
Prerequisites for this procedure are as follows:
- Obtain the supported JBoss Data Grid Library Mode distribution files.
- Ensure that the JBoss Data Grid and JBoss Enterprise Application Platform Maven repositories are installed and configured. For details, see Install and Use the Maven Repositories
- Select a JBoss server to use (JBoss Enterprise Application Platform6 (or better) or JBoss EAP6 (or better).
Build and Deploy CarMart to JBoss EAP
Start JBoss EAP
Depending on your operating system, use the appropriate command from the following to start the first instance of your selected application server:
For Linux users:
$JBOSS_HOME/bin/standalone.sh
For Windows users:
$JBOSS_HOME\bin\standalone.bat
Navigate to the Root Directory
Open a command line and navigate to the root directory of this quickstart.
Build and Deploy the Application
Use the following command to build and deploy the application to the running instance of JBoss EAP using Maven:
$ mvn clean package jboss-as:deploy
16.4.4. View the CarMart Quickstart on JBoss EAP
The following procedure outlines how to view the CarMart quickstart on JBoss EAP:
Prerequisite
The CarMart quickstart must be built and deployed to be viewed.
View the CarMart Quickstart on JBoss EAP
To view the application, use your browser to navigate to the following link:
http://localhost:8080/jboss-carmart
16.4.5. Remove the CarMart Quickstart from JBoss EAP
The following procedure provides directions to remove a deployed application from JBoss EAP.
Remove an Application from JBoss EAP
To remove an application, use the following from the root directory of this quickstart:
$ mvn jboss-as:undeploy
16.5. The (Non-transactional) CarMart Quickstart Using JBoss Enterprise Web Server
16.5.1. The CarMart Quickstart Using JBoss Enterprise Web Server
The Carmart (non-transactional) quickstart is supported for JBoss Data Grid’s Library Mode with the JBoss Enterprise Web Server container.
16.5.2. Build and Deploy the CarMart Quickstart to JBoss Enterprise Web Server
The following procedure provides directions to build and deploy the CarMart quickstart to the JBoss Enterprise Web Server.
Prerequisites
Prerequisites for this procedure are as follows:
- Ensure that the JBoss Data Grid and JBoss Enterprise Application Platform Maven repositories are installed and configured. For details, see Install and Use the Maven Repositories
- Select JBoss Enterprise Web Server 2 (or better) for your application and install it.
Build the CarMart Quickstart to the Server (Library Mode)
Start the Server
Depending on your operating system, use the appropriate command from the following to start the first instance of your selected application server:
For Linux users:
$JBOSS_EWS_HOME/tomcat7/bin/catalina.sh run
For Windows users:
$JBOSS_EWS_HOME\tomcat7\bin\catalina.bat run
Navigate to the Root Directory
Open a command line and navigate to the root directory of this quickstart.
Build and Deploy Your Application
Use the following command to build and deploy your application to the running instance of the selected server using Maven:
$ mvn -Plibrary-tomcat clean package tomcat:deploy
16.5.3. View the CarMart Quickstart Using JBoss Enterprise Web Server
The following procedure outlines how to view the CarMart quickstart on the JBoss Enterprise Web Server:
Prerequisite
The CarMart quickstart must be built and deployed to be viewed.
View the CarMart Quickstart
To view the application, use your browser to navigate to the following link:
http://localhost:8080/jboss-carmart
16.5.4. Remove the CarMart Quickstart from JBoss Enterprise Web Server
The following procedure provides directions to remove an already deployed application from JBoss Enterprise Web Server.
Remove an Application from JBoss Enterprise Web Server
To remove an application, use the following command from the root directory of this quickstart:
$ mvn tomcat:undeploy -Plibrary-tomcat
16.6. The (Non-transactional) CarMart Quickstart in Remote Client-Server Mode (JBoss EAP)
16.6.1. The CarMart Quickstart in Remote Client-Server Mode
The Carmart (non-transactional) quickstart is supported for JBoss Data Grid’s Remote Client-Server Mode with the JBoss Enterprise Application Platform container.
16.6.2. Build and Deploy the CarMart Quickstart in Remote Client-Server Mode
This quickstart accesses Red Hat JBoss Data Grid via Hot Rod. This feature is not available for the Transactional CarMart quickstart.
This quickstart deploys to JBoss Enterprise Application Platform. The application cannot be deployed to JBoss Data Grid because it does not support application deployment.
Prerequisites
Prerequisites for this procedure are as follows:
- Obtain the most recent supported JBoss Data Grid Remote Client-Server Mode distribution files from RedHat.
- Ensure that the JBoss Data Grid and JBoss Enterprise Application Platform Maven repositories are installed and configured. For details, see Install and Use the Maven Repositories
Select a JBoss server to use (JBoss Enterprise Application Platform 6 or later). Navigate to the root of the JBoss server directory in a terminal window and enter the following command:
For Linux users:
$JBOSS_HOME/bin/standalone.sh
For Windows users:
$JBOSS_HOME\bin\standalone.bat
Build and Deploy the CarMart Quickstart in Remote Client-Server Mode
Configure the Standalone File
Add the following configuration to the standalone.xml file located in the $JDG_HOME/standalone/configuration/ directory.
Add the following configuration within the infinispan subsystem tags:
<local-cache name="carcache" statistics="true"> <eviction strategy="LIRS" max-entries="4"/> </local-cache>
注記If the
carcache
element already exists in your configuration, replace it with the provided configuration.
Start the JBoss Data Grid Server
Run the following script to start the JBoss Data Grid Server:
$JDG_HOME/bin/standalone.sh -Djboss.socket.binding.port-offset=100
Start the JBoss Server
Run the following script to start the JBoss server instance where your application will deploy:
$JBOSS_HOME/bin/standalone.sh
Optional: Specify the Host and Port Address
The application uses the values in the jboss-datagrid-{VERSION}-quickstarts/carmart/src/main/resources/META-INF/[path]datagrid.properties file to locate the JBoss Data Grid server. If your JBoss Data Grid server is not running using the default host and port values, edit the file and insert the correct host and port values, as follows:
datagrid.host=localhost datagrid.hotrod.port=11322
Navigate to the Root Directory
Open a command line and navigate to the root directory of this quickstart.
Build and Deploy the Application
Use the following command to build and deploy your application using Maven:
$ mvn clean package jboss-as:deploy -Premote-jbossas
16.6.3. View the CarMart Quickstart in Remote Client-Server Mode
The following procedure outlines how to view the CarMart quickstart in Red Hat JBoss Data Grid’s Remote Client-Server Mode:
Prerequisite
The CarMart quickstart must be built and deployed be viewed.
View the CarMart Quickstart in Remote Client-Server Mode
Visit the following link in a browser window to view the application:
http://localhost:8080/jboss-carmart
16.6.4. Remove the CarMart Quickstart in Remote Client-Server Mode
The following procedure provides directions to remove an already deployed application in Red Hat JBoss Data Grid’s Remote Client-Server mode.
Remove an Application in Remote Client-Server Mode
To remove an application, use the following command from the root directory of this quickstart:
$ mvn jboss-as:undeploy -Premote-jbossas
16.7. The (Non-Transactional) CarMart Quickstart in Remote Client-Server Mode (JBoss Enterprise Web Server)
16.7.1. The CarMart Quickstart in Remote Client-Server Mode (JBoss Enterprise Web Server)
The Carmart (non-transactional) quickstart is supported for JBoss Data Grid’s Remote Client-Server Mode with the JBoss Enterprise Web Server container.
16.7.2. Build and Deploy the CarMart Quickstart in Remote Client-Server Mode
This quickstart accesses Red Hat JBoss Data Grid via Hot Rod. This feature is not available for the Transactional CarMart quickstart.
This quickstart deploys to JBoss Enterprise Web Server or Tomcat. The application cannot be deployed to JBoss Data Grid because it does not support application deployment.
Prerequisites
Prerequisites for this procedure are as follows:
- Obtain the most recent supported JBoss Data Grid Remote Client-Server Mode distribution files from RedHat.
- Ensure that the JBoss Data Grid and JBoss Enterprise Application Platform Maven repositories are installed and configured. For details, see Install and Use the Maven Repositories
Add a
server
element to the Maven settings.xml file. In theid
elements withinserver
, add the appropriate tomcat credentials.<server> <id>tomcat</id> <username>admin</username> <password>admin</password> </server>
Build and Deploy the CarMart Quickstart in Remote Client-Server Mode
Configure the Standalone File
Add the following configuration to the standalone.xml file located in the $JDG_HOME/standalone/configuration/ directory.
Add the following configuration within the infinispan subsystem tags:
<local-cache name="carcache" statistics="true"> <eviction strategy="LIRS" max-entries="4"/> </local-cache>
注記If the
carcache
element already exists in your configuration, replace it with the provided configuration.
Start the Container
Start the JBoss server instance where your application will deploy.
For Linux:
$JBOSS_EWS_HOME/tomcat7/bin/catalina.sh run
For Windows:
$JBOSS_EWS_HOME\tomcat7\bin\catalina.bat run
Build the Application
Use the following command to build your application in the relevant directory:
$ mvn clean package -Premote-tomcat
Deploy the Application
Use the following command to deploy the application in the relevant directory:
mvn tomcat:deploy -Premote-tomcat
16.7.3. View the CarMart Quickstart in Remote Client-Server Mode
The following procedure outlines how to view the CarMart quickstart in Red Hat JBoss Data Grid’s Remote Client-Server Mode:
Prerequisite
The CarMart quickstart must be built and deployed be viewed.
View the CarMart Quickstart in Remote Client-Server Mode
Visit the following link in a browser window to view the application:
http://localhost:8080/jboss-carmart
16.7.4. Remove the CarMart Quickstart in Remote Client-Server Mode
The following procedure provides directions to remove an already deployed application in Red Hat JBoss Data Grid’s Remote Client-Server mode.
Remove an Application in Remote Client-Server Mode
To remove an application, use the following command from the root directory of this quickstart:
$ mvn tomcat:undeploy -Premote-tomcat
16.8. The (Transactional) CarMart Quickstart Using JBoss EAP
16.8.1. The CarMart Transactional Quickstart Using JBoss EAP
This CarMart Transactional quickstart requires JBoss Data Grid’s Library mode with the JBoss Enterprise Application Platform container.
All required libraries (jar files) are bundled with the application and deployed to the server. Caches are configured programmatically and run in the same JVM as the web application.
All operations are transactional and are configured at JBossASCacheContainerProvider
/TomcatCacheContainerProvider
implementation classes for the CacheContainerProvider
interface.
16.8.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.
16.8.3. Build and Deploy the Transactional CarMart Quickstart
Prerequisites
Ensure that the following prerequisites are met before building and deploying the CarMart quickstart.
- Configure Maven (See Quickstart Prerequisites)
Start JBoss Enterprise Application Platform:
- In a command line terminal, navigate to the root of the JBoss EAP server directory.
Use one of the following commands to start the server with a web profile:
For Linux:
$JBOSS_HOME/bin/standalone.sh
For Windows:
%JBOSS_HOME%\bin\standalone.bat
Build and Deploy the Transactional Quickstart
- Open a command line and navigate to the root directory of this quickstart.
Enter the following command to build and deploy the archive:
mvn clean package jboss-as:deploy
- The target/jboss-carmart-tx.war file is deployed to the running instance of the server.
16.8.4. View the Transactional CarMart Quickstart
The following procedure outlines how to view the CarMart quickstart:
Prerequisite
The CarMart quickstart must be built and deployed to be viewed.
View the CarMart Quickstart
To view the application, use your browser to navigate to the following link:
http://localhost:8080/jboss-carmart-tx
16.8.5. Undeploy The Transactional CarMart Quickstart
Undeploy the transactional CarMart quickstart as follows:
- In a command line terminal, navigate to the root directory of the quickstart.
Undeploy the archive as follows:
mvn jboss-as:undeploy
16.8.6. Test the Transactional CarMart Quickstart
The JBoss Data Grid quickstarts include Arquillian Selenium tests. To run these tests:
- Stop JBoss EAP, if it is running.
- In a command line terminal, navigate to root directory for the quickstart.
Build the quickstarts as follows:
mvn clean package
Run the tests as follows:
mvn test -Puitests-jbossas -Das7home=/path/to/server
16.9. The (Transactional) CarMart Quickstart Using JBoss Enterprise Web Server
16.9.1. The CarMart Transactional Quickstart Using JBoss Enterprise Web Server
This CarMart Transactional quickstart requires JBoss Data Grid’s Library mode with the JBoss Enterprise Web Server container.
All the required libraries (jar files) are bundled with the application and deployed to the server. Caches are configured programatically and run in the same JVM as the web application for this quickstart.
Additionally, all operations are transactional. The standalone transaction manager from JBoss Transactions is used to run the application in JBoss Enterprise Web Server.
Only the library-tomcat
profile can be used when running this quickstart with JBoss Enterprise Web Server because this profile enables library mode.
16.9.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.
16.9.3. Build and Deploy the Transactional CarMart Quickstart
Prerequisites
Ensure that the following prerequisites are met before building and deploying the CarMart quickstart.
- Configure Maven (See Quickstart Prerequisites)
To configure JBoss Enterprise Web Server, add the following lines to the conf/tomcat-users.xml file:
<role rolename="manager-script"/> <user username="admin" password="admin" roles="manager-script"/>
Configure Maven by adding the following configuration information to the Maven settings.xml file with the appropriate credentials:
<server> <id>tomcat</id> <username>admin</username> <password>admin</password> </server>
Start JBoss Enterprise Web Server:
- In a command line terminal, navigate to the root of the JBoss Enterprise Web Server directory.
Use one of the following commands to start the server with a web profile:
For Linux:
$TOMCAT_HOME/bin/catalina.sh run
For Windows:
%TOMCAT_HOME%\bin\catalina.bat run
Build and Deploy the Transactional CarMart Quickstart
- In a command line terminal, navigate to the root directory for the quickstart.
Enter the following command to build and deploy archive:
mvn -Plibrary-tomcat clean package tomcat:deploy
- The target/jboss-carmart-tx.war file is deployed to the running instance of JBoss Enterprise Web Server.
16.9.4. View the Transactional CarMart Quickstart
The following procedure outlines how to view the CarMart quickstart:
Prerequisite
The CarMart quickstart must be built and deployed to be viewed.
View the CarMart Quickstart
To view the application, use your browser to navigate to the following link:
http://localhost:8080/jboss-carmart-tx
16.9.5. Undeploy The Transactional CarMart Quickstart
Undeploy the transactional CarMart quickstart as follows:
- In a command line terminal, navigate to the root directory of the quickstart.
Undeploy the archive as follows:
mvn -Plibrary-tomcat tomcat:undeploy
16.9.6. Test the Transactional CarMart Quickstart
The JBoss Data Grid quickstarts include Arquillian Selenium tests. To run these tests:
- Undeploy the archive (see Undeploy the Transactional Carmart Quickstart)
- Stop JBoss Enterprise Web Server, if it is running.
- In a command line terminal, navigate to root directory for the quickstart.
Build the quickstarts as follows:
mvn clean package
Run the tests as follows:
mvn test -Puitests-jbossas -Das7home=/path/to/server