test_class.declarator: store = new MemoryStore()
test_class.modifier: private final
test_class.original_string: private final MemoryStore store = new MemoryStore();
test_class.type: MemoryStore
test_class.var_name: store
test_class.declarator: rootId = store.getRevisions().getHead()
test_class.modifier: private final
test_class.original_string: private final RecordId rootId = store.getRevisions().getHead();
test_class.type: RecordId
test_class.var_name: rootId
test_class.declarator: gcGeneration = GCGeneration.NULL
test_class.modifier: private
test_class.original_string: private GCGeneration gcGeneration = GCGeneration.NULL;
test_class.type: GCGeneration
test_class.var_name: gcGeneration
test_class.declarator: pool = new SegmentBufferWriterPool(
              store.getSegmentIdProvider(),
              store.getReader(),
              "",
              () -> gcGeneration
      )
test_class.modifier: private final
test_class.original_string: private final SegmentBufferWriterPool pool = new SegmentBufferWriterPool(
              store.getSegmentIdProvider(),
              store.getReader(),
              "",
              () -> gcGeneration
      );
test_class.type: SegmentBufferWriterPool
test_class.var_name: pool
test_class.declarator: executors = new ExecutorService[] {
          newSingleThreadExecutor(), newSingleThreadExecutor(), newSingleThreadExecutor()}
test_class.modifier: private final
test_class.original_string: private final ExecutorService[] executors = new ExecutorService[] {
          newSingleThreadExecutor(), newSingleThreadExecutor(), newSingleThreadExecutor()};
test_class.type: ExecutorService[]
test_class.var_name: executors
test_class.file: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBufferWriterPoolTest.java
test_class.identifier: SegmentBufferWriterPoolTest
test_case.body: @Test
      public void testFlush() throws ExecutionException, InterruptedException, IOException {
          GCGeneration gen = pool.getGCGeneration();
          ConcurrentMap<String, SegmentBufferWriter> map1 = newConcurrentMap();
          Future<RecordId> res1 = execute(gen, createOp("a", map1), 0);
          Future<RecordId> res2 = execute(gen, createOp("b", map1), 1);
          Future<RecordId> res3 = execute(gen, createOp("c", map1), 2);
  
          // Give the tasks some time to complete
          sleepUninterruptibly(10, MILLISECONDS);
  
          assertEquals(rootId, res1.get());
          assertEquals(rootId, res2.get());
          assertEquals(rootId, res3.get());
          assertEquals(3, map1.size());
  
          pool.flush(store);
  
          ConcurrentMap<String, SegmentBufferWriter> map2 = newConcurrentMap();
          Future<RecordId> res4 = execute(gen, createOp("a", map2), 0);
          Future<RecordId> res5 = execute(gen, createOp("b", map2), 1);
          Future<RecordId> res6 = execute(gen, createOp("c", map2), 2);
  
          // Give the tasks some time to complete
          sleepUninterruptibly(10, MILLISECONDS);
  
          assertEquals(rootId, res4.get());
          assertEquals(rootId, res5.get());
          assertEquals(rootId, res6.get());
          assertEquals(3, map2.size());
          assertTrue(intersection(newHashSet(map1.values()), newHashSet(map2.values())).isEmpty());
      }
test_case.class_method_signature: SegmentBufferWriterPoolTest.testFlush()
test_case.full_signature: @Test public void testFlush()
test_case.identifier: testFlush
test_case.invocations: getGCGeneration newConcurrentMap execute createOp execute createOp execute createOp sleepUninterruptibly assertEquals get assertEquals get assertEquals get assertEquals size flush newConcurrentMap execute createOp execute createOp execute createOp sleepUninterruptibly assertEquals get assertEquals get assertEquals get assertEquals size assertTrue isEmpty intersection newHashSet values newHashSet values
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFlush()
focal_class.declarator: poolMonitor = new Monitor(true)
focal_class.modifier: private final
focal_class.original_string: private final Monitor poolMonitor = new Monitor(true);
focal_class.type: Monitor
focal_class.var_name: poolMonitor
focal_class.declarator: writers = newHashMap()
focal_class.modifier: private final
focal_class.original_string: private final Map<Object, SegmentBufferWriter> writers = newHashMap();
focal_class.type: Map<Object, SegmentBufferWriter>
focal_class.var_name: writers
focal_class.declarator: borrowed = newHashSet()
focal_class.modifier: private final
focal_class.original_string: private final Set<SegmentBufferWriter> borrowed = newHashSet();
focal_class.type: Set<SegmentBufferWriter>
focal_class.var_name: borrowed
focal_class.declarator: disposed = newHashSet()
focal_class.modifier: private final
focal_class.original_string: private final Set<SegmentBufferWriter> disposed = newHashSet();
focal_class.type: Set<SegmentBufferWriter>
focal_class.var_name: disposed
focal_class.declarator: idProvider
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final SegmentIdProvider idProvider;
focal_class.type: SegmentIdProvider
focal_class.var_name: idProvider
focal_class.declarator: reader
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final SegmentReader reader;
focal_class.type: SegmentReader
focal_class.var_name: reader
focal_class.declarator: gcGeneration
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final Supplier<GCGeneration> gcGeneration;
focal_class.type: Supplier<GCGeneration>
focal_class.var_name: gcGeneration
focal_class.declarator: wid
focal_class.modifier: @NotNull
      private final
focal_class.original_string: @NotNull
      private final String wid;
focal_class.type: String
focal_class.var_name: wid
focal_class.declarator: writerId = -1
focal_class.modifier: private
focal_class.original_string: private short writerId = -1;
focal_class.type: short
focal_class.var_name: writerId
focal_class.file: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentBufferWriterPool.java
focal_class.identifier: SegmentBufferWriterPool
focal_class.interfaces: implements WriteOperationHandler
focal_class.class_method_signature: SegmentBufferWriterPool.SegmentBufferWriterPool(
              @NotNull SegmentIdProvider idProvider,
              @NotNull SegmentReader reader,
              @NotNull String wid,
              @NotNull Supplier<GCGeneration> gcGeneration)
focal_class.full_signature: public  SegmentBufferWriterPool(
              @NotNull SegmentIdProvider idProvider,
              @NotNull SegmentReader reader,
              @NotNull String wid,
              @NotNull Supplier<GCGeneration> gcGeneration)
focal_class.identifier: SegmentBufferWriterPool
focal_class.modifiers: public
focal_class.parameters: (
              @NotNull SegmentIdProvider idProvider,
              @NotNull SegmentReader reader,
              @NotNull String wid,
              @NotNull Supplier<GCGeneration> gcGeneration)
focal_class.signature:  SegmentBufferWriterPool(
              @NotNull SegmentIdProvider idProvider,
              @NotNull SegmentReader reader,
              @NotNull String wid,
              @NotNull Supplier<GCGeneration> gcGeneration)
focal_class.class_method_signature: SegmentBufferWriterPool.getGCGeneration()
focal_class.full_signature: @Override @NotNull public GCGeneration getGCGeneration()
focal_class.identifier: getGCGeneration
focal_class.modifiers: @Override @NotNull public
focal_class.parameters: ()
focal_class.return: GCGeneration
focal_class.signature: GCGeneration getGCGeneration()
focal_class.class_method_signature: SegmentBufferWriterPool.execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.full_signature: @NotNull @Override public RecordId execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.identifier: execute
focal_class.modifiers: @NotNull @Override public
focal_class.parameters: (@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.return: RecordId
focal_class.signature: RecordId execute(@NotNull GCGeneration gcGeneration,
                              @NotNull WriteOperation writeOperation)
focal_class.class_method_signature: SegmentBufferWriterPool.flush(@NotNull SegmentStore store)
focal_class.full_signature: @Override public void flush(@NotNull SegmentStore store)
focal_class.identifier: flush
focal_class.modifiers: @Override public
focal_class.parameters: (@NotNull SegmentStore store)
focal_class.return: void
focal_class.signature: void flush(@NotNull SegmentStore store)
focal_class.class_method_signature: SegmentBufferWriterPool.allReturned(final List<SegmentBufferWriter> toReturn)
focal_class.full_signature: @NotNull private Guard allReturned(final List<SegmentBufferWriter> toReturn)
focal_class.identifier: allReturned
focal_class.modifiers: @NotNull private
focal_class.parameters: (final List<SegmentBufferWriter> toReturn)
focal_class.return: Guard
focal_class.signature: Guard allReturned(final List<SegmentBufferWriter> toReturn)
focal_class.class_method_signature: SegmentBufferWriterPool.safeEnterWhen(Monitor monitor, Guard guard)
focal_class.full_signature: private static boolean safeEnterWhen(Monitor monitor, Guard guard)
focal_class.identifier: safeEnterWhen
focal_class.modifiers: private static
focal_class.parameters: (Monitor monitor, Guard guard)
focal_class.return: boolean
focal_class.signature: boolean safeEnterWhen(Monitor monitor, Guard guard)
focal_class.class_method_signature: SegmentBufferWriterPool.borrowWriter(@NotNull Object key, @NotNull GCGeneration gcGeneration)
focal_class.full_signature: private SegmentBufferWriter borrowWriter(@NotNull Object key, @NotNull GCGeneration gcGeneration)
focal_class.identifier: borrowWriter
focal_class.modifiers: private
focal_class.parameters: (@NotNull Object key, @NotNull GCGeneration gcGeneration)
focal_class.return: SegmentBufferWriter
focal_class.signature: SegmentBufferWriter borrowWriter(@NotNull Object key, @NotNull GCGeneration gcGeneration)
focal_class.class_method_signature: SegmentBufferWriterPool.returnWriter(Object key, SegmentBufferWriter writer)
focal_class.full_signature: private void returnWriter(Object key, SegmentBufferWriter writer)
focal_class.identifier: returnWriter
focal_class.modifiers: private
focal_class.parameters: (Object key, SegmentBufferWriter writer)
focal_class.return: void
focal_class.signature: void returnWriter(Object key, SegmentBufferWriter writer)
focal_class.class_method_signature: SegmentBufferWriterPool.getWriterId(String wid)
focal_class.full_signature: private String getWriterId(String wid)
focal_class.identifier: getWriterId
focal_class.modifiers: private
focal_class.parameters: (String wid)
focal_class.return: String
focal_class.signature: String getWriterId(String wid)
focal_method.body: @Override
      public void flush(@NotNull SegmentStore store) throws IOException {
          List<SegmentBufferWriter> toFlush = newArrayList();
          List<SegmentBufferWriter> toReturn = newArrayList();
  
          poolMonitor.enter();
          try {
              // Collect all writers that are not currently in use and clear
              // the list so they won't get re-used anymore.
              toFlush.addAll(writers.values());
              writers.clear();
  
              // Collect all borrowed writers, which we need to wait for.
              // Clear the list so they will get disposed once returned.
              toReturn.addAll(borrowed);
              borrowed.clear();
          } finally {
              poolMonitor.leave();
          }
  
          // Wait for the return of the borrowed writers. This is the
          // case once all of them appear in the disposed set.
          if (safeEnterWhen(poolMonitor, allReturned(toReturn))) {
              try {
                  // Collect all disposed writers and clear the list to mark them
                  // as flushed.
                  toFlush.addAll(toReturn);
                  disposed.removeAll(toReturn);
              } finally {
                  poolMonitor.leave();
              }
          }
  
          // Call flush from outside the pool monitor to avoid potential
          // deadlocks of that method calling SegmentStore.writeSegment
          for (SegmentBufferWriter writer : toFlush) {
              writer.flush(store);
          }
      }
focal_method.class_method_signature: SegmentBufferWriterPool.flush(@NotNull SegmentStore store)
focal_method.full_signature: @Override public void flush(@NotNull SegmentStore store)
focal_method.identifier: flush
focal_method.invocations: newArrayList newArrayList enter addAll values clear addAll clear leave safeEnterWhen allReturned addAll removeAll leave flush
focal_method.modifiers: @Override public
focal_method.parameters: (@NotNull SegmentStore store)
focal_method.return: void
focal_method.signature: void flush(@NotNull SegmentStore store)