/**
  * Clean up the cache if necessary and close the context provided (if the flag indicates that
  * processing was successful).
  *
  * @param retryPolicy the {@link RetryPolicy}
  * @param context the {@link RetryContext}
  * @param state the {@link RetryState}
  * @param succeeded whether the close succeeded
  */
 protected void close(
     RetryPolicy retryPolicy, RetryContext context, RetryState state, boolean succeeded) {
   if (state != null) {
     if (succeeded) {
       if (!context.hasAttribute(GLOBAL_STATE)) {
         this.retryContextCache.remove(state.getKey());
       }
       retryPolicy.close(context);
       context.setAttribute(RetryContext.CLOSED, true);
     }
   } else {
     retryPolicy.close(context);
     context.setAttribute(RetryContext.CLOSED, true);
   }
 }