Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
   * 
   * http://aws.amazon.com/apache2.0
   * 
  * or in the "license" file accompanying this file. This file is distributed on
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.simpleworkflow.flow.interceptors;
 
 
Cancels and reexecutes a command when cancelCurrentAndReexecute() is called. In case of command failures or successful completions it is not reexecuted.

Author(s):
fateev
 
 public class AsyncCancelAndRetryExecutor implements AsyncExecutor {
 
 
     private Settable<VoidcommandDone;

    
Used to inhibit retry in case of failures or successful completions
 
     private boolean cancelledDueToRetryRequest;
 
     protected AsyncRunnable command;
 
     @Override
     public void execute(final AsyncRunnable cmd) {
         if ( != null) {
             throw new IllegalStateException("Already executing a command");
         }
          = cmd;
          = new TryCatchFinally() {
 
             @Override
             protected void doTry() throws Throwable {
                 cmd.run();
             }
 
             @Override
             protected void doCatch(Throwable ethrows Throwable {
                 if (e instanceof CancellationException &&  != null) {
                      = true;
                 }
                 else {
                     throw e;
                 }
             }
 
             @Override
             protected void doFinally() throws Throwable {
                 if (!) {
                      = null;
                 }
                 if ( != null) {
                     .set(null);
                 }
                  = null;
                  = null;
             }
 
         };
     }
 
     public void cancelCurrentAndReexecute() {
         if ( != null) {
             // Skip duplicated calls to cancelCurrentAndReexecute
             if ( == null) {
                  = new Settable<Void>();
                 .cancel(null);
                 new Task() {
 
                     @Override
                     protected void doExecute() throws Throwable {
                         if () {
                             execute();
                         }
                     }
                 };
             }
         }
     }
New to GrepCode? Check out our FAQ X