private List<String> dependenciesOf(Package source) {
   List<String> result = new ArrayList<>();
   if (source.isAnnotationPresent(DependsUpon.class))
     for (Class<?> target : source.getAnnotation(DependsUpon.class).packagesOf())
       result.add(target.getPackage().getName());
   return result;
 }
  // Loads the parameters from file if the file has changed.
  // Returns the parameters or null if the file does not exist.
  private static <T extends ConfProvider> T loadParameters(
      Path path, Class<T> clazz, T existingInstance) throws Exception {
    T params = existingInstance != null ? existingInstance : (T) clazz.newInstance();

    if (params.hasChanged()) {
      log.trace("Loading {} from {}", clazz.getSimpleName(), path);

      params.load(path.toString());
    }

    return params;
  }
  /**
   * Returns compact class host.
   *
   * @param obj Object to compact.
   * @return String.
   */
  @Nullable
  public static Object compactObject(Object obj) {
    if (obj == null) return null;

    if (obj instanceof Enum) return obj.toString();

    if (obj instanceof String || obj instanceof Boolean || obj instanceof Number) return obj;

    if (obj instanceof Collection) {
      Collection col = (Collection) obj;

      Object[] res = new Object[col.size()];

      int i = 0;

      for (Object elm : col) res[i++] = compactObject(elm);

      return res;
    }

    if (obj.getClass().isArray()) {
      Class<?> arrType = obj.getClass().getComponentType();

      if (arrType.isPrimitive()) {
        if (obj instanceof boolean[]) return Arrays.toString((boolean[]) obj);
        if (obj instanceof byte[]) return Arrays.toString((byte[]) obj);
        if (obj instanceof short[]) return Arrays.toString((short[]) obj);
        if (obj instanceof int[]) return Arrays.toString((int[]) obj);
        if (obj instanceof long[]) return Arrays.toString((long[]) obj);
        if (obj instanceof float[]) return Arrays.toString((float[]) obj);
        if (obj instanceof double[]) return Arrays.toString((double[]) obj);
      }

      Object[] arr = (Object[]) obj;

      int iMax = arr.length - 1;

      StringBuilder sb = new StringBuilder("[");

      for (int i = 0; i <= iMax; i++) {
        sb.append(compactObject(arr[i]));

        if (i != iMax) sb.append(", ");
      }

      sb.append("]");

      return sb.toString();
    }

    return U.compact(obj.getClass().getName());
  }
 private static Class<?> type(Location location) {
   try {
     return Class.forName(location.getClassName());
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
 /**
  * Log task mapped.
  *
  * @param log Logger.
  * @param clazz Task class.
  * @param nodes Mapped nodes.
  */
 public static void logMapped(
     @Nullable IgniteLogger log, Class<?> clazz, Collection<ClusterNode> nodes) {
   log0(
       log,
       U.currentTimeMillis(),
       String.format("[%s]: MAPPED: %s", clazz.getSimpleName(), U.toShortString(nodes)));
 }
  /**
   * Log finished.
   *
   * @param log Logger.
   * @param clazz Class.
   * @param start Start time.
   */
  public static void logFinish(@Nullable IgniteLogger log, Class<?> clazz, long start) {
    final long end = U.currentTimeMillis();

    log0(
        log,
        end,
        String.format(
            "[%s]: FINISHED, duration: %s", clazz.getSimpleName(), formatDuration(end - start)));
  }
  /**
   * Log message.
   *
   * @param log Logger.
   * @param msg Message to log.
   * @param clazz class.
   * @param start start time.
   * @return Time when message was logged.
   */
  public static long log(@Nullable IgniteLogger log, String msg, Class<?> clazz, long start) {
    final long end = U.currentTimeMillis();

    log0(
        log,
        end,
        String.format(
            "[%s]: %s, duration: %s", clazz.getSimpleName(), msg, formatDuration(end - start)));

    return end;
  }
Esempio n. 8
0
  /** Returns a set of tests to run for varied log configurations. */
  protected Object[] testsFor(Class<? extends LogTest> testClass) throws Throwable {
    List<Object> tests = new ArrayList<>();
    for (int i = 1; i < 10; i++) {
      LogTest test = testClass.newInstance();
      test.entriesPerSegment = i;
      test.entryPadding = i / 3;
      tests.add(test);
    }

    return tests.toArray(new Object[tests.size()]);
  }
 /**
  * Log start.
  *
  * @param log Logger.
  * @param clazz Class.
  * @param start Start time.
  */
 public static void logStart(@Nullable IgniteLogger log, Class<?> clazz, long start) {
   log0(log, start, "[" + clazz.getSimpleName() + "]: STARTED");
 }