-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Fetched child folder information in parallel
Closes #26
- Loading branch information
1 parent
cb07105
commit 7a58f9b
Showing
9 changed files
with
235 additions
and
30 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
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
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/devatherock/artifactory/config/AppProperties.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,16 @@ | ||
package io.github.devatherock.artifactory.config; | ||
|
||
import io.micronaut.context.annotation.ConfigurationProperties; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@ConfigurationProperties("artifactory.badge") | ||
public class AppProperties { | ||
/** | ||
* Amount of parallelization to use when fetching details about versions of an | ||
* image | ||
*/ | ||
private int parallelism = 5; | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/io/github/devatherock/artifactory/util/ParallelProcessor.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,56 @@ | ||
package io.github.devatherock.artifactory.util; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ParallelProcessor { | ||
private final Executor executor; | ||
private final Semaphore semaphore; // To limit parallelism in case of outbound API calls | ||
|
||
public <T> List<T> parallelProcess(List<Supplier<T>> suppliers) { | ||
Map<Integer, Optional<T>> result = new ConcurrentHashMap<>(); | ||
CountDownLatch countDownLatch = new CountDownLatch(suppliers.size()); | ||
|
||
try { | ||
for (int index = 0; index < suppliers.size(); index++) { | ||
int currentIndex = index; | ||
|
||
semaphore.acquire(); | ||
executor.execute(() -> { | ||
try { | ||
LOGGER.trace("In parallelProcess. Index: {}", currentIndex); | ||
T currentResult = suppliers.get(currentIndex).get(); | ||
result.put(currentIndex, currentResult != null ? Optional.of(currentResult) : Optional.empty()); | ||
} finally { | ||
countDownLatch.countDown(); | ||
semaphore.release(); | ||
} | ||
}); | ||
} | ||
|
||
countDownLatch.await(); | ||
} catch (InterruptedException exception) { | ||
LOGGER.warn("Exception during parallel processing", exception); | ||
} | ||
|
||
return result.entrySet() | ||
.stream() | ||
.sorted(Entry.comparingByKey(Comparator.naturalOrder())) | ||
.map(entry -> entry.getValue().orElse(null)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
Oops, something went wrong.