Allow consumers to provide their executor service by jonesbusy · Pull Request #637 · oras-project/oras-java
Expand Up
@@ -66,7 +66,7 @@ public final class Registry extends OCI<ContainerRef> {
/**
* The executor service for parallel operations
*/
private ExecutorService executors;
private ExecutorService executorService;
/** * The registries configuration loaded from the environment Expand Down Expand Up @@ -139,6 +139,14 @@ private void setParallelism(int maxConcurrentDownloads) { this.maxConcurrentDownloads = maxConcurrentDownloads; }
/** * Allow consumer to set custom executor service for parallel operations. If not set, a default one will be created with the given parallelism * @param executorService The executor service */ private void setExecutorService(ExecutorService executorService) { this.executorService = executorService; }
/** * Return if this registry is insecure * @return True if insecure Expand Down Expand Up @@ -177,11 +185,13 @@ private void setSkipTlsVerify(boolean skipTlsVerify) { */ private Registry build() { client = HttpClient.Builder.builder().withSkipTlsVerify(skipTlsVerify).build(); executors = Executors.newFixedThreadPool(maxConcurrentDownloads, r -> { Thread t = new Thread(r); t.setName("layer-transfer-worker-%d".formatted(t.getId())); return t; }); if (executorService == null) { executorService = Executors.newFixedThreadPool(maxConcurrentDownloads, r -> { Thread t = new Thread(r); t.setName("layer-transfer-worker-%d".formatted(t.getId())); return t; }); } return this; }
Expand Down Expand Up @@ -220,7 +230,7 @@ public Registry asInsecure() {
@Override public ExecutorService getExecutorService() { return executors; return executorService; }
@Override Expand Down Expand Up @@ -1108,6 +1118,7 @@ public Builder from(Registry registry) { this.registry.setInsecure(registry.insecure); this.registry.setRegistry(registry.registry); this.registry.setSkipTlsVerify(registry.skipTlsVerify); this.registry.setExecutorService(registry.executorService); this.registry.setParallelism(registry.maxConcurrentDownloads); return this; } Expand Down Expand Up @@ -1195,6 +1206,17 @@ public Builder withParallelism(int parallelism) { return this; }
/** * Set the executor service to use for parallel uploads/downloads. By default it uses a parallelism level given by withParallelism() and a fixed thread pool. * Only uses for layers upload/download, not for manifest or index upload/download. * @param executorService The executor service * @return The builder */ public Builder withExecutorService(ExecutorService executorService) { registry.setExecutorService(executorService); return this; }
/** * Set the insecure flag * @param insecure Insecure Expand Down
/** * The registries configuration loaded from the environment Expand Down Expand Up @@ -139,6 +139,14 @@ private void setParallelism(int maxConcurrentDownloads) { this.maxConcurrentDownloads = maxConcurrentDownloads; }
/** * Allow consumer to set custom executor service for parallel operations. If not set, a default one will be created with the given parallelism * @param executorService The executor service */ private void setExecutorService(ExecutorService executorService) { this.executorService = executorService; }
/** * Return if this registry is insecure * @return True if insecure Expand Down Expand Up @@ -177,11 +185,13 @@ private void setSkipTlsVerify(boolean skipTlsVerify) { */ private Registry build() { client = HttpClient.Builder.builder().withSkipTlsVerify(skipTlsVerify).build(); executors = Executors.newFixedThreadPool(maxConcurrentDownloads, r -> { Thread t = new Thread(r); t.setName("layer-transfer-worker-%d".formatted(t.getId())); return t; }); if (executorService == null) { executorService = Executors.newFixedThreadPool(maxConcurrentDownloads, r -> { Thread t = new Thread(r); t.setName("layer-transfer-worker-%d".formatted(t.getId())); return t; }); } return this; }
Expand Down Expand Up @@ -220,7 +230,7 @@ public Registry asInsecure() {
@Override public ExecutorService getExecutorService() { return executors; return executorService; }
@Override Expand Down Expand Up @@ -1108,6 +1118,7 @@ public Builder from(Registry registry) { this.registry.setInsecure(registry.insecure); this.registry.setRegistry(registry.registry); this.registry.setSkipTlsVerify(registry.skipTlsVerify); this.registry.setExecutorService(registry.executorService); this.registry.setParallelism(registry.maxConcurrentDownloads); return this; } Expand Down Expand Up @@ -1195,6 +1206,17 @@ public Builder withParallelism(int parallelism) { return this; }
/** * Set the executor service to use for parallel uploads/downloads. By default it uses a parallelism level given by withParallelism() and a fixed thread pool. * Only uses for layers upload/download, not for manifest or index upload/download. * @param executorService The executor service * @return The builder */ public Builder withExecutorService(ExecutorService executorService) { registry.setExecutorService(executorService); return this; }
/** * Set the insecure flag * @param insecure Insecure Expand Down