Home Programming Infinispan Data Grid Platform Definitive Guide

Infinispan Data Grid Platform Definitive Guide

books-svg-icon Book
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Getting Started
About this book
Publication date:
May 2015
Publisher
Packt
Pages
464
ISBN
9781782169970

 

Chapter 1. Getting Started

With the advent of Cloud technology, many paradigms started to change, like the way the industry tackles issues related data security and user privacy. Even the most conservative and traditional organizations have been forced to start adapting to this new technology, and are trying to use one of the many existent cloud platforms.

There are numerous benefits offered by cloud computing, both to end users and companies of all sizes and shapes. For small companies, they are a good option because it can minimize licensing software, and for big companies that want to expand their business, cloud computing can help improve accessibility without the need to spend too much money on hardware.

Moving to the field of data, a few years ago, managers and even developers assumed that nearly all data should be stored in a Relational Database Management System (RDBMS). Some years ago, it was unthinkable to run a production system that kept all of its data within memory, but now, due to the continuous decline in the prices of RAM, modern in-memory products are emerging such as big data analytics tools (in-memory computation) and in-memory data grids. One such in-memory data grid system is Infinispan.

Infinispan is an open source data grid platform distributed by JBoss, written in Java; it exposes a JSR-107 compatible cache interface in which you can store objects.

This first chapter launches you on a tour of this technology by focusing on fundamentals.

In this chapter, we will cover the following topics:

  • Introducing the Infinispan data grid

  • Infinispan and JSR 107 – Java Temporary Caching API

  • Getting started with Infinispan

  • Running the sample application

  • Creating your first project

  • Building Infinispan from source

  • Contributing to the project

 

Introducing the Infinispan data grid


Generally, data grids are considered an evolution of distributed caches. As the name implies, a distributed cache is characterized by the usage of multiple servers to host cached data, so that it can grow in size and in capacity. A distributed cache solution is mainly used to store temporary application data, such as web session data.

There are several benefits to using an in-memory data grid like Infinispan; a good and simple example is database offloading. Database offloading is the process of removing or reducing the database load, mainframes, and shared or partner services.

As mentioned in the introduction, Cloud platforms are also changing the way we store and distribute our data. A common solution adopted on cloud architectures is to expose the data through REST services.

In these cloud architectures, applications that expose the business data via REST services to clients normally decompose the system into layers, in order to separate the user interface from the business logic, as illustrated in the following image:

In the image, you can see how the data layer fits in a layered application. In our example, the data layer hides the implementation details to the database. We can consider that the database is a single repository of data, which is accessed at first by a few clients. However, that's the scenario if you're on a cloud environment, things can change fast.

From the performance point of view, retrieving data for every request from one single repository can be expensive, both in terms of time and hardware cost.

Also, you may need to provide access to your data for many clients' social media and mobile device integration, which can decrease the performance of your services, thereby impacting user experience.

This scenario can be a good example of offloading; in our scenario, we designed our database to provide a certain amount of data via REST services, which does not only impact the response time of the database request, but can also impact the whole infrastructure where the data is being transmitted.

Infinispan can work well in very demanding environments, as in this scenario. Thoughtful use of a distributed caching to offload the network and database can really improve performance. For instance, when a client makes a web method call to the service layer, which in turn performs several calls to the database, you could cache the query results in an Infinispan cache. Then, the next time this client needs to make the same Web method call, the service layer gets that data from the cache instead. This step can really improve overall performance because the application does not have to make an expensive database call. An Infinispan cache, in this scenario, can also reduce the pressure on the service layer, because data in an Infinispan cache can be distributed among all nodes of the cluster.

The following figure presents the same architecture as included in the first image, but now with an Infinispan cache:

At the same time, Infinispan can also power embedded applications, be used as a JPA/Hibernate second-level cache provider, or as a highly available key/value data store.

The scenario we presented previously is one of the two possible ways you can interact with Infinispan. We are using Infinispan in the embedded mode, which initiates the Infinispan data grid within the same JVM as the application.

The other way is the client/server mode, where you have an Infinispan data grid instance running in a separated server, which delivers and manages the grid content to be consumed by the client, including non-java clients, such as C++, Python, and .NET.

Tip

We will cover Infinispan Server in detail in Chapter 9, Server Modules.

Infinispan also provides an extremely low latency access to the cache, and high availability of the application data, by keeping the data in the memory and distributing it to several nodes of the grid, which makes your application able to load terabytes of data into memory. However, it not only provides a new attempt to use the main memory as a storage area instead of a disk, (Infinispan perform much faster than disk-based databases) but it also provides features such as:

  • Data partitioning across a cluster

  • Work with domain objects rather than only bytes, arrays, or strings

  • Synchronous and asynchronous operations throughout

  • Distributed ACID transactions

  • Data distribution through the use of a consistent hash algorithm to determine where keys should be located in the cluster

  • Write-through/behind cache store support

  • Eviction support

  • Elastic scaling

  • Multiple access protocols

  • Support for compute grids

  • Persisting state to configurable cache stores

We will cover all these features in detail throughout this chapter.

From a Java developer perspective, an Infinispan cache can be seen as a distributed key-value object store similar in its interface to a typical concurrent hash map, in a way that it can have any application domain object as either a value or a key.

 

Infinispan and JSR 107 – Java Temporary Caching API


The Java specification request 107 (JSR 107: JCACHE - Java Temporary Caching API) has been created to define a temporary caching API for the Java platform and presents a Map-like API. As in a regular java.util.Map, data is stored as values by keys.

Note

Java Specification Request (JSR) is a formal document that describes a proposal for a new feature or change in the Java Platform.

This process is defined by the Java Community Process (JCP), which is responsible for approving and developing the standard technical specifications for the Java technology.

Any organization or individual can sign up to become a JCP member and then participate on the expert group of a JSR or even submit their own JSR proposals.

With JCACHE, you can store and retrieve your objects, control how values expire from the cache, inspect the contents of the cache, and get statistics about the cache. JCACHE also provides support for optional runtime cache annotations, support for transactions, and listeners to add custom behavior when setting and deleting values.

The primary programming artifact is the javax.cache.Cache interface, with some modifications for distributed environments.

Infinispan exposes a JSR-107 compatible cache interface in which you can store data, and enhances it by providing additional APIs and features.

 

Getting started with Infinispan


Let's see how to get started in the easiest way using Infinispan in the embedded mode. If you haven't done so already, the first thing you'll need to do is install Infinispan. To do so, you have two options. You can download the latest release from the Infinispan website. At the time of this writing, the page to download Infinispan was located at http://infinispan.org/download/, but this might change. If it does, you can find its new location by searching for Infinispan using your favorite search engine.

The second option is if you are using Maven/Gradle. You can download the binaries from the JBoss.org Maven Repository, as we will see in the upcoming section.

Installing Infinispan

Installing Infinispan is straightforward. In-keeping with the tradition of many open source tools, there are no fancy installers. Just download the latest version (version 7.1 at the time of this writing) from the previously mentioned Infinispan website and extract the package into a directory of your choice. The Infinispan website looks like this:

Looking inside the box

Once you download the zip file and extract it, you will find the following folder structure:

In the root folder, in our example infinispan-7.1.1.Final-all.zip, you can find the following files:

  • The infinispan-embedded.jar file, which is the main library of the framework, contains everything you need to create a local or clustered cache. From Infinispan 7, this package includes all required dependencies such as the JGroups, JCache, and JBoss Marshalling classes. So you don't have to include these additional libraries in your classpath.

  • The infinispan-embedded-query.jar file, which you'll need to include in your application if you want to provide query capabilities to your cache.

  • The infinispan-cli.jar file, which you can execute using the ispn-cli.sh script to open a command-line interface. You can use this to interact with the data within the caches and some internal components.

Along with these JAR files, in the root folder, you will also find some README files and the following directories:

  • bin: This folder contains a few batch scripts to run different Infinispan demos, like the runEC2Demo** scripts file, whose purpose is to show how Infinispan can easily run on an Amazon EC2 instance. It also contains scripts to manage your data grid using different flavors of clients, such as a Ruby and Python REST client. The scripts are as follows:

    • A script to execute the command-line interface (ispn-cli.sh/bat)

    • A lucene directory demo (runLuceneDemo.sh)

    • runWordCountDemo.sh and runPiApproximationDemo.sh for a Map/Reduce task computation

    • And finally, a runGuiDemo.sh/.bat script, which opens a nice swing app that starts Infinispan in a standalone JVM process that you can use to test your settings and your installation

  • configs: This folder contains some sample configuration files. The config-samples/sample.xml file contains some configuration examples on how to use different features of Infinispan, such as transactions and cache loaders and you can find several examples of different cache configurations for different setups. The distributed-udp.xml file creates a cache that uses UDP as a transport protocol and distributed-ec2.xml for Amazon environments, both via JGroups.

    Note

    We are going to read more about JGroups in Chapter 11, An Introduction to JGroups.

  • demos: This contains the JAR and WAR files for the sample applications.

  • docs: The distribution comes with a rich API documentation, which contains the Javadoc files for the API (api folder) and some HTML pages that describe the configuration schemas.

It also provides an index.html page with a link to the above-mentioned javadoc and configuration schemas for configuration files, and a link to an HTML document that describes the available JMX MBeans exposed by Infinispan.

You will learn more about configuring Infinispan in Chapter 3, Using the APIs.

The other folders present are as follows:

  • lib: This folder contains all the dependencies including the libraries used by the modules.

  • licenses: The licenses directory contains the licenses for some of the other libraries shipped with the distributions that are not covered by the LGPL-2.1 license.

    All dependencies of Infinispan are available under the LGPL or a compatible license (such as the Apache License 2); a full dependency report can be found in every Infinispan JAR.

  • modules: This directory contains a number of optional modules, such as the Infinispan spring, Infinispan tree, and the REST module that allows you to extend Infinispan functionalities.

  • rhq-plugin: Infinispan provides a plugin if you are monitoring your systems with JBoss RHQ. You can read more about monitoring Infinispan in Chapter 8, Managing and Monitoring Infinispan.

  • schema: This folder contains the XML schemas for the Infinispan configuration files, such as the infinispan-config-7.1.xsd and infinispan-spring-7.1.xsd files and several infinispan-cachestore-*.xml files to be used in different cache store configuration.

If you wish to use one or more of these modules, you will also need the module's jar file and all of its dependencies (listed in the corresponding runtime-classpath.txt file) to be on your classpath.

Using Maven

If you're a Maven user, Infinispan builds are also published to the JBoss.org Maven repository, which allows you to access the Infinispan builds with Apache Maven, Apache Ivy, or Apache Ant with Maven Ant Tasks. To accomplish this task, perform the following steps:

  1. You have to include the following Infinispan dependency to your project's pom.xml:

    <dependency>
        <groupId>org.infinispan</groupId>
        <artifactId>infinispan-core</artifactId>
        <version>${infinispan.version}</version>
    </dependency>
  2. It's optional, but if you want, it's recommended that you enable the JBoss Repository, so that you can import the dependencies directly from the jboss.org repository. To configure, add the following profile configuration to your Maven settings, located in your .m2 directory, giving the new repository its own ID and URL, making modifications to the settings.xml file:

    <profiles>
      <profile>
        <!-- Repository is active unless explicitly disabled e.g. -P!jboss-public-repository -->
        <activation>
          <property>
            <name>jboss-public-repository</name>
            <value>!false</value>
          </property>
        </activation>
        <repositories>
          <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
            <layout>default</layout>
            <releases>
              <enabled>true</enabled>
              <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
              <enabled>false</enabled>
              <updatePolicy>never</updatePolicy>
            </snapshots>
          </repository>
        </repositories>
        <pluginRepositories>
          <pluginRepository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>http://repository.jboss.org/nexus/content/groups/public</url>
            <layout>default</layout>
            <releases>
              <enabled>true</enabled>
              <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
              <enabled>true</enabled>
              <updatePolicy>never</updatePolicy>
            </snapshots>
          </pluginRepository>
        </pluginRepositories>
      </profile>
    </profiles>

    This piece of configuration in your pom.xml file will be active by default during the build process and will add the JBoss Repository to a profile. With this profile activated, Maven will be able to download dependencies from the JBoss repository during the build.

    Tip

    If, for some reason, you want to disable the JBoss Repository, you can use the maven command line tool to deactivate this profile for a specific build, using the maven standard command:

    mvn –P!jboss-public-repository install
    
  3. If you want to know more details about how to customize the Maven settings, take a look at the Maven Settings Reference at http://maven.apache.org/settings.html.

 

Running the sample application


To get a feel of how Infinispan looks, we are going to execute a Swing GUI demo that ships with Infinispan and can be used to test its basic caching functionalities, either as a standalone server or as a clustered server.

It's a good way to test our environment without the need to write a single line of code. Perform the following steps:

  1. First, open the bin folder and execute the runGuiDemo.sh script (adjust to runGuiDemo.bat if you are using a windows development environment) by executing the following command:

    ./runGuiDemo.sh
    
  2. If everything went well, the following screen should be displayed:

  3. To start the cache, press the Start Cache button, which will instantiate a cache:

    Note that the GUI Demo highlights the path to the configuration file used for initialization and presents its content in the text area.

    This demo application provides a very useful way to quickly test your own configuration files; to do so, execute the script passing your configuration's file directory as a JVM parameter beginning with the file protocol:

    ./runGuiDemo.sh file:/devenv/infinispan/configs/config-samples/sample.xml
    
  4. The most attentive readers will probably notice that now the toolbar is activated. Move to the Manipulate data tab; in this tab, you can perform CRUD operations on the cache, including a button to generate from 1 to 1000 random entries in the cache.

    Note

    CRUD is a well-known acronym that stands for Create, Read, Update, and Delete

  5. In the following example, we will add a sample entry in the cache by filling the Key and Value textboxes and hitting the Go button, which is shown in the following screenshot;

    Note

    Option Lifespan (millis) sets the lifespan of the cache entry, in milliseconds.

    MaxIdle (millis) sets the max idle of the cache entry, also in milliseconds.

    All these parameters can be set in the configuration.xml file.

  6. Once added, the application will switch automatically to the Data view tab, which will display all entries contained in the cache, as shown in the following screenshot:

  7. To test the cluster capabilities of Infinispan, let's open another command prompt and repeat the steps above, only changing the values in step 4. In both applications, move to the Data view tab, as shown in the following screenshot:

    You can see that both applications now have the same data.

    Note

    If one of the applications shows different values, hit the Refresh view button.

    Invoking the runGuiDemo script a few more times will create GUI frames, and you'll be able to start a new cache instance in each JVMs.

  8. Finally, in both applications, move to the Cluster view tab, as shown in the following screenshot:

As you can see, despite the fact that the GUI Demo applications are running in the same environment, they are running on different JVMs and we can see that the caches have discovered each other and formed a cluster.

 

Creating your first project


To create our first Infinispan project we are going to use Eclipse with a specific Maven archetype to create the skeleton of our project.

Tip

Maven provides a useful mechanism called Maven Archetypes that you can use to define a template for project creation; the archetype can create the skeleton of a project with the right structure and dependencies.

Infinispan currently provides two archetypes that we can use to create a skeleton project, which includes everything you need to start to use Infinispan. The archetype also generates a sample code and a pom.xml file with all required dependencies.

To create an Infinispan project using the Maven template inside Eclipse, you will have to add the Infinispan archetype. To do so perform the following steps:

  1. Navigate to File | New | Project. In the dialog box that opens, select the existing Maven projects option inside the Maven folder.

  2. Select your project location and press the Next button in the dialog that will appear.

  3. On the screen that comes up next, hit the Add Archetype button, as shown in the following screenshot:

  4. A new dialog box will appear asking you to add the new Archetype; include the information for the new project archetype, as in the following screenshot and press OK:

  5. The new archetype should now be available in the list. Select it and confirm by pressing the Next button, as shown in the following screenshot;

  6. You will be prompted to enter some information to create the project; in this example, enter the Group ID (com.packtpub) and the Artifact ID (infinispan-sample), for the rest, keep the default values as they are.

  7. You should then be taken back to the Project Explorer where you can see your new project created.

  8. The first thing to notice is the pom.xml file, which includes the necessary dependencies, such as the infinispan-embedded module (see the following code), which provides the basic functionalities:

       <dependencies>
          <dependency>
             <groupId>org.infinispan</groupId>
             <artifactId>infinispan-embedded</artifactId>
             <version>${version.infinispan}</version>
          </dependency>
       </dependencies>

    This also includes plugins to enforce the correct versions of Java and Maven, the JBoss public repository configuration, and a profile to run the sample application created.

  9. In the structure of the project, you can find two classes for the sample application: SampleCacheContainer.java and Application.java. The SampleCacheContainer class contains all the logic to create and configure an embedded cache manager. The sample application ships with four different Infinispan files, to test different configurations.

  10. The Application class is responsible for actually starting the program, and it executes four distinct operations. This example is demonstrated as follows:

    • It presents a simple example of how to use Infinispan API, the cache stores and replaces arbitrary strings.

    • This demonstrates how you can use Infinispan to store an entry with a lifespan.

    • This demonstrates asynchronous operations, where writes can be done in a non-blocking fashion.

    • This demonstrates how to register listeners.

    Note

    All features presented in this demo will be explained in the upcoming chapters.

  11. The following code is an extract from the main method Application class:

       public static void main(String[] args) throws Exception {
          System.out.println("\n\n\n   ********************************  \n\n\n");
          System.out.println("Hello.  This is a sample application making use of Infinispan.");
          Application a = new Application();
          a.basicUse();
          a.lifespans();
          a.asyncOperations();
          a.registeringListeners();
          System.out.println("Sample complete.");
          System.out.println("\n\n\n   ********************************  \n\n\n");
       }
  12. Examine the source code to figure out what its doing and execute the Application class. The Application class will execute and print the four operations on your prompt, which is shown in the following screenshot:

Creating a Maven project manually

You have also the option to create an Infinispan manually using the same archetype that was used before. To do so, perform the following steps:

  1. To create a new project manually, open a terminal prompt and navigate to the directory you want to create the project then type the following command:

    mvn archetype:generate \
        -DarchetypeGroupId=org.infinispan.archetypes \
        -DarchetypeArtifactId=newproject-archetype \
        -DarchetypeVersion=1.0.14 \
        -DarchetypeRepository=http://repository.jboss.org/nexus/content/groups/public
  2. To execute the application, type the following command in the same folder you created the project in:

    mvn install –Prun
    

That's all! The application will execute and print the four operations on your prompt.

 

Building Infinispan from source


Infinispan uses Maven as a build tool. The following steps describe the sequence of tasks to build Infinispan from the source code:

  1. You will need a copy of the Infinispan sources, which can be downloaded from Github, but it's important to note that the git version of Infinispan might contain unreleased and unstable changes, it's intended for developers and contributors.

  2. To get the source from Github, first of all, you must have a git client to clone the repository. To clone the Infinispan from Github, you can execute the following command:

    git clone https://github.com/infinispan/infinispan.git
    
  3. If everything went well, you should see a new folder called Infinispan with the following folder structure:

  4. But first, since Infinispan is a very big multi-modular project, we will probably run into an OutOfMemoryError exception when building it. To prevent the error, we must instruct Maven to use more memory by setting the MAVEN_OPTS environment variable to increase the memory of the JVM executing the following command:

    export MAVEN_OPTS='-Xmx512m -XX:MaxPermSize=128m'
    
  5. On Windows, use:

    set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=128m
    
  6. Now, we can finally build Infinispan using the following command:

    mvn clean package install -DskipTests
    

This command will first clean out any old build and binary and then it will package the module as a JAR file, and insert them into the target folder.

The DskipTests parameter will prevent the unit tests from being run and finally, the install command installs the artifacts in your local repo for use by other projects/modules, including inter-module dependencies within the same project.

The next step is to open the source code with your preferred IDE that provides basic support to Apache Maven such as Eclipse, IntelliJ IDEA, and Netbeans.

Here, we are going to present how to setup IntelliJ IDEA.

Setting up the environment

Assuming that you have downloaded and compiled the source code, let's import the Infinispan project to IntelliJ IDE. Perform the following steps:

  1. If no project is currently open in your IntelliJ (I'm using IntelliJ IDEA 14.0.3), click on Import Project and change the directory to the location where you cloned Infinispan.

  2. Automatically, IntelliJ will detect the pom.xml file in the infinispan root folder and import the Maven project. Select all the projects you want to import and press Next.

  3. At the end of the import process, IntelliJ will open all projects, as you can see in the following image:

  4. Before starting to code, on IntelliJ, you will need to set up a specific feature introduced in Infinispan 5, which uses annotation processing as part of the compilation, to allow log messages to be internationalized. To change IntelliJ, open the Preferences window and go to Compiler | Annotation Processor and select the Enable annotation processing option. In the Annotation Processors option, add a new Processor FQ Name by pressing the plus button and insert org.jboss.logging.LoggingToolsProcessor.

  5. Infinispan also requires the IntelliJ Scala plugin to work. To install the plugin, open the Preferences window, go the Plugins option, and click in the Browse Repositories button. In the Browse Repositories pane, search for the Scala plugin and click on Install plugin.

  6. You will need to restart the IDE for the plugin installation to take effect.

    Tip

    You can also download the code style file used by the Infinispan team and import it into IntelliJ IDEA. To download the JAR file, click on the following link:

    https://github.com/infinispan/infinispan/blob/master/ide-settings/intellij/IntelliJ_IDEA_Code_Style.jar?raw=true

 

Contributing to the project


What do people such as Linus Torvalds, Ward Cunningham, and Richard Stallman all have in common?

If you are just a little interested in software development, you may have heard about one of them. Even if you haven't heard of them, surely you are very likely to know about some of their creations: Linux, Wiki, and the GNU System.

They are all famous and successful software developers and all of them contribute to open source software. So what? You might be thinking, "Why should I contribute to open source software (OSS) projects?"

If you followed the last step and downloaded the source code, open it on IntelliJ or in your favorite IDE, I would like to share two important thoughts on this and maybe inspire you to participate, which are as follows:

  • It's a great opportunity to learn and collaborate with really smart people and experts of the open source community you want to join

  • It's also the best way to improve your resume; today more and more employers of developers are looking towards community contributors, blog writers, discussion lists, and committers on an OSS project

There are probably many software developers that would like to start contributing but don't know where to start. If you develop software for a while using open source projects, you'll probably face a bug and maybe have to fix it, whether you are a member of the project or not.

If you could fix a bug, why not make that your contribution? Now, try the following steps:

  1. Download and build the source code.

  2. Join the discussion list.

  3. See how the Issue Management Tool works and ask for access.

  4. Find a bug. You can find your own bug or access the Issue Management Tool and pick one.

  5. Reproduce the error in your environment.

  6. Create unit tests and fix the bug.

  7. Make and submit the patch.

  8. Communicate with other developers.

  9. Welcome to the team!

    Note

    For more information about how to contribute to Infinispan, please click on the following link:

    http://infinispan.org/docs/7.0.x/contributing/contributing.html

 

Summary


In this chapter, we've taken an introductory look at Infinispan's defining characteristics and major features.

At this point, you have the source code ready to go and a new sample project created and running. You should also probably be thinking about how to spend some time contributing to open source software.

You've worked with the Infinispan GUI demo to insert and retrieve some data, and you're ready to take a step back and get the big picture on Infinispan before really diving into the details.

In the next chapter, you will discover common approaches used to overcome obstacles, such as performance, scalability, and high availability. It also covers how these solutions can be improved using Infinispan.

Infinispan Data Grid Platform Definitive Guide
Unlock this book and the full library FREE for 7 days
Start now