/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { try { for (final ProfileInterceptorResult result : results) { store(result); } } catch (final IOException e) { log.error("{} Unable to write results '{}' to storage", getLogPrefix(), results, e); ActionSupport.buildEvent(profileRequestContext, EventIds.IO_ERROR); } }
/** {@inheritDoc} */ @Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { if (!super.doPreExecute(profileRequestContext, interceptorContext)) { return false; } results = interceptorContext.getResults(); if (results.isEmpty()) { log.debug("{} No results available from interceptor context, nothing to store", getLogPrefix()); return false; } flowDescriptor = interceptorContext.getAttemptedFlow(); if (flowDescriptor == null) { log.warn("{} No flow descriptor within interceptor context", getLogPrefix()); return false; } storageService = flowDescriptor.getStorageService(); if (storageService == null) { log.warn("{} No storage service available from interceptor flow descriptor", getLogPrefix()); return false; } return true; }
/** * Store a profile interceptor result. * * @param result the profile interceptor result to be stored * @throws IOException if an error occurs */ protected void store(@Nonnull final ProfileInterceptorResult result) throws IOException { final String context = result.getStorageContext(); final String key = result.getStorageKey(); final String value = result.getStorageValue(); final Long expiration = result.getStorageExpiration(); // Create / update loop until we succeed or exhaust attempts. int attempts = 10; boolean success = false; do { success = storageService.create(context, key, value, expiration); if (!success) { // The record already exists, so we need to overwrite via an update. success = storageService.update(context, key, value, expiration); } } while (!success && attempts-- > 0); if (!success) { log.error("{} Exhausted retry attempts storing result '{}'", getLogPrefix(), result); } }