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.core;
 
 
 
     private final class ExternalTaskCompletionHandleImpl implements ExternalTaskCompletionHandle {
 
         private String methodName;
 
         private boolean completed;
 
         private Throwable failure;
 
         private void setDoExecuteFailed(String methodNameThrowable e) {
             this. = e;
             this. = methodName;
         }
 
         @Override
         public void complete() {
             if ( != null) {
                 throw new IllegalStateException("Invalid ExternalTaskCompletionHandle as " + 
                         + " failed with an exception.");
             }
             if () {
                 throw new IllegalStateException("Already completed");
             }
              = true;
             if (!) {
                 removeFromParent();
             }
         }
 
         @Override
         public void fail(final Throwable e) {
             if ( != null) {
                 throw new IllegalStateException("Invalid ExternalTaskCompletionHandle as " + 
                         + " failed with exception.");
             }
             if () {
                 throw new IllegalStateException("Already completed");
             }
             if ( != null && !.isRethrown(e)) {
                 AsyncStackTrace merged = new AsyncStackTrace(e.getStackTrace(), 0);
                 merged.setStartFrom(getParentTaskMethodName());
                 e.setStackTrace(merged.getStackTrace());
             }
              = e;
             if (!) {
                 failToParent(e);
             }
         }
 
         public boolean isCompleted() {
             return ;
         }
 
         public Throwable getFailure() {
             return ;
         }
 
     }
 
     private final ExternalTask task;
 
 
     private boolean canceled;

    
Used to deal with situation when task is completed while in cancellation handler and then exception is thrown from it.
 
     private boolean inCancellationHandler;
 
 
     private String description;
 
     public ExternalTaskContext(ExternalTask taskBoolean daemonPromise<?>[] waitFor) {
         super(daemonwaitFor, 6);
         this. = task;
     }
 
    public ExternalTaskContext(AsyncParentContext parentExternalTask taskBoolean daemonPromise<?>[] waitFor) {
        super(parentdaemonwaitFor, 6);
        this. = task;
    }
    public void cancel(final Throwable cause) {
        if (. != null || .) {
            return;
        }
        if () {
            return;
        }
         = true;
        if ( != null) {
            .getExecutor().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                         = true;
                        .handleCancellation(cause);
                    }
                    catch (Throwable e) {
                        if ( != null && !.isRethrown(e)) {
                            AsyncStackTrace merged = new AsyncStackTrace(e.getStackTrace(), 0);
                            merged.setStartFrom(getParentTaskMethodName());
                            e.setStackTrace(merged.getStackTrace());
                        }
                        .setDoExecuteFailed("ExternalTaskCancellationHandler.handleCancellation"e);
                    }
                    finally {
                         = false;
                        if (.getFailure() != null) {
                            failToParent(.getFailure());
                        }
                        else if (.isCompleted()) {
                            removeFromParent();
                        }
                    }
                }
            });
        }
    }
    @Override
    public void run() {
        if () {
            return;
        }
        setCurrent();
        try {
        }
        catch (Throwable e) {
            .setDoExecuteFailed("ExternalTask.doExecute"e);
            if ( != null && !.isRethrown(e)) {
                AsyncStackTrace merged = new AsyncStackTrace(e.getStackTrace(), 0);
                merged.setStartFrom(getParentTaskMethodName());
                e.setStackTrace(merged.getStackTrace());
            }
            .fail(thise);
        }
        finally {
            setCurrent(null);
        }
    }
    @Override
    public void add(AsyncContextBase asyncPromise<?> waitFor) {
        .add(asyncwaitFor);
    }
    @Override
    public void remove(AsyncContextBase async) {
        .remove(async);
    }
    @Override
    public void fail(AsyncContextBase asyncThrowable e) {
        .fail(asynce);
    }
    @Override
    public Executor getExecutor() {
        return .getExecutor();
    }
    @Override
    public boolean isRethrown(Throwable e) {
        return .isRethrown(e);
    }
    @Override
        return ;
    }
    @Override
    public boolean getDaemonFlagForHeir() {
        return isDaemon();
    }
    @Override
    public String getParentTaskMethodName() {
        if () {
            return "handleCancellation";
        }
        return "doExecute";
    }
    private void removeFromParent() {
        .getExecutor().execute(new Runnable() {
            @Override
            public void run() {
                .remove(ExternalTaskContext.this);
            }
        });
    }
    private void failToParent(final Throwable e) {
        .getExecutor().execute(new Runnable() {
            @Override
            public void run() {
                .fail(ExternalTaskContext.thise);
            }
        });
    }
    public void setDescription(String description) {
        this. = description;
    }
    public String getDescription() {
        return ;
    }
New to GrepCode? Check out our FAQ X