@Override
    protected Product doInBackground(com.bc.ceres.core.ProgressMonitor pm) throws Exception {
      final TargetProductSelectorModel model = getTargetProductSelector().getModel();
      pm.beginTask("Writing...", model.isOpenInAppSelected() ? 100 : 95);
      ProgressMonitorList.instance().add(pm); // NESTMOD
      saveTime = 0L;
      Product product = null;
      try {
        // free cache	// NESTMOD
        JAI.getDefaultInstance().getTileCache().flush();
        System.gc();

        executeStartTime = Calendar.getInstance().getTime();
        long t0 = System.currentTimeMillis();
        Operator operator = null;
        if (targetProduct.getProductReader() instanceof OperatorProductReader) {
          final OperatorProductReader opReader =
              (OperatorProductReader) targetProduct.getProductReader();
          if (opReader.getOperatorContext().getOperator() instanceof Output) {
            operator = opReader.getOperatorContext().getOperator();
          }
        }
        if (operator == null) {
          WriteOp writeOp =
              new WriteOp(targetProduct, model.getProductFile(), model.getFormatName());
          writeOp.setDeleteOutputOnFailure(true);
          writeOp.setWriteEntireTileRows(true);
          writeOp.setClearCacheAfterRowWrite(false);
          operator = writeOp;
        }
        final OperatorExecutor executor = OperatorExecutor.create(operator);
        executor.execute(SubProgressMonitor.create(pm, 95));

        saveTime = System.currentTimeMillis() - t0;
        File targetFile = model.getProductFile();
        if (model.isOpenInAppSelected() && targetFile.exists()) {
          product = ProductIO.readProduct(targetFile);
          if (product == null) {
            product = targetProduct; // todo - check - this cannot be ok!!! (nf)
          }
          pm.worked(5);
        }
      } finally {
        // free cache
        JAI.getDefaultInstance().getTileCache().flush();
        System.gc();

        pm.done();
        ProgressMonitorList.instance().remove(pm); // NESTMOD
        if (product != targetProduct) {
          targetProduct.dispose();
        }
      }
      return product;
    }
예제 #2
0
 private void runOperator() throws Exception {
   Map<String, String> parameterMap = getRawParameterMap();
   String operatorName = commandLineArgs.getOperatorName();
   Map<String, Object> parameters = convertParameterMap(operatorName, parameterMap);
   Map<String, Product> sourceProducts = getSourceProductMap();
   Product targetProduct = createOpProduct(operatorName, parameters, sourceProducts);
   // write product only if Operator does not implement the Output interface
   OperatorProductReader opProductReader = null;
   if (targetProduct.getProductReader() instanceof OperatorProductReader) {
     opProductReader = (OperatorProductReader) targetProduct.getProductReader();
   }
   Operator operator =
       opProductReader != null ? opProductReader.getOperatorContext().getOperator() : null;
   if (operator instanceof Output) {
     final OperatorExecutor executor = OperatorExecutor.create(operator);
     executor.execute(ProgressMonitor.NULL);
   } else {
     String filePath = commandLineArgs.getTargetFilePath();
     String formatName = commandLineArgs.getTargetFormatName();
     writeProduct(
         targetProduct, filePath, formatName, commandLineArgs.isClearCacheAfterRowWrite());
   }
   VelocityContext velocityContext = metadataResourceEngine.getVelocityContext();
   if (operator != null) {
     OperatorSpi spi = operator.getSpi();
     velocityContext.put("operator", operator);
     velocityContext.put("operatorSpi", spi);
     velocityContext.put(
         "operatorMetadata", spi.getOperatorClass().getAnnotation(OperatorMetadata.class));
   }
   velocityContext.put("operatorName", operatorName);
   velocityContext.put("parameters", parameters); // Check if we should use parameterMap here (nf)
   velocityContext.put("sourceProduct", sourceProducts.get("sourceProduct"));
   velocityContext.put(
       "sourceProducts", sourceProducts); // Check if we should use an array here (nf)
   velocityContext.put("targetProduct", targetProduct);
   velocityContext.put("targetProducts", new Product[] {targetProduct});
 }