<?xml version="1.0" encoding="UTF-8"?>
<!-- This document was created with Syntext Serna Free. -->
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<section id="ISPN.integration">
  <title>Infinispan integration</title>

  <para>eXo JCR can rely on distributed cache such as Infinispan. This article
  describes the required configuration.</para>

  <section id="ISPN.integration.ComponentsConfigurationRequirement">
    <title>Components configuration requirements</title>

    <programlisting>&lt;component&gt;
    &lt;key&gt;org.infinispan.transaction.lookup.TransactionManagerLookup&lt;/key&gt;
    &lt;type&gt;org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup&lt;/type&gt;
&lt;/component&gt;

&lt;component profiles="ispn"&gt;
    &lt;key&gt;org.exoplatform.services.transaction.TransactionService&lt;/key&gt;
    &lt;type&gt;org.exoplatform.services.transaction.infinispan.JBossTransactionsService&lt;/type&gt;
    &lt;init-params&gt;
        &lt;value-param&gt;
            &lt;name&gt;timeout&lt;/name&gt;
            &lt;value&gt;3000&lt;/value&gt;
        &lt;/value-param&gt;
    &lt;/init-params&gt;
&lt;/component&gt;

&lt;component profiles="ispn"&gt;
    &lt;key&gt;org.exoplatform.services.rpc.RPCService&lt;/key&gt;
    &lt;type&gt;org.exoplatform.services.rpc.jgv3.RPCServiceImpl&lt;/type&gt;
    &lt;init-params&gt;
        &lt;value-param&gt;
            &lt;name&gt;jgroups-configuration&lt;/name&gt;
            &lt;value&gt;jar:/conf/udp-mux-v3.xml&lt;/value&gt;
        &lt;/value-param&gt;
        &lt;value-param&gt;
            &lt;name&gt;jgroups-cluster-name&lt;/name&gt;
            &lt;value&gt;RPCService-Cluster&lt;/value&gt;
        &lt;/value-param&gt;
        &lt;value-param&gt;
            &lt;name&gt;jgroups-default-timeout&lt;/name&gt;
            &lt;value&gt;0&lt;/value&gt;
        &lt;/value-param&gt;
    &lt;/init-params&gt;
&lt;/component&gt;
</programlisting>
  </section>

  <section id="ISPN.integration.WorkspacesConfigurationRequirements">
    <title>Workspaces configuration requirements</title>

    <para>Each mentioned below components uses instances of Infinispan Cache
    product for caching in clustered environment. So every element has it's
    own transport and has to be configured in a proper way. As usual,
    workspaces have similar configuration. The simplest way to configure them
    is to define their own configuration files for each component in each
    workspace. There are several commons parameters. <abbrev></abbrev></para>

    <para><abbrev>"infinispan-configuration"</abbrev> defines path to template
    based configuration for Infinispan Cache instance.</para>

    <para>JGroups is used by Infinispan Cache for network communications and
    transport in a clustered environment. If property
    <abbrev>"jgroups-configuration"</abbrev> is defined in component
    configuration, it will be injected into the Infinispan Cache instance on
    startup.</para>

    <para>The another parameter is <abbrev>"infinispan-cluster-name".</abbrev>
    This defines the name of the cluster. Needs to be the same for all nodes
    in a cluster in order to find each other.</para>

    <itemizedlist>
      <listitem>
        <para>Cache configuration:</para>

        <programlisting language="xml">&lt;cache enabled="true" class="org.exoplatform.services.jcr.impl.dataflow.persistent.infinispan.ISPNCacheWorkspaceStorageCache"&gt;
    &lt;properties&gt;
        &lt;property name="infinispan-configuration" value="jar:/conf/portal/cluster/infinispan-data.xml" /&gt;
        &lt;property name="jgroups-configuration" value="jar:/conf/udp-mux-v3.xml" /&gt;
        &lt;property name="infinispan-cluster-name" value="JCR-cluster" /&gt;
    &lt;/properties&gt;
&lt;/cache&gt;</programlisting>
      </listitem>

      <listitem>
        <para>Indexer configuration</para>

        <programlisting language="xml">&lt;query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex"&gt;
    &lt;properties&gt;
        &lt;property name="index-dir" value="${exo.jcr.parent.dir:..}/temp/jcrlucenedb/production" /&gt;
        &lt;property name="changesfilter-class" value="org.exoplatform.services.jcr.impl.core.query.ispn.ISPNIndexChangesFilter" /&gt;
        &lt;property name="infinispan-configuration" value="jar:/conf/portal/cluster/infinispan-indexer.xml" /&gt;
        &lt;property name="jgroups-configuration" value="jar:/conf/udp-mux-v3.xml" /&gt;
        &lt;property name="infinispan-cluster-name" value="JCR-cluster" /&gt;
        &lt;property name="max-volatile-time" value="60" /&gt;
    &lt;/properties&gt;
&lt;/query-handler&gt;</programlisting>

        <itemizedlist>
          <listitem>
            <para><abbrev>changesfilter-class</abbrev> - defines cluster-ready
            index strategy based on Infinispan Cache, it can be either
            <classname>org.exoplatform.services.jcr.impl.core.query.ispn.ISPNIndexChangesFilter</classname>
            (for shared index) or
            <classname>org.exoplatform.services.jcr.impl.core.query.ispn.LocalIndexChangesFilter</classname>
            (for local index)</para>
          </listitem>
        </itemizedlist>
      </listitem>

      <listitem>
        <para>Lock Manager configuration</para>

        <programlisting language="xml">&lt;lock-manager class="org.exoplatform.services.jcr.impl.core.lock.infinispan.ISPNCacheableLockManagerImpl"&gt;
    &lt;properties&gt;
        &lt;property name="time-out" value="15m" /&gt;
        &lt;property name="infinispan-configuration" value="jar:/conf/portal/cluster/infinispan-lock.xml" /&gt;
        &lt;property name="jgroups-configuration" value="jar:/conf/udp-mux-v3.xml" /&gt;
        &lt;property name="infinispan-cluster-name" value="JCR-cluster" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.table.name" value="lk" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.table.create" value="true" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.table.drop" value="false" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.id.column" value="id" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.data.column" value="data" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.timestamp.column" value="timestamp" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.datasource" value="jdbcjcr" /&gt;
        &lt;property name="infinispan-cl-cache.jdbc.connectionFactory" value="org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory" /&gt;
    &lt;/properties&gt;
&lt;/lock-manager&gt;^
</programlisting>

        <itemizedlist>
          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.table.name</abbrev> - table
            name</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.table.create</abbrev> - is
            true or false. Indicates whether to create table at start phase.
            If true, the table is created if it does not already exist.</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.table.drop</abbrev> - is
            true or false. Indicates whether to drop the table at stop
            phase.</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.id.column</abbrev> - id
            column name</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.data.column</abbrev> - data
            column name</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.timestamp.column</abbrev> -
            timestamp column name</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.datasource</abbrev> - name
            of the datasource to use to store locks.</para>
          </listitem>

          <listitem>
            <para><abbrev>infinispan-cl-cache.jdbc.connectionFactory</abbrev>
            - connection factory to use with the JDBC Cache Store.</para>
          </listitem>
        </itemizedlist>
      </listitem>
    </itemizedlist>
  </section>

  <section id="ISPN.integration.ShippedInfinispanCacheConfigurationTemplates">
    <title>Shipped Infinispan Cache configuration templates</title>

    <para>eXo JCR implementation is shipped with ready-to-use Infinispan Cache
    configuration templates for JCR's components.</para>

    <section id="ISPN.integration.ShippedInfinispanCacheConfigurationTemplates.DataContainerTemplate">
      <title>Data container template</title>

      <para>Data container template is "infinispan-data.xml":</para>

      <programlisting>&lt;infinispan 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". 
      xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd". 
      xmlns="urn:infinispan:config:5.1"&gt;

    &lt;global&gt;
      &lt;evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory"&gt;
        &lt;properties&gt;
          &lt;property name="threadNamePrefix" value="EvictionThread"/&gt;
        &lt;/properties&gt;
      &lt;/evictionScheduledExecutor&gt;

      &lt;globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/&gt;

      &lt;transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout=
        &lt;properties&gt;
          &lt;property name="configurationFile" value="${jgroups-configuration}"/&gt;
        &lt;/properties&gt;
      &lt;/transport&gt;
    &lt;/global&gt;

    &lt;default&gt;
      &lt;clustering mode="replication"&gt;
        &lt;stateTransfer timeout="20000" fetchInMemoryState="false" /&gt;
        &lt;sync replTimeout="20000"/&gt;
      &lt;/clustering&gt;

      &lt;locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="true"/&gt;
      &lt;transaction transactionManagerLookupClass="org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup" syncRollbackPhase="true" s
      &lt;jmxStatistics enabled="true"/&gt;
      &lt;eviction strategy="LRU" threadPolicy="DEFAULT" maxEntries="1000000"/&gt;
      &lt;expiration wakeUpInterval="5000"/&gt;
   &lt;/default&gt;
&lt;/infinispan&gt;</programlisting>

      <table>
        <title>Template variables</title>

        <tgroup cols="2">
          <thead>
            <row>
              <entry align="center">Variable</entry>

              <entry align="center">Description</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry>jgroups-configuration</entry>

              <entry>This is the path to JGroups configuration that should not
              be anymore jgroups' stack definitions but a normal jgroups
              configuration format with the shared transport configured by
              simply setting the jgroups property singleton_name to a unique
              name (it must remain unique from one portal container to
              another). This file is also pre-bundled with templates and is
              recommended for use.</entry>
            </row>

            <row>
              <entry>infinispan-cluster-name</entry>

              <entry>This defines the name of the cluster. Needs to be the
              same for all nodes in a cluster in order to find each
              other.</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
    </section>

    <section id="ISPN.integration.ShippedInfinispanCacheConfigurationTemplates.LockManagerTemplate">
      <title>Lock manager template</title>

      <para>Its template name is "infinispan-lock.xml"</para>

      <programlisting language="xml">&lt;infinispan 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". 
      xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd". 
      xmlns="urn:infinispan:config:5.1"&gt;

    &lt;global&gt;
      &lt;evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory"&gt;
        &lt;properties&gt;
          &lt;property name="threadNamePrefix" value="EvictionThread"/&gt;
        &lt;/properties&gt;
      &lt;/evictionScheduledExecutor&gt;

      &lt;globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/&gt;

      &lt;transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout=
        &lt;properties&gt;
          &lt;property name="configurationFile" value="${jgroups-configuration}"/&gt;
        &lt;/properties&gt;
      &lt;/transport&gt;
    &lt;/global&gt;

    &lt;default&gt;
      &lt;clustering mode="replication"&gt;
        &lt;stateTransfer timeout="20000" fetchInMemoryState="false" /&gt;
        &lt;sync replTimeout="20000"/&gt;
      &lt;/clustering&gt;

      &lt;locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="false"/&gt;
      &lt;transaction transactionManagerLookupClass="org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup" syncRollbackPhase="true" s
      &lt;jmxStatistics enabled="true"/&gt;
      &lt;eviction strategy="NONE"/&gt;

      &lt;loaders passivation="false" shared="true" preload="true"&gt;
        &lt;loader class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" fetchPersistentState="true" ignoreModifications="false" purgeOnStar
          &lt;properties&gt;
             &lt;property name="stringsTableNamePrefix" value="${infinispan-cl-cache.jdbc.table.name}"/&gt;
             &lt;property name="idColumnName" value="${infinispan-cl-cache.jdbc.id.column}"/&gt;
             &lt;property name="dataColumnName" value="${infinispan-cl-cache.jdbc.data.column}"/&gt;
             &lt;property name="timestampColumnName" value="${infinispan-cl-cache.jdbc.timestamp.column}"/&gt;
             &lt;property name="idColumnType" value="${infinispan-cl-cache.jdbc.id.type}"/&gt;
             &lt;property name="dataColumnType" value="${infinispan-cl-cache.jdbc.data.type}"/&gt;
             &lt;property name="timestampColumnType" value="${infinispan-cl-cache.jdbc.timestamp.type}"/&gt;
             &lt;property name="dropTableOnExit" value="${infinispan-cl-cache.jdbc.table.drop}"/&gt;
             &lt;property name="createTableOnStart" value="${infinispan-cl-cache.jdbc.table.create}"/&gt;
             &lt;property name="connectionFactoryClass" value="${infinispan-cl-cache.jdbc.connectionFactory}"/&gt;
             &lt;property name="datasourceJndiLocation" value="${infinispan-cl-cache.jdbc.datasource}"/&gt;
          &lt;/properties&gt;
          &lt;async enabled="false"/&gt;
        &lt;/loader&gt;
      &lt;/loaders&gt;
   &lt;/default&gt;

&lt;/infinispan&gt;
</programlisting>

      <table>
        <title>Template variables</title>

        <tgroup cols="2">
          <thead>
            <row>
              <entry align="center">Variable</entry>

              <entry align="center">Description</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry>jgroups-configuration</entry>

              <entry>This is the path to JGroups configuration that should not
              be anymore jgroups' stack definitions but a normal jgroups
              configuration format with the shared transport configured by
              simply setting the jgroups property singleton_name to a unique
              name (it must remain unique from one portal container to
              another). This file is also pre-bundled with templates and is
              recommended for use.</entry>
            </row>

            <row>
              <entry>infinispan-cluster-name</entry>

              <entry>This defines the name of the cluster. Needs to be the
              same for all nodes in a cluster in order to find each
              other.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.table.name</entry>

              <entry>The table name.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.id.column</entry>

              <entry>The name of the column id.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.data.column</entry>

              <entry>The name of the column data.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.timestamp.column</entry>

              <entry>The name of the column timestamp.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.id.type</entry>

              <entry>The type of the column id.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.data.type</entry>

              <entry>The type of the column data.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.timestamp.type</entry>

              <entry>The type of the column timestamp.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.table.drop</entry>

              <entry>Can be set to true or false. Indicates whether to drop
              the table at stop phase.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.table.create</entry>

              <entry>Can be set to true or false. Indicates whether to create
              table at start phase. If true, the table is created if it does
              not already exist.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.connectionFactory</entry>

              <entry>The connection factory to use with the JDBC Cache
              Store.</entry>
            </row>

            <row>
              <entry>infinispan-cl-cache.jdbc.datasource</entry>

              <entry>The name of the datasource to use to store locks.</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
    </section>

    <section id="ISPN.integration.ShippedInfinispanCacheConfigurationTemplates.QueryHandlerTemplate">
      <title>Query handler (indexer) template</title>

      <para>Have a look at "infinispan-indexer.xml"</para>

      <programlisting>&lt;infinispan 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". 
      xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd". 
      xmlns="urn:infinispan:config:5.1"&gt;

    &lt;global&gt;
      &lt;evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory"&gt;
        &lt;properties&gt;
          &lt;property name="threadNamePrefix" value="EvictionThread"/&gt;
        &lt;/properties&gt;
      &lt;/evictionScheduledExecutor&gt;

      &lt;globalJmxStatistics jmxDomain="exo" enabled="true" allowDuplicateDomains="true"/&gt;

      &lt;transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout=
        &lt;properties&gt;
          &lt;property name="configurationFile" value="${jgroups-configuration}"/&gt;
        &lt;/properties&gt;
      &lt;/transport&gt;
    &lt;/global&gt;

    &lt;default&gt;
      &lt;clustering mode="replication"&gt;
        &lt;stateTransfer timeout="20000" fetchInMemoryState="false" /&gt;
        &lt;sync replTimeout="20000"/&gt;
      &lt;/clustering&gt;

      &lt;locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500" useLockStriping="false"/&gt;
      &lt;transaction transactionManagerLookupClass="org.exoplatform.services.transaction.infinispan.JBossStandaloneJTAManagerLookup" syncRollbackPhase="true" s
      &lt;jmxStatistics enabled="true"/&gt;
      &lt;eviction strategy="NONE"/&gt;

      &lt;loaders passivation="false" shared="false" preload="false"&gt;
        &lt;loader class="${infinispan-cachestore-classname}" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false"&gt;
          &lt;async enabled="false"/&gt;
        &lt;/loader&gt;
      &lt;/loaders&gt;
   &lt;/default&gt;
&lt;/infinispan&gt;
</programlisting>

      <table>
        <title>Template variables</title>

        <tgroup cols="2">
          <thead>
            <row>
              <entry align="center">Variable</entry>

              <entry align="center">Description</entry>
            </row>
          </thead>

          <tbody>
            <row>
              <entry>jgroups-configuration</entry>

              <entry>This is the path to JGroups configuration that should not
              be anymore jgroups' stack definitions but a normal jgroups
              configuration format with the shared transport configured by
              simply setting the jgroups property singleton_name to a unique
              name (it must remain unique from one portal container to
              another). This file is also pre-bundled with templates and is
              recommended for use.</entry>
            </row>

            <row>
              <entry>infinispan-cluster-name</entry>

              <entry>This defines the name of the cluster. Needs to be the
              same for all nodes in a cluster in order to find each
              other.</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
    </section>
  </section>
</section>
