public static OperationRegistry initializeRegistry() {
    try {
      InputStream url = PropertyUtil.getFileFromClasspath(JAI_REGISTRY_FILE);

      if (url == null) {
        throw new RuntimeException("Could not find the main registry file");
      }

      OperationRegistry registry = new ConcurrentOperationRegistry();

      if (url != null) {
        registry.updateFromStream(url);
      }

      registry.registerServices(null);

      return registry;

    } catch (IOException ioe) {
      ImagingListener listener = JAI.getDefaultInstance().getImagingListener();
      String message = "Error occurred while initializing JAI";
      listener.errorOccurred(
          message, new ImagingException(message, ioe), OperationRegistry.class, false);

      return null;
    }
  }
 public void registerServices(ClassLoader cl) throws IOException {
   Lock writeLock = lock.writeLock();
   try {
     writeLock.lock();
     super.registerServices(cl);
   } finally {
     writeLock.unlock();
   }
 }
예제 #3
0
 private static void initJAI(ClassLoader cl) {
   System.setProperty(
       "com.sun.media.jai.disableMediaLib", "true"); // disable native libraries for JAI
   // Must use a new operation registry in order to register JAI operators defined in Ceres and
   // BEAM
   OperationRegistry operationRegistry = OperationRegistry.getThreadSafeOperationRegistry();
   InputStream is = SystemUtils.class.getResourceAsStream(JAI_REGISTRY_PATH);
   if (is != null) {
     // Suppress ugly (and harmless) JAI error messages saying that a descriptor is already
     // registered.
     final PrintStream oldErr = System.err;
     try {
       setSystemErr(new PrintStream(new ByteArrayOutputStream()));
       operationRegistry.updateFromStream(is);
       operationRegistry.registerServices(cl);
       JAI.getDefaultInstance().setOperationRegistry(operationRegistry);
     } catch (IOException e) {
       BeamLogManager.getSystemLogger()
           .log(
               Level.SEVERE,
               MessageFormat.format("Error loading {0}: {1}", JAI_REGISTRY_PATH, e.getMessage()),
               e);
     } finally {
       setSystemErr(oldErr);
     }
   } else {
     BeamLogManager.getSystemLogger()
         .warning(MessageFormat.format("{0} not found", JAI_REGISTRY_PATH));
   }
   Integer parallelism =
       Integer.getInteger(
           BEAM_PARALLELISM_PROPERTY_NAME, Runtime.getRuntime().availableProcessors());
   JAI.getDefaultInstance().getTileScheduler().setParallelism(parallelism);
   BeamLogManager.getSystemLogger()
       .info(MessageFormat.format("JAI tile scheduler parallelism set to {0}", parallelism));
 }