use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class AddValueToCache method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
Optional<Expiry> hasExpiry = buildExpiry(msg);
String cacheKey = msg.resolve(getKey());
// should be hasExpiry.ifPresentOrElse() once we goto J11...
if (hasExpiry.isPresent()) {
TimeInterval expiryInterval = hasExpiry.get().expiresIn();
log.trace("[{}] will expire in {}", cacheKey, expiryInterval);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg), hasExpiry.get().expiresIn());
} else {
log.trace("Expiry for [{}] taken from cache settings", cacheKey);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg));
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class CheckCacheService method eval.
protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
int count = 0;
int required = getCacheEntryEvaluators().size();
Cache cache = retrieveCache();
for (CacheEntryEvaluator lookup : getCacheEntryEvaluators()) {
Object o = cache.get(lookup.getKey(msg));
if (o != null) {
count++;
callback.handle(msg, o, lookup.valueTranslator());
}
}
return count == required;
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class GetValueFromCache method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
String key = msg.resolve(getKey());
Object value = cache.get(key);
if (value != null || !exceptionIfNotFound()) {
getValueTranslator().addValueToMessage(msg, value);
} else {
throw new ServiceException(String.format("%s not found in cache", key));
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class RemoveFromCacheService method doService.
/**
* Retrieves the item from the cache, stores it against the message and then removes it from the cache
*
* @see com.adaptris.core.services.cache.RetrieveFromCacheService#doService(com.adaptris.core.AdaptrisMessage)
*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
for (CacheEntryEvaluator ceg : getCacheEntryEvaluators()) {
String key = ceg.getKey(msg);
if (isEmpty(key)) {
log.warn("{} generated null values for the key, nothing to do", ceg.friendlyName());
continue;
}
addCacheValueToMessage(msg, key, ceg.valueTranslator(), !exceptionIfNotFound());
cache.remove(key);
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.cache.Cache in project interlok by adaptris.
the class RemoveKeyFromCache method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
cache.remove(msg.resolve(getKey()));
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
Aggregations