Java Code Examples for ucar.unidata.io.RandomAccessFile#getGlobalFileCache()

The following examples show how to use ucar.unidata.io.RandomAccessFile#getGlobalFileCache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestGribCollectionsDense.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@AfterClass
static public void after() {
  Grib.setDebugFlags(new DebugFlagsImpl());
  Formatter out = new Formatter(System.out);

  FileCacheIF cache = GribCdmIndex.gribCollectionCache;
  if (cache != null) {
    cache.showTracking(out);
    cache.showCache(out);
    cache.clearCache(false);
  }

  FileCacheIF rafCache = RandomAccessFile.getGlobalFileCache();
  if (rafCache != null) {
    rafCache.showCache(out);
  }

  System.out.printf("            countGC=%7d%n", GribCollectionImmutable.countGC);
  System.out.printf("            countPC=%7d%n", PartitionCollectionImmutable.countPC);
  System.out.printf("    countDataAccess=%7d%n", GribIosp.debugIndexOnlyCount);
  System.out.printf(" total files needed=%7d%n",
      GribCollectionImmutable.countGC + PartitionCollectionImmutable.countPC + GribIosp.debugIndexOnlyCount);

  FileCache.shutdown();
  RandomAccessFile.setGlobalFileCache(null);
  TestDir.checkLeaks();
  RandomAccessFile.setDebugLeaks(false);
}
 
Example 2
Source File: TestGribIndexCreationOther.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@AfterClass
static public void after() {
  Grib.setDebugFlags(new DebugFlagsImpl());
  Formatter out = new Formatter(System.out);

  FileCacheIF cache = GribCdmIndex.gribCollectionCache;
  if (show && cache != null) {
    cache.showTracking(out);
    cache.showCache(out);
    cache.clearCache(false);
  }

  FileCacheIF rafCache = RandomAccessFile.getGlobalFileCache();
  if (show && rafCache != null) {
    rafCache.showCache(out);
  }

  System.out.printf("            countGC=%7d%n", GribCollectionImmutable.countGC);
  System.out.printf("            countPC=%7d%n", PartitionCollectionImmutable.countPC);
  System.out.printf("    countDataAccess=%7d%n", GribIosp.debugIndexOnlyCount);
  System.out.printf(" total files needed=%7d%n",
      GribCollectionImmutable.countGC + PartitionCollectionImmutable.countPC + GribIosp.debugIndexOnlyCount);

  FileCache.shutdown();
  RandomAccessFile.setGlobalFileCache(null);
  TestDir.checkLeaks();
  RandomAccessFile.setDebugLeaks(false);
}
 
Example 3
Source File: TestGribCollectionMissing.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@AfterClass
static public void after() {
  Grib.setDebugFlags(new DebugFlagsImpl());
  Formatter out = new Formatter(System.out);

  FileCacheIF cache = GribCdmIndex.gribCollectionCache;
  if (cache != null) {
    cache.showTracking(out);
    cache.showCache(out);
    cache.clearCache(false);
  }

  FileCacheIF rafCache = RandomAccessFile.getGlobalFileCache();
  if (rafCache != null) {
    rafCache.showCache(out);
  }

  System.out.printf("            countGC=%7d%n", GribCollectionImmutable.countGC);
  System.out.printf("            countPC=%7d%n", PartitionCollectionImmutable.countPC);
  System.out.printf("    countDataAccess=%7d%n", GribIosp.debugIndexOnlyCount);
  System.out.printf(" total files needed=%7d%n",
      GribCollectionImmutable.countGC + PartitionCollectionImmutable.countPC + GribIosp.debugIndexOnlyCount);

  FileCache.shutdown();
  RandomAccessFile.setGlobalFileCache(null);
  TestDir.checkLeaks();
  RandomAccessFile.setDebugLeaks(false);
}
 
Example 4
Source File: TestGribIndexCreation.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@AfterClass
static public void after() {
  Grib.setDebugFlags(new DebugFlagsImpl());
  Formatter out = new Formatter(System.out);

  FileCacheIF cache = GribCdmIndex.gribCollectionCache;
  if (show && cache != null) {
    cache.showTracking(out);
    cache.showCache(out);
    cache.clearCache(false);
  }

  FileCacheIF rafCache = RandomAccessFile.getGlobalFileCache();
  if (show && rafCache != null) {
    rafCache.showCache(out);
  }

  System.out.printf("            countGC=%7d%n", GribCollectionImmutable.countGC);
  System.out.printf("            countPC=%7d%n", PartitionCollectionImmutable.countPC);
  System.out.printf("    countDataAccess=%7d%n", GribIosp.debugIndexOnlyCount);
  System.out.printf(" total files needed=%7d%n",
      GribCollectionImmutable.countGC + PartitionCollectionImmutable.countPC + GribIosp.debugIndexOnlyCount);

  FileCache.shutdown();
  RandomAccessFile.setGlobalFileCache(null);
  TestDir.checkLeaks();
  RandomAccessFile.setDebugLeaks(false);
}
 
Example 5
Source File: TestGribCollectionsBig.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@AfterClass
static public void after() {
  Grib.setDebugFlags(new DebugFlagsImpl());
  Formatter out = new Formatter(System.out);

  FileCacheIF cache = GribCdmIndex.gribCollectionCache;
  if (cache != null) {
    cache.showTracking(out);
    cache.showCache(out);
    cache.clearCache(false);
  }

  FileCacheIF rafCache = RandomAccessFile.getGlobalFileCache();
  if (rafCache != null) {
    rafCache.showCache(out);
  }

  System.out.printf("            countGC=%7d%n", GribCollectionImmutable.countGC);
  System.out.printf("            countPC=%7d%n", PartitionCollectionImmutable.countPC);
  System.out.printf("    countDataAccess=%7d%n", GribIosp.debugIndexOnlyCount);
  System.out.printf(" total files needed=%7d%n",
      GribCollectionImmutable.countGC + PartitionCollectionImmutable.countPC + GribIosp.debugIndexOnlyCount);

  FileCache.shutdown();
  RandomAccessFile.setGlobalFileCache(null);
  TestDir.checkLeaks();
  RandomAccessFile.setDebugLeaks(false);
}
 
Example 6
Source File: TestStationFcOpenFiles.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Before
public void setup() {
  mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
  rafCache = (FileCache) RandomAccessFile.getGlobalFileCache();
  rafCache.clearCache(true);
  if (TestDir.cdmUseBuilders) {
    NetcdfDatasets.getNetcdfFileCache().clearCache(true);
  } else {
    NetcdfDataset.getNetcdfFileCache().clearCache(true);
  }
}
 
Example 7
Source File: TestCompositeStationCollectionsWithCaches.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testOpenFileHandles() throws IOException {

    if (checkRafCache) {
      if (RandomAccessFile.getGlobalFileCache() != null) {
        RandomAccessFile.getGlobalFileCache().enable();
      } else {
        RandomAccessFile.enableDefaultGlobalFileCache();
      }
    } else {
      RandomAccessFile.getGlobalFileCache().clearCache(true);
      RandomAccessFile.shutdown();
      // RandomAccessFile.getGlobalFileCache().disable();
    }


    if (checkNetcdfFileCache) {
      // FeatureCollections still use NetcdfDataset, so work with that cache.
      NetcdfDataset.getNetcdfFileCache().enable();
    } else {
      NetcdfDataset.getNetcdfFileCache().clearCache(true);
      NetcdfDataset.getNetcdfFileCache().disable();
    }

    // open the collection
    String collection = ucar.nc2.ft.point.collection.CompositeDatasetFactory.SCHEME + TestDir.cdmUnitTestDir
        + "/ft/station/gempak/collection_with_missing_station_features/#yyMMdd#.sf$";
    FeatureDataset fds = FeatureDatasetFactoryManager.open(FeatureType.STATION, collection, null, null);
    assertThat(fds instanceof FeatureDatasetPoint);
    FeatureDatasetPoint fdp = (FeatureDatasetPoint) fds;

    // the collection dataset should have one feature collection, and it should
    // be a CompositeStationCollection
    assertThat(fdp.getPointFeatureCollectionList()).hasSize(1);
    DsgFeatureCollection dfc = fdp.getPointFeatureCollectionList().get(0);
    assertThat(dfc instanceof CompositeStationCollection);
    CompositeStationCollection csc = (CompositeStationCollection) dfc;

    // now it gets tricky. We have to tickle the PointFeatureIterator for each station trigger
    // the bug, but the iterator is hidden within the station collection because the collection
    // is made up of multiple files. Here, we use the StationHelper to get at the PointFeatureIterator
    // at the individual file level of the collection.
    StationHelper helper = csc.createStationHelper();
    List<Station> stations = helper.getStations();

    // Ensure the RandomAccessFile cache does not contain any locked files
    if (checkRafCache) {
      testRafCache();
    }

    if (checkNetcdfFileCache) {
      testNetcdfFileCache();
    }

    // Now, iterate over the stations. Each station cycles through one or more files of the collection,
    // and the bug is that the file isn't closed or released if it does not contain the given station.
    for (int station = 0; station < 2; station++) {
      // Get the PointFeatureIterator for the given station
      PointFeatureIterator pointFeatureIterator =
          ((StationTimeSeriesFeature) stations.get(station)).getPointFeatureIterator();
      // all we have to do is call .hasNext(), and if not, the underlying code will cycle through the
      // datasets of the collection but not close them
      pointFeatureIterator.hasNext();
      pointFeatureIterator.close();
    }

    if (checkRafCache) {
      testRafCache();
    }

    if (checkNetcdfFileCache) {
      testNetcdfFileCache();
    }
  }