diff --git a/re-core/pom.xml b/re-core/pom.xml index 46a29b7..9513590 100644 --- a/re-core/pom.xml +++ b/re-core/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 re-core @@ -28,17 +30,23 @@ en-diagram ${enigma.version} - + ${project.groupId} re-cache ${project.version} - + com.g2forge.alexandria ax-log ${alexandria.version} + + + com.g2forge.alexandria + ax-workqueue + ${alexandria.version} + diff --git a/re-core/src/main/java/com/g2forge/reassert/core/algorithm/visitor/ReassertGraphExplorer.java b/re-core/src/main/java/com/g2forge/reassert/core/algorithm/visitor/ReassertGraphExplorer.java index c617b36..b9f2a87 100644 --- a/re-core/src/main/java/com/g2forge/reassert/core/algorithm/visitor/ReassertGraphExplorer.java +++ b/re-core/src/main/java/com/g2forge/reassert/core/algorithm/visitor/ReassertGraphExplorer.java @@ -5,7 +5,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -19,6 +18,9 @@ import com.g2forge.alexandria.java.core.error.HError; import com.g2forge.alexandria.java.core.error.OrThrowable; import com.g2forge.alexandria.java.core.helpers.HCollection; +import com.g2forge.alexandria.workqueue.BasicWorkQueueFactory; +import com.g2forge.alexandria.workqueue.IWorkQueueContext; +import com.g2forge.alexandria.workqueue.IWorkQueueHandler; import com.g2forge.reassert.core.api.IReassertGraphBuilder; import com.g2forge.reassert.core.api.IReassertGraphBuilder.ICallback; import com.g2forge.reassert.core.api.ReassertGraphBuilder; @@ -152,17 +154,18 @@ public Graph createGraph(IOrigins origins) { } protected void extendGraph(final Callback callback, final Graph graph) { - final ArtifactLoadContext context = new ArtifactLoadContext(graph); - final LinkedList> queue = new LinkedList<>(); + final ArtifactLoadContext artifactLoadContext = new ArtifactLoadContext(graph); final Collection failures = new ArrayList<>(); - queue.add(callback); - while (!queue.isEmpty()) { - handle(context, queue, queue.remove(), failures); - } + BasicWorkQueueFactory.create().run(new IWorkQueueHandler>() { + @Override + public void run(IWorkQueueContext> context, IReassertGraphBuilder.ICallback task) { + handle(artifactLoadContext, context, task, failures); + } + }, callback); if (!failures.isEmpty()) throw HError.withSuppressed(new RuntimeException("Failed to load one or more artifacts!"), failures); } - protected void handle(final ArtifactLoadContext loadContext, final Collection> queue, final ICallback callback, final Collection failures) { + protected void handle(final ArtifactLoadContext loadContext, final IWorkQueueContext> queueContext, final ICallback callback, final Collection failures) { final List> callbacks = new ArrayList<>(); final Artifact unloadedArtifact = callback.getArtifact(); @@ -191,7 +194,7 @@ protected void handle(final ArtifactLoadConte name = coordinates.toString(); } - log.info(String.format("Starting %1$s with %2$d remaining", name, queue.size())); + log.info(String.format("Starting %1$s with %2$d remaining", name, queueContext.getApproximateQueueSize())); } final ReassertGraphBuilder builder = new ReassertGraphBuilder(loadContext.getGraph(), callbacks); @@ -211,6 +214,6 @@ protected void handle(final ArtifactLoadConte } callback.callback(artifact, builder); - queue.addAll(callbacks); + queueContext.queue(callbacks); } }