Book Image

Infinispan data grid platform definitive guide

Book Image

Infinispan data grid platform definitive guide

Overview of this book

Table of Contents (20 chapters)
Infinispan Data Grid Platform Definitive Guide
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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.