I'm developing simple type of event processing with apache storm and ehcache to handle the data from specific sensor.
General flow is, When sensor's data is published to redis, my 'Redis Spout' in storm gets it and send it to next bolt, and the bolt gets some data everytime from ehcache to get basic information to handle the sensor data (Ehcache data is created when storm engine is started).
The problem is that, when I run storm engine in 2 different computers respectively and then whenever the data is created from the sensor, 2 application subscribe the data randomly. This seems going well.. but then suddenly one of the applications fails to get data from cache with subscribed key. The key is sent with the sensor data and I confirmed the key exists before getting into .get(key) method. But after get(key) returns null and getKeys() gets nothing as well. (Ehcache is synchronized in some other process since ehcache data is updated in web page)
Running with only one application works fine, but running 2 applications at the same time always makes some of the applications's cache null.
I'm using net.sf.ehcache 2.10.6. Can you give me any suggestions? And I confuse whether it is ok to obtain data from ehcache everytime when huge amout of sensor data is coming very frequently(0.1-1sec)through apache storm engine..
public static synchronized Cache getCache(String cacheName) {
Cache cache = null;
CacheManager cacheManager = CacheManager.getInstance();
if (cacheManager == null) {
URL configurationFileURL = Constants.class.getResource("/Constants.xml");
cacheManager = CacheManager.create(configurationFileURL);
} else {
cache = cacheManager.getCache(cacheName);
}
return cache;}
public static List<PrepObject> getPrepObjectCacheData(String epId) {
List<PrepObject> list = new ArrayList<PrepObject>();
Cache prepObjectCache = getCache(prepCache);
if (prepObjectCache != null) {
if (prepObjectCache.isKeyInCache(epId)) {
Element element = prepObjectCache.get(epId);
list = (List<PrepObject>) element.getObjectValue();
} else {
LOGGER.info(
String.format("the element %s has not been found in the cache %s", epId, prepCache));
}
} else {
LOGGER.info(String.format("The cache %s has not been found in the cacheManager.", prepCache));
}
return list;}