예제 #1
0
 /**
  * Checks that FileChannel map throws one of the expected exceptions when invoked with the given
  * inputs.
  */
 private static void checkException(
     FileChannel fc, MapMode mode, long position, long size, Class<?>... expected)
     throws IOException {
   Exception exc = null;
   try {
     fc.map(mode, position, size);
   } catch (Exception actual) {
     exc = actual;
   }
   if (exc != null) {
     for (Class<?> clazz : expected) {
       if (clazz.isInstance(exc)) {
         return;
       }
     }
   }
   System.err.println("Expected one of");
   for (Class<?> clazz : expected) {
     System.out.println(clazz);
   }
   if (exc == null) {
     throw new RuntimeException("No expection thrown");
   } else {
     throw new RuntimeException("Unexpected exception thrown", exc);
   }
 }
예제 #2
0
  /**
   * 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());
  }
예제 #3
0
파일: LibRt.java 프로젝트: yamila87/rt_src
 public static void executeMethodClass(
     String pathToJar,
     String pkg,
     String classToGet,
     String methodName,
     String pathToFile,
     long logIdSyncMin,
     long logIdSyncMax)
     throws IOException, ClassNotFoundException, SecurityException, InstantiationException,
         IllegalAccessException, NoSuchMethodException, IllegalArgumentException,
         InvocationTargetException {
   Class<?> c = getClassFromJar(pathToJar, pkg, classToGet);
   Method method = c.getDeclaredMethod(methodName, String.class, long.class, long.class);
   method.invoke(null, pathToFile, logIdSyncMin, logIdSyncMax);
 }
예제 #4
0
 /**
  * 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)));
 }
예제 #5
0
  /**
   * 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)));
  }
예제 #6
0
  /**
   * 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;
  }
예제 #7
0
 @Override
 public Result attempt(
     final List<AvailObject> args, final Interpreter interpreter, final boolean skipReturnCheck) {
   assert args.size() == 2;
   final AvailObject handle = args.get(0);
   final AvailObject options = args.get(1);
   final AvailObject pojo = handle.getAtomProperty(AtomDescriptor.socketKey());
   if (pojo.equalsNil()) {
     return interpreter.primitiveFailure(
         handle.isAtomSpecial() ? E_SPECIAL_ATOM : E_INVALID_HANDLE);
   }
   final AsynchronousSocketChannel socket = (AsynchronousSocketChannel) pojo.javaObjectNotNull();
   try {
     for (final MapDescriptor.Entry entry : options.mapIterable()) {
       final AvailObject key = entry.key();
       final AvailObject entryValue = entry.value();
       assert key != null;
       @SuppressWarnings("rawtypes")
       final SocketOption option = socketOptions[key.extractInt()];
       final Class<?> type = option.type();
       if (type.equals(Boolean.class) && entryValue.isBoolean()) {
         final SocketOption<Boolean> booleanOption = option;
         socket.setOption(booleanOption, entryValue.extractBoolean());
       } else if (type.equals(Integer.class) && entryValue.isInt()) {
         final Integer value = entryValue.extractInt();
         socket.<Integer>setOption(option, value);
       } else {
         return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
       }
     }
     return interpreter.primitiveSuccess(NilDescriptor.nil());
   } catch (final IllegalArgumentException e) {
     return interpreter.primitiveFailure(E_INCORRECT_ARGUMENT_TYPE);
   } catch (final IOException e) {
     return interpreter.primitiveFailure(E_IO_ERROR);
   }
 }
예제 #8
0
파일: LibRt.java 프로젝트: yamila87/rt_src
  private static Class<?> getClassFromJar(String pathToJar, String pkg, String classToGet)
      throws IOException, ClassNotFoundException, SecurityException, InstantiationException,
          IllegalAccessException, NoSuchMethodException, IllegalArgumentException,
          InvocationTargetException {

    JarFile jarFile = new JarFile(pathToJar);
    Enumeration e = jarFile.entries();

    URL[] urls = {new URL("jar:file:" + pathToJar + "!/")};
    ClassLoader cl = URLClassLoader.newInstance(urls);

    Class<?> c = Class.forName(pkg + "." + classToGet, true, cl);

    return c;
  }
예제 #9
0
 /**
  * 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");
 }