org.apache.commons.lang.exception.ExceptionUtils#getFullStackTrace ( )源码实例Demo

下面列出了org.apache.commons.lang.exception.ExceptionUtils#getFullStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: systemds   文件: FederatedWorkerHandler.java
private FederatedResponse constructResponse(FederatedRequest request) {
	FederatedRequest.FedMethod method = request.getMethod();
	try {
		switch (method) {
			case READ:
				return readMatrix(request);
			case MATVECMULT:
				return executeMatVecMult(request);
			case TRANSFER:
				return getVariableData(request);
			case AGGREGATE:
				return executeAggregation(request);
			case SCALAR:
				return executeScalarOperation(request);
			default:
				String message = String.format("Method %s is not supported.", method);
				return new FederatedResponse(FederatedResponse.Type.ERROR, message);
		}
	}
	catch (Exception exception) {
		return new FederatedResponse(FederatedResponse.Type.ERROR, ExceptionUtils.getFullStackTrace(exception));
	}
}
 
public void handleException( Exception exception ){
    if( isServiceEnabled() ){
        Date now = new Date();
        newExceptionsCount.incrementAndGet();

        if( nextPossibleNotification.before( now ) ){
            int count = newExceptionsCount.getAndSet( 0 );

            String subject = count + " exception(s) occured in " + mailEnvironment + " Workflow Engine";
            String body = ""
                    + count + " exception(s) occured with ip " + getHostIpAddress() + ". \n"
                    + "\n"
                    + "The most recent exception occured at " + format( now ) + " with the following stacktrace:\n"
                    + "\n"
                    + ExceptionUtils.getFullStackTrace( exception );

            sendEmail( mailFrom, recipients, subject, body );

            nextPossibleNotification = DateUtils.addMinutes( now, notificationIntervalMinutes );
        }
    }
}
 
源代码3 项目: systemds   文件: FederatedResponse.java
public String getErrorMessage() {
	if (_data[0] instanceof Throwable )
		return ExceptionUtils.getFullStackTrace( (Throwable) _data[0] );
	else if (_data[0] instanceof String)
		return (String) _data[0];
	else return "No readable error message";
}
 
/**
 * Verify a specific dataset by following below steps
 *    1) Retrieve a tier-to-count mapping
 *    2) Read count from {@link CompactionAuditCountVerifier#gobblinTier}
 *    3) Read count from all other {@link CompactionAuditCountVerifier#referenceTiers}
 *    4) Compare count retrieved from steps 2) and 3), if any of (gobblin/refenence) >= threshold, return true, else return false
 * @param dataset Dataset needs to be verified
 * @return If verification is succeeded
 */
public Result verify (FileSystemDataset dataset) {
  if (!enabled) {
    return new Result(true, "");
  }
  if (auditCountClient == null) {
    log.debug("No audit count client specified, skipped");
    return new Result(true, "");
  }

  CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset);
  ZonedDateTime startTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(result.getTime().getMillis()), zone);
  ZonedDateTime endTime = TimeIterator.inc(startTime, granularity, 1);
  String datasetName = result.getDatasetName();
  try {
    Map<String, Long> countsByTier = auditCountClient.fetch(datasetName,
        startTime.toInstant().toEpochMilli(), endTime.toInstant().toEpochMilli());
    for (String tier: referenceTiers) {
      Result rst = passed (datasetName, countsByTier, tier);
      if (rst.isSuccessful()) {
        return new Result(true, "");
      }
    }
  } catch (IOException e) {
    return new Result(false, ExceptionUtils.getFullStackTrace(e));
  }

  return new Result(false, String.format("%s data is not complete between %s and %s", datasetName, startTime, endTime));
}
 
/**
 * There are two record count we are comparing here
 *    1) The new record count in the input folder
 *    2) The record count we compacted previously from last run
 * Calculate two numbers difference and compare with a predefined threshold.
 *
 * (Alternatively we can save the previous record count to a state store. However each input
 * folder is a dataset. We may end up with loading too many redundant job level state for each
 * dataset. To avoid scalability issue, we choose a stateless approach where each dataset tracks
 * record count by themselves and persist it in the file system)
 *
 * @return true iff the difference exceeds the threshold or this is the first time compaction
 */
public Result verify(FileSystemDataset dataset) {

  Map<String, Double> thresholdMap = RecompactionConditionBasedOnRatio.
      getDatasetRegexAndRecompactThreshold(
          state.getProp(MRCompactor.COMPACTION_LATEDATA_THRESHOLD_FOR_RECOMPACT_PER_DATASET, StringUtils.EMPTY));

  CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset);

  double threshold =
      RecompactionConditionBasedOnRatio.getRatioThresholdByDatasetName(result.getDatasetName(), thresholdMap);
  log.debug("Threshold is {} for dataset {}", threshold, result.getDatasetName());

  InputRecordCountHelper helper = new InputRecordCountHelper(state);
  try {
    double newRecords = 0;
    if (!dataset.isVirtual()) {
      newRecords = helper.calculateRecordCount(Lists.newArrayList(new Path(dataset.datasetURN())));
    }
    double oldRecords = helper.readRecordCount(new Path(result.getDstAbsoluteDir()));

    if (oldRecords == 0) {
      return new Result(true, "");
    }
    if (newRecords < oldRecords) {
      return new Result(false, "Illegal state: Current records count should old be smaller.");
    }

    if ((newRecords - oldRecords) / oldRecords > threshold) {
      log.debug("Dataset {} records exceeded the threshold {}", dataset.datasetURN(), threshold);
      return new Result(true, "");
    }

    return new Result(false, String
        .format("%s is failed for dataset %s. Prev=%f, Cur=%f, not reaching to threshold %f", this.getName(),
            result.getDatasetName(), oldRecords, newRecords, threshold));
  } catch (IOException e) {
    return new Result(false, ExceptionUtils.getFullStackTrace(e));
  }
}
 
源代码6 项目: rice   文件: XmlIngesterServiceImpl.java
private static void addProcessingException(XmlDoc xmlDoc, String message, Throwable t) {
    String msg = xmlDoc.getProcessingMessage();
    if (msg == null) {
        msg = "";
    }
    msg += message + "\n" + ExceptionUtils.getFullStackTrace(t);
    xmlDoc.setProcessingMessage(msg);
}
 
源代码7 项目: rice   文件: XmlDigesterServiceImpl.java
private static void addProcessingException(XmlDoc xmlDoc, String message, Throwable t) {
    String msg = xmlDoc.getProcessingMessage();
    if (msg == null) {
        msg = "";
    }
    msg += message + "\n" + ExceptionUtils.getFullStackTrace(t);
    xmlDoc.setProcessingMessage(msg);
}
 
源代码8 项目: hop   文件: BodyHttpServlet.java
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException {
  if ( isJettyMode() && !request.getContextPath().startsWith( getContextPath() ) ) {
    return;
  }

  if ( log.isDebug() ) {
    logDebug( messages.getString( "Log.Execute" ) );
  }

  boolean useXML = useXML( request );
  PrintWriter out = new PrintWriter( response.getOutputStream() );

  try {

    if ( useXML ) {
      startXml( response, out );
    } else {
      beginHtml( response, out );
    }

    WebResult result = generateBody( request, response, useXML );
    if ( result != null ) {
      out.println( result.getXml() );
    }

  } catch ( Exception e ) {
    String st = ExceptionUtils.getFullStackTrace( e );
    if ( useXML ) {
      out.println( new WebResult( WebResult.STRING_ERROR, st ).getXml() );
    } else {
      out.println( "<p><pre>" );
      out.println( Encode.forHtml( st ) );
      out.println( "</pre>" );
    }
  } finally {
    if ( !useXML ) {
      endHtml( out );
    }
    out.flush();
    IOUtils.closeQuietly( out );
  }
}
 
源代码9 项目: DataLink   文件: TaskExceptionProbeIndex.java
private String buildExceptionInfo(Throwable t) {
    return ExceptionUtils.getFullStackTrace(t);
}
 
public static Wire getWire(Throwable e) {
    return new Wire(ExceptionUtils.getFullStackTrace(e), "", "");
}
 
public static Wire getWire(Throwable e) {
    return new Wire(ExceptionUtils.getFullStackTrace(e), "");
}
 
源代码12 项目: tddl5   文件: ExtensionLoader.java
private static <S> S loadFile(Class<S> service, String activateName, ClassLoader loader) {
    try {
        boolean foundFromCache = true;
        List<Class> extensions = providers.get(service);
        if (extensions == null) {
            synchronized (service) {
                extensions = providers.get(service);
                if (extensions == null) {
                    extensions = findAllExtensionClass(service, activateName, loader);
                    foundFromCache = false;
                    providers.put(service, extensions);
                }
            }
        }

        // 为避免被覆盖,每个activateName的查找,允许再加一层子目录
        if (StringUtils.isNotEmpty(activateName)) {
            loadFile(service, TDDL_DIRECTORY + activateName.toLowerCase() + "/", loader, extensions);

            List<Class> activateExtensions = new ArrayList<Class>();
            for (int i = 0; i < extensions.size(); i++) {
                Class clz = extensions.get(i);
                Activate activate = (Activate) clz.getAnnotation(Activate.class);
                if (activate != null && activateName.equals(activate.name())) {
                    activateExtensions.add(clz);
                }
            }

            extensions = activateExtensions;
        }

        if (extensions.isEmpty()) {
            throw new ExtensionNotFoundException("not found service provider for : " + service.getName() + "["
                                                 + activateName + "] and classloader : "
                                                 + ObjectUtils.toString(loader));
        }
        Class<?> extension = extensions.get(extensions.size() - 1);// 最大的一个
        S result = service.cast(extension.newInstance());
        if (!foundFromCache && logger.isInfoEnabled()) {
            logger.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class["
                        + extension.getName() + "]");
        }
        return result;
    } catch (Throwable e) {
        if (e instanceof ExtensionNotFoundException) {
            throw (ExtensionNotFoundException) e;
        } else {
            throw new ExtensionNotFoundException("not found service provider for : " + service.getName()
                                                 + " caused by " + ExceptionUtils.getFullStackTrace(e));
        }
    }
}
 
源代码13 项目: tddl5   文件: ExceptionErrorCodeUtils.java
public static String exceptionToString(Throwable ex) {
    return ExceptionUtils.getFullStackTrace(ex);
}
 
源代码14 项目: tddl   文件: ExtensionLoader.java
private static <S> List<Class> findAllExtensionClass(Class<S> service, String activateName, ClassLoader loader) {
    List<Class> extensions = Lists.newArrayList();
    try {
        loadFile(service, SERVICES_DIRECTORY, loader, extensions);
        loadFile(service, TDDL_DIRECTORY, loader, extensions);
    } catch (IOException e) {
        throw new ExtensionNotFoundException("not found service provider for : " + service.getName()
                                             + " caused by " + ExceptionUtils.getFullStackTrace(e));
    }

    if (extensions.isEmpty()) {
        return extensions;
    }

    // 做一下排序
    Collections.sort(extensions, new Comparator<Class>() {

        public int compare(Class c1, Class c2) {
            Integer o1 = 0;
            Integer o2 = 0;
            Activate a1 = (Activate) c1.getAnnotation(Activate.class);
            Activate a2 = (Activate) c2.getAnnotation(Activate.class);

            if (a1 != null) {
                o1 = a1.order();
            }

            if (a2 != null) {
                o2 = a2.order();
            }

            return o1.compareTo(o2);

        }
    });

    if (activateName != null) { // 如果有激活条件
        for (int i = extensions.size() - 1; i >= 0; i--) {
            Class clz = extensions.get(i);
            Activate activate = (Activate) clz.getAnnotation(Activate.class);
            if (activate != null && activateName.equals(activate.name())) {
                return Arrays.asList(clz);
            }
        }

        throw new ExtensionNotFoundException("not found service provider for : " + service.getName()
                                             + " activateName : " + activateName);
    } else {
        return extensions;
    }

}
 
源代码15 项目: honeydew   文件: Result.java
public Result(String errorMessage, Throwable exception) {
    this(errorMessage);
    this.stackTrace = ExceptionUtils.getFullStackTrace(exception);
}
 
源代码16 项目: pentaho-kettle   文件: BodyHttpServlet.java
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException {
  if ( isJettyMode() && !request.getContextPath().startsWith( getContextPath() ) ) {
    return;
  }

  if ( log.isDebug() ) {
    logDebug( messages.getString( "Log.Execute" ) );
  }

  boolean useXML = useXML( request );
  PrintWriter out = new PrintWriter( response.getOutputStream() );

  try {

    if ( useXML ) {
      startXml( response, out );
    } else {
      beginHtml( response, out );
    }

    WebResult result = generateBody( request, response, useXML );
    if ( result != null ) {
      out.println( result.getXML() );
    }

  } catch ( Exception e ) {
    String st = ExceptionUtils.getFullStackTrace( e );
    if ( useXML ) {
      out.println( new WebResult( WebResult.STRING_ERROR, st ).getXML() );
    } else {
      out.println( "<p><pre>" );
      out.println( Encode.forHtml( st ) );
      out.println( "</pre>" );
    }
  } finally {
    if ( !useXML ) {
      endHtml( out );
    }
    out.flush();
    IOUtils.closeQuietly( out );
  }
}
 
源代码17 项目: Kettle   文件: MCUtil.java
/**
 * Quickly generate a stack trace for current location
 *
 * @return Stacktrace
 */
public static String stack() {
    return ExceptionUtils.getFullStackTrace(new Throwable());
}
 
源代码18 项目: Kettle   文件: MCUtil.java
/**
 * Quickly generate a stack trace for current location with message
 *
 * @param str
 * @return Stacktrace
 */
public static String stack(String str) {
    return ExceptionUtils.getFullStackTrace(new Throwable(str));
}