JBoss Cache 3.x.x Affinity Split Example.
Affinity MapReduce with JBoss Cache example that you can find in release is working with JBoss Cache 2.x.x. Example that is working with JBoss Cache 3.x.x will be available at new release, but here is short description how you can run current release with JBoss Cache 3.x.x.
1. To make possible to run existing example you should update JBoss Cache XML configuration that is available at ${GRIDGAIN_HOME}/config/jbosscache/jboss-cache.xml . Here is new configuration:
<?xml version="1.0" encoding="UTF-8"?> <jbosscache xmlns="urn:jboss:jbosscache-core:config:3.0"> <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="15000"/> <clustering mode="invalidation" clusterName="JBossCache-Cluster"> <sync replTimeout="15000"/> <stateRetrieval fetchInMemoryState="false"/> <jgroupsConfig multiplexerStack="grid.jgroups.stack"/> </clustering> <eviction wakeUpInterval="5000"> <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000"> <property name="maxNodes" value="1000000"/> <property name="timeToLive" value="-1"/> </default> <region name="/gridgain/example" algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" eventQueueSize="200000"> <property name="maxNodes" value="1000000"/> <property name="timeToLive" value="-1"/> </region> </eviction> </jbosscache>
2. Due to changes in JBoss Cache API you should change GridJbossCacheManager.java. Here is new version:
GridJbossCacheManager.java
/* * GRIDGAIN - OPEN CLOUD PLATFORM. * COPYRIGHT (C) 2005-2008 GRIDGAIN SYSTEMS. ALL RIGHTS RESERVED. * * THIS IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR * MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC * LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; EITHER * VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER * VERSION. * * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE * GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS. * * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC * LICENSE ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE * SOFTWARE FOUNDATION, INC., 51 FRANKLIN ST, FIFTH FLOOR, BOSTON, MA * 02110-1301 USA */ package org.gridgain.examples.jbosscache; import java.io.*; import java.util.*; import org.gridgain.grid.util.*; import org.gridgain.grid.*; import org.jgroups.*; import org.jboss.cache.config.*; import org.jboss.cache.config.parsing.*; import org.jboss.cache.*; public final class GridJbossCacheManager { /** Cache configuration path relative to GridGain installation. */ public static final String CACHE_CFG_PATH = "config/jbosscache/jboss-cache.xml"; /** JGroups configuration path relative to GridGain installation. */ public static final String JGROUPS_CFG_PATH = "config/jgroups/multicast/jgroups.xml"; /** JBoss Cache instance. */ private Cache<Long, String> cache = null; /** Cache node for caching example data. */ private Node<Long, String> cacheRoot = null; /** Singleton instance. */ private static GridJbossCacheManager instance = new GridJbossCacheManager(); /** * Gets singleton. * * @return Singleton. */ public static GridJbossCacheManager getInstance() { return instance; } /** * Ensure singleton. */ private GridJbossCacheManager() { // No-op. } /** * Gets test data from data cache by ID. * * @param id Test data ID. * @return Cached data (possibly <tt>null</tt>). */ public String getDataFromCache(long id) { assert cacheRoot != null; // Try to get child node from cache. Node<Long, String> dataNode = cacheRoot.getChild(Fqn.fromList(Collections.singletonList(id))); // If data node does not exist, we lazily create it. if (dataNode == null) { dataNode = cacheRoot.addChild(Fqn.fromList(Collections.singletonList(id))); } assert dataNode != null; // Retrieve cached data from cache. return dataNode.get(id); } /** * Puts test data to the data cache. * * @param id index that associated with this test data. * @param data Data to store in cache. */ public void putDataToCache(long id, String data) { assert cacheRoot != null; Node<Long, String> dataNode = cacheRoot.getChild(Fqn.fromList(Collections.singletonList(id))); // If data node does not exist, we lazily create it. if (dataNode == null) { dataNode = cacheRoot.addChild(Fqn.fromList(Collections.singletonList(id))); } assert dataNode != null; // Cache data. dataNode.put(id, data); } /** * Starts JBoss Cache instance. * * @throws GridException If start failed. */ public void start() throws GridException { File cacheCfg = GridUtils.resolveGridGainPath(CACHE_CFG_PATH); if (cacheCfg == null) { throw new GridException("Failed to find cache configuration file: " + CACHE_CFG_PATH); } File jgroupsCfg = GridUtils.resolveGridGainPath(JGROUPS_CFG_PATH); if (jgroupsCfg == null) { throw new GridException("Failed to find jgroups configuration: " + JGROUPS_CFG_PATH); } // Make sure JBoss Cache and GridGain are on the same "wave length". JChannelFactory factory = new JChannelFactory(); try { factory.setMultiplexerConfig(jgroupsCfg.getCanonicalPath()); } catch (Exception e) { throw new GridException("Failed to start Data Manager.", e); } try { XmlConfigurationParser parser = new XmlConfigurationParser(); // Start JBoss Cache cache with shared JGroups configuration. Configuration svrCfg = parser.parseFile(cacheCfg.getCanonicalPath()); svrCfg.getRuntimeConfig().setMuxChannelFactory(factory); CacheFactory<Long, String> dataFactory = new DefaultCacheFactory<Long, String>(); // Instantiate and start JBoss Cache. cache = dataFactory.createCache(svrCfg); // Cache node for storing example data. cacheRoot = cache.getRoot().addChild(Fqn.fromString("/gridgain/example")); } catch (IOException e) { throw new GridException("Failed to start Data Manager.", e); } System.out.println("JBoss Cache data manager started."); } /** * Stops JBoss Cache instance. */ public void stop() { if (cache != null) { cache.stop(); cache.destroy(); } System.out.println("JBoss Cache data manager stopped."); } }
3. And do not forget to use new JBoss Cache libraries instead of libraries provided with our release.
