-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from aloubyansky/more-parallel
Platform gen task scheduler API and a bit more of concurrent tasks
- Loading branch information
Showing
7 changed files
with
249 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
bom-decomposer/src/main/java/io/quarkus/bom/task/ConcurrentTaskScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.bom.task; | ||
|
||
import java.util.Collection; | ||
import java.util.Deque; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentLinkedDeque; | ||
import java.util.concurrent.Phaser; | ||
|
||
public class ConcurrentTaskScheduler implements PlatformGenTaskScheduler { | ||
|
||
private final Phaser phaser = new Phaser(1); | ||
private final Deque<Exception> errors = new ConcurrentLinkedDeque<>(); | ||
private final Deque<PlatformGenTask> finalizingTasks = new ConcurrentLinkedDeque<>(); | ||
|
||
@Override | ||
public void schedule(PlatformGenTask task) { | ||
phaser.register(); | ||
CompletableFuture.runAsync(() -> { | ||
try { | ||
task.run(); | ||
} catch (Exception e) { | ||
errors.add(e); | ||
} finally { | ||
phaser.arriveAndDeregister(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void addFinializingTask(PlatformGenTask task) { | ||
finalizingTasks.add(task); | ||
} | ||
|
||
@Override | ||
public void waitForCompletion() throws Exception { | ||
phaser.arriveAndAwaitAdvance(); | ||
for (var t : finalizingTasks) { | ||
t.run(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasErrors() { | ||
return !errors.isEmpty(); | ||
} | ||
|
||
@Override | ||
public Collection<Exception> getErrors() { | ||
return errors; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
bom-decomposer/src/main/java/io/quarkus/bom/task/PlatformGenTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.quarkus.bom.task; | ||
|
||
public interface PlatformGenTask { | ||
void run() throws Exception; | ||
} |
21 changes: 21 additions & 0 deletions
21
bom-decomposer/src/main/java/io/quarkus/bom/task/PlatformGenTaskScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.bom.task; | ||
|
||
import io.quarkus.bom.decomposer.BomDecomposer; | ||
import java.util.Collection; | ||
|
||
public interface PlatformGenTaskScheduler { | ||
|
||
static PlatformGenTaskScheduler getInstance() { | ||
return BomDecomposer.isParallelProcessing() ? new ConcurrentTaskScheduler() : new SequentialTaskScheduler(); | ||
} | ||
|
||
void schedule(PlatformGenTask task) throws Exception; | ||
|
||
void addFinializingTask(PlatformGenTask task) throws Exception; | ||
|
||
void waitForCompletion() throws Exception; | ||
|
||
boolean hasErrors(); | ||
|
||
Collection<Exception> getErrors(); | ||
} |
31 changes: 31 additions & 0 deletions
31
bom-decomposer/src/main/java/io/quarkus/bom/task/SequentialTaskScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.bom.task; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class SequentialTaskScheduler implements PlatformGenTaskScheduler { | ||
|
||
@Override | ||
public void schedule(PlatformGenTask task) throws Exception { | ||
task.run(); | ||
} | ||
|
||
@Override | ||
public void addFinializingTask(PlatformGenTask task) throws Exception { | ||
task.run(); | ||
} | ||
|
||
@Override | ||
public void waitForCompletion() { | ||
} | ||
|
||
@Override | ||
public boolean hasErrors() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Collection<Exception> getErrors() { | ||
return List.of(); | ||
} | ||
} |
Oops, something went wrong.