What is it?
Memcached is an in-memory caching system used to improve response and operation times for database-driver websites. JBoss Data Grid offers a server that uses the text based, client-server Memcached protocol, removing the necessity to use Memcached separately with JBoss Data Grid. Additionally, due to JBoss Data Grid's clustering features, its data failover capabilities surpass those provided by Memcached.
This quickstart demonstrates how to connect remotely to JBoss Data Grid (JDG) to store, retrieve, and remove data from cache using the Memcached protocol. It is a simple Football Manager console application allows you to add and remove teams, add players to or remove players from teams, or print a list of the current teams and players using the memcached based connector.
All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
The application this project produces is designed to be run on JBoss Data Grid 6.0
If you have not yet done so, you must Configure Maven before testing the quickstarts.
Obtain JDG server distribution on Red Hat's Customer Portal at https://access.redhat.com/jbossnetwork/restricted/listSoftware.html
Install a JDBC driver into JDG (since JDG includes H2 by default, this step may be skipped for the scope of this example). More information can be found in the DataSource Management chapter of the Administration and Configuration Guide for JBoss Enterprise Application Platform on the Customer Portal at https://access.redhat.com/site/documentation/JBoss_Enterprise_Application_Platform/ . NOTE: JDG does not support deploying applications so one cannot install it as a deployment.
This Quickstart uses JDBC to store the cache. To permit this, it's necessary to alter JDG configuration file (
JDG_HOME/standalone/configuration/standalone.xml) to contain the following definitions:
Datasource subsystem definition:
<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>
Infinispan subsystem definition:
<subsystem xmlns="urn:infinispan:server:core:5.2" default-cache-container="local"> <cache-container name="local" default-cache="default"> <local-cache name="default" start="EAGER"> <locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/> <transaction mode="NONE"/> </local-cache> <local-cache name="memcachedCache" start="EAGER"> <locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/> <transaction mode="NONE"/> </local-cache> <local-cache name="namedCache" start="EAGER"/> <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>
Start JBoss Data Grid 6
- Open a command line and navigate to the root of the JBoss Data Grid directory.
The following shows the command line to start the server with the web profile:
For Linux: JDG_HOME/bin/standalone.sh For Windows: JDG_HOME\bin\standalone.bat
Build and Run the Quickstart
NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See Build and Deploy the Quickstarts for complete instructions and additional options.
- Make sure you have started the JBoss Server as described above.
- Open a command line and navigate to the root directory of this quickstart.
Type this command to build and deploy the archive:
mvn clean package
This will create a file at
Run the example application in its directory:
Using the application
Basic usage scenarios can look like this (keyboard shortcuts will be shown to you upon start):
at - add a team ap - add a player to a team rt - remove a team rp - remove a player from a team p - print all teams and players q - quit
q one more time to exit the application.
Debug the Application
If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc
Find this guide useful?
FeedbackFind a bug in the guide? Something missing? You can fix it by [forking the repository](http://github.com/jboss-jdf/jboss-as-quickstart), making the correction and [sending a pull request](http://help.github.com/send-pull-requests). If you're just plain stuck, feel free to ask a question in the [user discussion forum](http://jboss.org/jdf/forums/jdf-users).
- Nov 20, 2013: Not yet committed You