public void close() {
   if (jusl) {
     try {
       // Call java.util.ServiceLoader.reload
       Method reloadMethod = loaderClass.getMethod("reload");
       reloadMethod.invoke(loader);
     } catch (Exception e) {; // Ignore problems during a call to reload.
     }
   }
 }
    ServiceIterator(ClassLoader classLoader, Log log) {
      String loadMethodName;

      this.log = log;
      try {
        try {
          loaderClass = Class.forName("java.util.ServiceLoader");
          loadMethodName = "load";
          jusl = true;
        } catch (ClassNotFoundException cnfe) {
          try {
            loaderClass = Class.forName("sun.misc.Service");
            loadMethodName = "providers";
            jusl = false;
          } catch (ClassNotFoundException cnfe2) {
            // Fail softly if a loader is not actually needed.
            this.iterator = handleServiceLoaderUnavailability("proc.no.service", null);
            return;
          }
        }

        // java.util.ServiceLoader.load or sun.misc.Service.providers
        Method loadMethod = loaderClass.getMethod(loadMethodName, Class.class, ClassLoader.class);

        Object result = loadMethod.invoke(null, Processor.class, classLoader);

        // For java.util.ServiceLoader, we have to call another
        // method to get the iterator.
        if (jusl) {
          loader = result; // Store ServiceLoader to call reload later
          Method m = loaderClass.getMethod("iterator");
          result = m.invoke(result); // serviceLoader.iterator();
        }

        // The result should now be an iterator.
        this.iterator = (Iterator<?>) result;
      } catch (Throwable t) {
        log.error("proc.service.problem");
        throw new Abort(t);
      }
    }
예제 #3
0
 protected Object callMethod(Object o, Class<?> clazz, String name) {
   try {
     Method m = clazz.getDeclaredMethod(name);
     boolean prev = m.isAccessible();
     m.setAccessible(true);
     try {
       return m.invoke(o);
     } finally {
       m.setAccessible(prev);
     }
   } catch (ReflectiveOperationException e) {
     return e;
   } catch (SecurityException e) {
     return e;
   }
 }
예제 #4
0
 protected Object getField(Object o, Class<?> clazz, String name) {
   try {
     Field f = clazz.getDeclaredField(name);
     boolean prev = f.isAccessible();
     f.setAccessible(true);
     try {
       return f.get(o);
     } finally {
       f.setAccessible(prev);
     }
   } catch (ReflectiveOperationException e) {
     return e;
   } catch (SecurityException e) {
     return e;
   }
 }
예제 #5
0
 protected String info(Class<?> clazz, Object internal, Object external) {
   return String.format("%s,%s,%s", clazz.getSimpleName(), internal, external);
 }