package io.domisum.lib.auxiliumlib.work;

import io.domisum.lib.auxiliumlib.annotations.API;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@API
public class InsertWorkDistributor<T>
	extends WorkDistributor<T>
{
	
	// STATE
	private final List<T> insertWorkQueue = new ArrayList<>();
	
	
	// INSERT
	public synchronized void insert(T work)
	{
		insertWorkQueue.add(work);
	}
	
	@Override
	protected void onClose(ReservedWork<T> work)
	{
		super.onClose(work);
		if(!work.isSuccessful())
			insert(work.getSubject());
	}
	
	
	// REFILL
	@Override
	protected boolean shouldRefill()
	{
		return insertWorkQueue.size() > 0;
	}
	
	@Override
	protected synchronized Collection<T> getMoreWork()
	{
		var moreWork = new ArrayList<>(insertWorkQueue);
		insertWorkQueue.clear();
		return moreWork;
	}
	
}

@@ -163,18 +163,48 @@
 .util.Li
-st
+nkedList;%0Aimport java.util.Queue
 ;%0A%0A@API%0A
@@ -290,24 +290,27 @@
 %0A%09pr
-iva
+otec
 te
+d
  final 
-List
+Queue
 %3CT%3E 
@@ -327,29 +327,30 @@
 Queue = new 
-Array
+Linked
 List%3C%3E();%0A%09%0A

Make InsertWorkDistributor easier to subclass