net.sf.ehcache.ClusteredInstanceFactoryAccessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/*
* All content copyright (c) 2003-2012 Terracotta, Inc., except as may otherwise be noted in a separate copyright
* notice. All rights reserved.
*/
package net.sf.ehcache;
import net.sf.ehcache.terracotta.ClusteredInstanceFactory;
import net.sf.ehcache.terracotta.TerracottaClient;
import java.lang.reflect.Field;
/**
* @author Ludovic Orban
*/
public class ClusteredInstanceFactoryAccessor {
public static ClusteredInstanceFactory getClusteredInstanceFactory(CacheManager cacheManager) {
try {
Field field = CacheManager.class.getDeclaredField("terracottaClient");
field.setAccessible(true);
TerracottaClient terracottaClient = (TerracottaClient)field.get(cacheManager);
return terracottaClient.getClusteredInstanceFactory();
} catch (NoSuchFieldException nsfe) {
throw new CacheException(nsfe);
} catch (IllegalAccessException iae) {
throw new CacheException(iae);
}
}
public static void setTerracottaClient(CacheManager cacheManager, TerracottaClient terracottaClient) {
try {
Field field = CacheManager.class.getDeclaredField("terracottaClient");
field.setAccessible(true);
field.set(cacheManager, terracottaClient);
} catch (NoSuchFieldException nsfe) {
throw new CacheException(nsfe);
} catch (IllegalAccessException iae) {
throw new CacheException(iae);
}
}
}