Hazelcast Integration for Spring Environments

This chapter describes the Spring configuration required to setup Hazelcast in-memory cache in Spring-managed environments. Hazelcast is a clustering and scalable data distribution platform. For detailed information on Hazelcast refer to http://www.hazelcast.com/product.jsp.

For details on tuning via an in-memory cache in Infinity refer to chapter Retrieving Entities from In-Memory Cache in the Developer Handbook.

The in-memory cache is turned on by default with the property below in your server-side carnot.properties file.

Infinity.Engine.Caching = true

If not, set this property explicitly.

Deployment Preparation

Perform the following steps to prepare a Spring deployment with Hazelcast integration:

  1. Integrate the following Spring Application Context by putting a file ending with -context.xml and the following content into the WEB-INF/config/ipp/spring folder of your WAR file:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
                      
       <bean id="localHazelcastConnectionFactory" class="org.springframework.jca.support.LocalConnectionFactoryBean">
          <property name="managedConnectionFactory" ref="managedConnectionFactory" />
          <property name="connectionManager">
             <bean id="connectionManagerFactory" class="org.jencks.factory.ConnectionManagerFactoryBean">
                <property name="transactionManager" ref="JencksXaTxManager" />
                <property name="transaction" value="xa" />
                <property name="poolingSupport" ref="hzPoolingSupport" />
             </bean>
          </property>
       </bean>
    
       <bean id="managedConnectionFactory" class="com.hazelcast.jca.ManagedConnectionFactoryImpl">
          <property name="connectionTracingEvents" value="" />
          <property name="connectionTracingDetail" value="false" />
          <property name="resourceAdapter" ref="resourceAdapter" />
       </bean>
    <bean id="resourceAdapter" class="com.hazelcast.jca.ResourceAdapterImpl" init-method="start" destroy-method="stop" /> <bean id="hzPoolingSupport" class="org.jencks.factory.PoolingSupportFactoryBean"> <property name="poolMinSize" value="50" /> <property name="poolMaxSize" value="100" /> <property name="connectionMaxWaitMilliseconds" value="5000" /> <property name="connectionMaxIdleMinutes" value="1" /> </bean> <bean name="JencksXaTxManager" class="org.jencks.factory.TransactionManagerFactoryBean" /> <bean name="springContextPostProcessor" class="org.eclipse.stardust.engine.spring.integration.jca.SpringContextPostProcessor" /> </beans>
  2. Put the following Hazelcast artifacts into the WEB-INF/lib of your WAR file:
  3. Add the following entry to your server-side carnot.properties file to enable the Spring-based version of the Hazelcast Cache Factory:
    Carnot.Engine.Hazelcast.JcaConnectionFactoryProvider = org.eclipse.stardust.engine.spring.integration.jca.SpringAppContextHazelcastJcaConnectionFactoryProvider
  4. Add the following entries to your carnot.properties file to enable Hazelcast caching:
    Infinity.Engine.Caching = true
    
    Infinity.Engine.Caching.CacheFactory = org.eclipse.stardust.engine.core.cache.hazelcast.HazelcastCacheFactory
    
    Infinity.Engine.Caching.Hazelcast.TxMode = rw
    Infinity.Engine.Caching.Hazelcast.ConnectionFactoryJndiName = HazelcastCF
    Infinity.Engine.Caching.Hazelcast.GlobalCacheName = ipp-2nd-level-cache
        
  5. Optional: Put an appropriate hazelcast.xml into WEB-INF/classes folder of your WAR (or a default configuration will be taken from com.hazelcast:hazelcast:2.4).

Hazelcast Configuration

Create the following default configuration template hazelcast.xml defining one IPP specific distributed cache object ipp-2nd-level-cache:

hazelcast.xml

The engine then uses Hazelcast as second level cache provider. Add the configuration file to your runtime's classpath.

Using Hazelcast in a non-clustered Environment

In case you use Hazelcast in non-clustered environments, e.g. in different environments in the same network, adjust your hazelcast.xml in one of the following ways:

  1. Configure Hazelcast to not join a cluster:
    ...
          <join>
             <aws enabled="false" />
             <multicast enabled="false" />
             <tcp-ip enabled="false" />
          </join>
          <interfaces>
             <interface>127.0.0.1</interface>
          </interfaces>
        </network>
    ...
  2. or define a different group for each environment:
        <group>
            <name>dev</name>
            <password>dev-pass</password>
        </group>