Creating new Infinispan 8 configuration
gregosby Mar 6, 2016 4:29 PMI have one Infinispan 8 configuration file, two jgroups files, custom tree cache provider (two spring beans that initilizes car and user cache respectively), I cant start the applicatio. I am reading Infinispan 8 user guide and I am bit confused.
I also put some comments in code as I don't know if the implementation is ok or missing something. I dont know, if I did it properly - I want to have different caches like below - cars and users. Both caches have different UDP multicast addresses so I creatd different jgroups files, but maybe there is some way to parametrize it like ${multicast_address} I see ${nodeName} in Infinispan examplpes but there s nothing about where to put value for such parameter.
I also not sure, whether my treecache provider class is implemented ok, so that it work in clustered cache and start / stop properly and use transactions.
I also see error putting multiple transport stacks, so how should it look like if I have multiple stack files?
<transport stack="cars_file" node-name="${nodeName}" /> <transport stack="user_file" node-name="${nodeName}" />
**Spring bean which is CacheProvider and reads Infinispan config file:**
public class InfinispanCarsCacheProvider implements InitializingBean, DisposableBean { private TreeCache tree; private String configurationFile = null; public void afterPropertiesSet() throws Exception { try { Assert.argNotNull("configurationFile", this.getConfigurationFile()); EmbeddedCacheManager cm = new DefaultCacheManager(this.getConfigurationFile()); Cache<String, String> cache = cm.getCache("carsCache"); TreeCacheFactory tcf = new TreeCacheFactory(); tree = tcf.createTreeCache(cache); ///tree.createService(); ///tree.startService(); tree.start(); } } public void destroy() throws Exception { tree.stop(); //ANY OTHER THINGS TO DO HERE? /** try { Field field = PropertyEditorManager.class.getDeclaredField("registry"); field.setAccessible(true); Hashtable table = (Hashtable) field.get(null); for( Object obj : table.keySet() ){ String name = ((Class<?>)table.get(obj)).getName(); if(name.contains("org.jboss.util.propertyeditor")){ LOGGER.info("Removing property editor: " + name); table.remove(obj); } } } catch ( Exception e ) { LOGGER.warn("Cannot unregister property editors", e); } LOGGER.info("Cache destroyed.");***/ } public boolean putObject(String[] entryKey, String objectKey, Object value) { boolean result; try { Object prevObject = tree.put( Fqn.fromList(Arrays.asList(entryKey)), objectKey, value); result = prevObject != null; } catch (CacheException e) { String msg = "Error putting " + getParamDescription(entryKey, objectKey, value); throw new SystemException(msg + e, e); } finally { //tree.setInvocationContext(null); } return result; } private String getParamDescription ( String[] entryKey , String objectKey , Object value ) { return "[entryKey ='" + StringUtils.join(entryKey,",") + "', objectKey='" + objectKey + "', value ='" + value + "']"; } public void removeObject ( String[] entryKey , String key ) { try { tree.remove(Fqn.fromList(Arrays.asList(entryKey)), key); } catch (CacheException e) { String msg = "Error removing object [entryKey='" + StringUtils.join(entryKey,",") + "' key='" + key + "']"; throw new SystemException(msg + e, e); } finally { // tree.setInvocationContext(null); } } public void removeNode(String[] entryKey) { try { tree.removeNode(Fqn.fromList(Arrays.asList(entryKey))); } catch (CacheException e) { String msg = "Error removing node [entryKey='" + StringUtils.join(entryKey,",") + "']"; throw new SystemException(msg + e, e); } finally { // tree.setInvocationContext(null); } } public Object getObject(String[] entryKey, String objectKey) { Object object; try { object = tree.get(Fqn.fromList(Arrays.asList(entryKey)), objectKey); } catch (CacheException e) { String msg = "Error getting object " + LOGGER.error(msg + e, e); throw new SystemException(msg + e, e); } finally { // tree.setInvocationContext(null); } return object; } public Map getAllObjects(String[] entryKey) { Map object = Collections.emptyMap(); try { Node node = tree.getNode(Fqn.fromList(Arrays.asList(entryKey))); if (node != null) { object = node.getData(); } } catch (CacheException e) { String msg = "Error getting object " + getParamDescription(entryKey, null, null); throw new SystemException(msg + e, e); } finally { // tree.setInvocationContext(null); } return object; } public String getConfigurationFile () { return configurationFile; } /** * @param configurationFile Ustawia wartość configurationFile. */ public void setConfigurationFile ( String configurationFile ) { this.configurationFile = configurationFile; } }
**Below is Infinispan config:**
<?xml version="1.0" encoding="UTF-8"?> <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:8.0 http://www.infinispan.org/schemas/infinispan-config-8.0.xsd" xmlns="urn:infinispan:config:8.0"> <jgroups> <stack-file name="cars_file" path="cars_jgroups.xml" /> <!-- separate jgroups - different multicast addresses --> <stack-file name="users_file" path="users_jgroups.xml" /> </jgroups> <cache-container default-cache="carsCache"> <transport stack="cars_file" node-name="${nodeName}" /><!-- what is nodeName, where is value of this parameter, when this will be replaced?? --> <invalidation-cache name="carsCache" configuration="invalidation-template" /> <invalidation-cache name="usersCache" configuration="invalidation-template" /> <!--</namedCache>--> <invalidation-cache-configuration name="invalidation-template" mode="ASYNC" queue-flush-interval="10" queue-size="1000" start="LAZY" statistics="true"> <locking acquire-timeout="30500" concurrency-level="2500" isolation="READ_COMMITTED" striping="true"/> <transaction mode="BATCH" stop-timeout="60500" locking="OPTIMISTIC"/> <eviction max-entries="20500" strategy="LRU"/> <expiration interval="10500" lifespan="11" max-idle="11"/> </invalidation-cache-configuration> </cache-container> </infinispan>