use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class AddToCacheService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
for (CacheEntryEvaluator ceg : getCacheEntryEvaluators()) {
String key = ceg.getKey(msg);
Object value = ceg.getValue(msg);
if (key == null || value == null) {
log.warn("{} generated null values for either the key or value, not storing in cache", ceg.friendlyName());
continue;
}
if (enforceSerializable() && !(value instanceof Serializable)) {
throw new ServiceException("Cache value " + value + " should be Serializable, but is of type " + value.getClass());
}
cache.put(key, value);
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.ServiceException 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.ServiceException 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.ServiceException 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.ServiceException 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