Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012-2015 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;
 
 import java.util.List;

 TODO: Deal with repeating async stack frames due to recursion. 
 So
 at a
 at -- continuation -- (repeated:1)
 at b
 at -- continuation -- (repeated:1)
 at c
 at -- continuation -- (repeated:1)
 at d
 at -- continuation -- (repeated:1)
 at c
 at -- continuation -- (repeated:1)
 at d
 
Should become something like
 at a
 at -- continuation -- (repeated:1)
 at b
 at -- continuation -- (repeated:2)
   at c
   at -- continuation -- (repeated:1)
   at d
  
 
 class AsyncStackTrace {
 
     private final StackTraceElement[] stackTrace;
 
     private final AsyncStackTrace parentTrace;
 
     private String startFrom;
     
     private boolean hideStartFromMethod;
 
     private final int skip;

    
When set to true disables the removal of any stack elements. Useful for troubleshooting the broken traces.
 
     private static final boolean printRawTrace = false;
 
     public AsyncStackTrace(AsyncStackTrace parentTraceStackTraceElement[] stackTraceint skip) {
         super();
         this. = parentTrace;
         this. = stackTrace;
         this. = skip;
     }
 
     public StackTraceElement[] getStackTrace() {
         if () {
             return printRawTrace();
         }
         List<StackTraceElementresult = new ArrayList<StackTraceElement>();
         getStackTrace(result);
         return result.toArray(new StackTraceElement[0]);
     }
 
     private void getStackTrace(List<StackTraceElementresult) {
         for (int i = i < .i++) {
             StackTraceElement element = [i];
             if (i ==  && result.size() > 0) {
                 StackTraceElement separator = new StackTraceElement("--- continuation ---""""", 0);
                 result.add(separator);
             }
             if ( != null && element.getMethodName().contains()) {
                 if (!) {
                     result.add(element);
                 }
                 break;
             }
             result.add(element);
         }
         if ( != null) {
             .getStackTrace(result);
         }
     }
    private StackTraceElement[] printRawTrace() {
        if ( != null) {
            StackTraceElement[] parentStack = .getStackTrace();
            int parentLength = parentStack.length;
            if (parentLength > 0) {
                StackTraceElement separator = new StackTraceElement("---continuation---""""", 0);
                StackTraceElement[] result = new StackTraceElement[. + parentLength + 1];
                System.arraycopy(, 0, result, 0, .);
                result[.] = separator;
                System.arraycopy(parentStack, 0, result. + 1, parentLength);
                return result;
            }
        }
        return ;
    }
    public void setStartFrom(String startFrom) {
        this. = startFrom;
    }
    public void setHideStartFromMethod(boolean hideStartFromMethod) {
        this. = hideStartFromMethod;
    }
    public String toString() {
        return stackTraceToString(getStackTrace());
    }
    private String stackTraceToString(StackTraceElement[] trace) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < trace.lengthi++) {
            if (i > 0) {
                result.append("\n\tat ");
            }
            else {
                result.append("\tat ");
            }
            result.append(trace[i]);
        }
        return result.toString();
    }
New to GrepCode? Check out our FAQ X