Пример #1
0
 /**
  * Transmogrify the filename
  *
  * @param filename filename
  * @param index which one
  * @return new file name
  */
 protected String processDataFilename(String filename, int index) {
   Hashtable properties = (Hashtable) getProperty(DataSource.PROP_SUBPROPERTIES + index);
   if (properties == null) {
     return filename;
   }
   String httpServer = (String) properties.get(PROP_SERVICE_HTTP);
   if (httpServer != null) {
     return httpServer;
   }
   return filename;
 }
Пример #2
0
  /**
   * Make the adapters for the given list of files
   *
   * @param files Data files
   * @throws Exception When bad things happen
   */
  private void makeAdapters(List files) throws Exception {
    adapters = new ArrayList<RadarAdapter>();
    Hashtable<String, RadarAdapter> oldAdapterMap = fileToAdapter;
    fileToAdapter = new Hashtable<String, RadarAdapter>();

    int cnt = 0;

    final List<String> badFiles = new ArrayList<String>();
    final List<Exception> badExceptions = new ArrayList<Exception>();

    final List<RadarAdapter> goodAdapters = new ArrayList<RadarAdapter>();
    final List<String> goodFiles = new ArrayList<String>();
    visad.util.ThreadManager threadManager =
        new visad.util.ThreadManager("radar data initialization");
    LogUtil.message("Initializing radar files");
    for (Iterator iter = files.iterator(); iter.hasNext(); ) {
      final String filename = iter.next().toString();
      RadarAdapter adapter = (RadarAdapter) oldAdapterMap.get(filename);
      cnt++;
      if (adapter == null) {
        threadManager.addRunnable(
            new visad.util.ThreadManager.MyRunnable() {
              public void run() throws Exception {
                try {
                  RadarAdapter myAdapter = makeRadarAdapter(filename);
                  synchronized (goodAdapters) {
                    goodAdapters.add(myAdapter);
                    goodFiles.add(filename);
                  }
                } catch (Exception e) {
                  synchronized (badExceptions) {
                    badExceptions.add(e);
                    badFiles.add(filename);
                  }
                }
              }
            });
      } else {
        goodAdapters.add(adapter);
        goodFiles.add(filename);
      }
    }

    //        threadManager.debug = true;
    threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount());
    LogUtil.message("");

    for (int i = 0; i < goodAdapters.size(); i++) {
      adapters.add(goodAdapters.get(i));
      fileToAdapter.put(goodFiles.get(i), goodAdapters.get(i));
    }

    if (!badFiles.isEmpty()) {
      StringBuffer buf = new StringBuffer();
      if (badFiles.size() < files.size()) {
        buf.append("<html>");
        buf.append("There were problems reading these files:");
        buf.append("<ul>");
        for (Iterator iterator = badFiles.iterator(); iterator.hasNext(); ) {
          buf.append("<li>");
          buf.append((String) iterator.next());
          buf.append("</li>");
        }
        buf.append("</ul>");
        buf.append("<p>Continue loading good data?<p></html>");
        boolean ok = ucar.unidata.util.GuiUtils.askYesNo("Error reading data", buf.toString());

        badExceptions.get(0).printStackTrace();
        if (ok) {
          files.removeAll(badFiles);
        } else {
          throw new VisADException("error reading files");
        }
      } else {
        throw badExceptions.get(0);
      }
    }
    // clean up any old adapters
    for (String source : oldAdapterMap.keySet()) {
      if (fileToAdapter.get(source) == null) {
        ((RadarAdapter) oldAdapterMap.get(source)).doRemove();
      }
    }
    oldAdapterMap = null;
  }