test_class.file: imhotep-server/src/test/java/com/indeed/imhotep/service/TestCachedFlamdexReader.java
test_class.identifier: TestCachedFlamdexReader
test_case.body: @Test
      public void testClosing() throws FlamdexOutOfMemoryException, IOException {
          final ImhotepMemoryCache<MetricKey, IntValueLookup> cache = new ImhotepMemoryCache<MetricKey, IntValueLookup>();
          final AtomicBoolean closed = new AtomicBoolean(false);
          FlamdexReader r = new SillyFlamdexReader() {
              @Override
              public void close() throws IOException {
                  closed.set(true);
              }
          };
          final MemoryReserver memory = new CachedMemoryReserver(new ImhotepMemoryPool(Long.MAX_VALUE), cache);
          final AtomicSharedReference<CachedFlamdexReader> resource = AtomicSharedReference.create(new CachedFlamdexReader(new MemoryReservationContext(memory), r, null, "test", "test", cache));
          assertFalse(closed.get());
          CachedFlamdexReaderReference cfr2 = new CachedFlamdexReaderReference(resource.get());
          assertFalse(closed.get());
          cfr2.close();
          assertFalse(closed.get());
          for (int i = 2; i < 10; ++i) {
              List<CachedFlamdexReaderReference> l = Lists.newArrayList();
              for (int j = 0; j < i; ++j) {
                  l.add(new CachedFlamdexReaderReference(resource.get()));
                  assertFalse(closed.get());
              }
              for (CachedFlamdexReaderReference cfr : l) {
                  cfr.close();
                  assertFalse(closed.get());
              }
          }
          final CachedFlamdexReaderReference cfr3 = new CachedFlamdexReaderReference(resource.get());
          assertFalse(closed.get());
          resource.unset();
          assertFalse(closed.get());
          cfr3.close();
          assertTrue(closed.get());
  
          closed.set(false);
          r = new SillyFlamdexReader() {
              @Override
              public void close() throws IOException {
                  closed.set(true);
              }
          };
          resource.set(new CachedFlamdexReader(new MemoryReservationContext(memory), r, null, "test", "test", cache));
          cfr2 = new CachedFlamdexReaderReference(resource.get());
          assertFalse(closed.get());
          cfr2.close();
          assertFalse(closed.get());
          resource.set(null);
          assertTrue(closed.get());
      }
test_case.class_method_signature: TestCachedFlamdexReader.testClosing()
test_case.full_signature: @Test public void testClosing()
test_case.identifier: testClosing
test_case.invocations: set create assertFalse get get assertFalse get close assertFalse get newArrayList add get assertFalse get close assertFalse get get assertFalse get unset assertFalse get close assertTrue get set set set get assertFalse get close assertFalse get set assertTrue get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testClosing()
focal_class.declarator: log = Logger.getLogger(CachedFlamdexReader.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = Logger.getLogger(CachedFlamdexReader.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: memory
focal_class.modifier: private final @Nullable
focal_class.original_string: private final @Nullable MemoryReservationContext memory;
focal_class.type: MemoryReservationContext
focal_class.var_name: memory
focal_class.declarator: readLockRef
focal_class.modifier: private final @Nullable
focal_class.original_string: private final @Nullable Closeable readLockRef;
focal_class.type: Closeable
focal_class.var_name: readLockRef
focal_class.declarator: wrapped
focal_class.modifier: private final
focal_class.original_string: private final FlamdexReader wrapped;
focal_class.type: FlamdexReader
focal_class.var_name: wrapped
focal_class.declarator: metricCache
focal_class.modifier: private final
focal_class.original_string: private final MetricCache metricCache;
focal_class.type: MetricCache
focal_class.var_name: metricCache
focal_class.declarator: intDocFreqCache = new ConcurrentHashMap<String, Long>()
focal_class.modifier: private final
focal_class.original_string: private final Map<String, Long> intDocFreqCache = new ConcurrentHashMap<String, Long>();
focal_class.type: Map<String, Long>
focal_class.var_name: intDocFreqCache
focal_class.declarator: stringDocFreqCache = new ConcurrentHashMap<String, Long>()
focal_class.modifier: private final
focal_class.original_string: private final Map<String, Long> stringDocFreqCache = new ConcurrentHashMap<String, Long>();
focal_class.type: Map<String, Long>
focal_class.var_name: stringDocFreqCache
focal_class.file: imhotep-server/src/main/java/com/indeed/imhotep/service/CachedFlamdexReader.java
focal_class.identifier: CachedFlamdexReader
focal_class.interfaces: implements FlamdexReader, MetricCache
focal_class.class_method_signature: CachedFlamdexReader.CachedFlamdexReader(final MemoryReservationContext memory,
                                    final FlamdexReader wrapped,
                                    final @Nullable Closeable readLockRef,
                                    final @Nullable String indexName,
                                    final @Nullable String shardName,
                                    final @Nullable ImhotepMemoryCache<MetricKey, IntValueLookup> freeCache)
focal_class.full_signature: public  CachedFlamdexReader(final MemoryReservationContext memory,
                                    final FlamdexReader wrapped,
                                    final @Nullable Closeable readLockRef,
                                    final @Nullable String indexName,
                                    final @Nullable String shardName,
                                    final @Nullable ImhotepMemoryCache<MetricKey, IntValueLookup> freeCache)
focal_class.identifier: CachedFlamdexReader
focal_class.modifiers: public
focal_class.parameters: (final MemoryReservationContext memory,
                                    final FlamdexReader wrapped,
                                    final @Nullable Closeable readLockRef,
                                    final @Nullable String indexName,
                                    final @Nullable String shardName,
                                    final @Nullable ImhotepMemoryCache<MetricKey, IntValueLookup> freeCache)
focal_class.signature:  CachedFlamdexReader(final MemoryReservationContext memory,
                                    final FlamdexReader wrapped,
                                    final @Nullable Closeable readLockRef,
                                    final @Nullable String indexName,
                                    final @Nullable String shardName,
                                    final @Nullable ImhotepMemoryCache<MetricKey, IntValueLookup> freeCache)
focal_class.class_method_signature: CachedFlamdexReader.getIntFields()
focal_class.full_signature: @Override public Collection<String> getIntFields()
focal_class.identifier: getIntFields
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Collection<String>
focal_class.signature: Collection<String> getIntFields()
focal_class.class_method_signature: CachedFlamdexReader.getStringFields()
focal_class.full_signature: @Override public Collection<String> getStringFields()
focal_class.identifier: getStringFields
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Collection<String>
focal_class.signature: Collection<String> getStringFields()
focal_class.class_method_signature: CachedFlamdexReader.getNumDocs()
focal_class.full_signature: @Override public int getNumDocs()
focal_class.identifier: getNumDocs
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getNumDocs()
focal_class.class_method_signature: CachedFlamdexReader.getDirectory()
focal_class.full_signature: @Override public String getDirectory()
focal_class.identifier: getDirectory
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getDirectory()
focal_class.class_method_signature: CachedFlamdexReader.getDocIdStream()
focal_class.full_signature: @Override public DocIdStream getDocIdStream()
focal_class.identifier: getDocIdStream
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: DocIdStream
focal_class.signature: DocIdStream getDocIdStream()
focal_class.class_method_signature: CachedFlamdexReader.getIntTermIterator(String field)
focal_class.full_signature: @Override public IntTermIterator getIntTermIterator(String field)
focal_class.identifier: getIntTermIterator
focal_class.modifiers: @Override public
focal_class.parameters: (String field)
focal_class.return: IntTermIterator
focal_class.signature: IntTermIterator getIntTermIterator(String field)
focal_class.class_method_signature: CachedFlamdexReader.getStringTermIterator(String field)
focal_class.full_signature: @Override public StringTermIterator getStringTermIterator(String field)
focal_class.identifier: getStringTermIterator
focal_class.modifiers: @Override public
focal_class.parameters: (String field)
focal_class.return: StringTermIterator
focal_class.signature: StringTermIterator getStringTermIterator(String field)
focal_class.class_method_signature: CachedFlamdexReader.getIntTermDocIterator(final String field)
focal_class.full_signature: @Override public IntTermDocIterator getIntTermDocIterator(final String field)
focal_class.identifier: getIntTermDocIterator
focal_class.modifiers: @Override public
focal_class.parameters: (final String field)
focal_class.return: IntTermDocIterator
focal_class.signature: IntTermDocIterator getIntTermDocIterator(final String field)
focal_class.class_method_signature: CachedFlamdexReader.getStringTermDocIterator(final String field)
focal_class.full_signature: @Override public StringTermDocIterator getStringTermDocIterator(final String field)
focal_class.identifier: getStringTermDocIterator
focal_class.modifiers: @Override public
focal_class.parameters: (final String field)
focal_class.return: StringTermDocIterator
focal_class.signature: StringTermDocIterator getStringTermDocIterator(final String field)
focal_class.class_method_signature: CachedFlamdexReader.getIntTotalDocFreq(String field)
focal_class.full_signature: @Override public long getIntTotalDocFreq(String field)
focal_class.identifier: getIntTotalDocFreq
focal_class.modifiers: @Override public
focal_class.parameters: (String field)
focal_class.return: long
focal_class.signature: long getIntTotalDocFreq(String field)
focal_class.class_method_signature: CachedFlamdexReader.getStringTotalDocFreq(String field)
focal_class.full_signature: @Override public long getStringTotalDocFreq(String field)
focal_class.identifier: getStringTotalDocFreq
focal_class.modifiers: @Override public
focal_class.parameters: (String field)
focal_class.return: long
focal_class.signature: long getStringTotalDocFreq(String field)
focal_class.class_method_signature: CachedFlamdexReader.getAvailableMetrics()
focal_class.full_signature: @Override public Collection<String> getAvailableMetrics()
focal_class.identifier: getAvailableMetrics
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Collection<String>
focal_class.signature: Collection<String> getAvailableMetrics()
focal_class.class_method_signature: CachedFlamdexReader.getMetric(String metric)
focal_class.full_signature: @Override public IntValueLookup getMetric(String metric)
focal_class.identifier: getMetric
focal_class.modifiers: @Override public
focal_class.parameters: (String metric)
focal_class.return: IntValueLookup
focal_class.signature: IntValueLookup getMetric(String metric)
focal_class.class_method_signature: CachedFlamdexReader.getStringLookup(final String field)
focal_class.full_signature: public StringValueLookup getStringLookup(final String field)
focal_class.identifier: getStringLookup
focal_class.modifiers: public
focal_class.parameters: (final String field)
focal_class.return: StringValueLookup
focal_class.signature: StringValueLookup getStringLookup(final String field)
focal_class.class_method_signature: CachedFlamdexReader.getMetricDump()
focal_class.full_signature: @Override public List<ImhotepStatusDump.MetricDump> getMetricDump()
focal_class.identifier: getMetricDump
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: List<ImhotepStatusDump.MetricDump>
focal_class.signature: List<ImhotepStatusDump.MetricDump> getMetricDump()
focal_class.class_method_signature: CachedFlamdexReader.getLoadedMetrics()
focal_class.full_signature: @Override public Set<String> getLoadedMetrics()
focal_class.identifier: getLoadedMetrics
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Set<String>
focal_class.signature: Set<String> getLoadedMetrics()
focal_class.class_method_signature: CachedFlamdexReader.memoryRequired(String metric)
focal_class.full_signature: @Override public long memoryRequired(String metric)
focal_class.identifier: memoryRequired
focal_class.modifiers: @Override public
focal_class.parameters: (String metric)
focal_class.return: long
focal_class.signature: long memoryRequired(String metric)
focal_class.class_method_signature: CachedFlamdexReader.close()
focal_class.full_signature: @Override public void close()
focal_class.identifier: close
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void close()
focal_method.body: @Override
      public void close() {
          try {
              if (readLockRef == null) {
                  Closeables2.closeAll(log, metricCache, wrapped);
              } else {
                  Closeables2.closeAll(log, metricCache, wrapped, readLockRef);                
              }
          } finally {
              if (memory == null) {
                  return;
              }
              if (memory.usedMemory() > 0) {
                  log.error("CachedFlamdexReader is leaking! memory reserved after all memory has been freed: "+memory.usedMemory());
              }
              Closeables2.closeQuietly(memory, log);
          }
      }
focal_method.class_method_signature: CachedFlamdexReader.close()
focal_method.full_signature: @Override public void close()
focal_method.identifier: close
focal_method.invocations: closeAll closeAll usedMemory error usedMemory closeQuietly
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void close()