use of net.sf.ehcache.CacheException in project camel by apache.
the class CacheProducer method createElementFromBody.
private Element createElementFromBody(String key, Exchange exchange, String cacheOperation) throws NoTypeConversionAvailableException {
Element element;
Object body = exchange.getIn().getBody();
if (body == null) {
throw new CacheException("Body cannot be null for operation " + cacheOperation);
} else if (body instanceof Serializable) {
element = new Element(key, body);
} else if (config.isObjectCache()) {
element = new Element(key, body);
} else {
InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, body);
// Read InputStream into a byte[] buffer
element = new Element(key, exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, is));
}
// set overrides for the cache expiration and such
final Integer ttl = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_TTL, Integer.class);
if (ttl != null) {
element.setTimeToLive(ttl);
}
final Integer idle = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_IDLE, Integer.class);
if (idle != null) {
element.setTimeToIdle(idle);
}
final Boolean flag = exchange.getIn().getHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_ETERNAL, Boolean.class);
if (flag != null) {
element.setEternal(flag);
}
return element;
}
use of net.sf.ehcache.CacheException in project jforum2 by rafaelsteil.
the class EhCacheEngine method add.
public void add(String fullyQualifiedName, String key, Object value) {
if (!manager.cacheExists(fullyQualifiedName)) {
try {
manager.addCache(fullyQualifiedName);
} catch (CacheException ce) {
log.error(ce, ce);
throw new RuntimeException(ce);
}
}
Cache cache = manager.getCache(fullyQualifiedName);
Element element = new Element(key, (Serializable) value);
cache.put(element);
}
Aggregations