-
Notifications
You must be signed in to change notification settings - Fork 0
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 #39 from codef-io/develop
release: v2.0.0-beta-004
- Loading branch information
Showing
22 changed files
with
497 additions
and
384 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/src/main/resources/logback-test.xml | ||
*.java.hsp | ||
*.sonarj | ||
*.sw* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.codef.api; | ||
|
||
import io.codef.api.dto.EasyCodefRequest; | ||
import io.codef.api.dto.EasyCodefResponse; | ||
import io.codef.api.facade.SingleReqFacade; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
// 실행기 관리를 위한 클래스 | ||
public class CodefExecutorManager implements AutoCloseable { | ||
private final ScheduledExecutorService scheduler; | ||
private final Executor virtualThreadExecutor; | ||
|
||
private CodefExecutorManager(ScheduledExecutorService scheduler, Executor virtualThreadExecutor) { | ||
this.scheduler = scheduler; | ||
this.virtualThreadExecutor = virtualThreadExecutor; | ||
} | ||
|
||
public static CodefExecutorManager create() { | ||
return new CodefExecutorManager( | ||
Executors.newScheduledThreadPool(1), | ||
Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory()) | ||
); | ||
} | ||
|
||
public CompletableFuture<EasyCodefResponse> scheduleRequest( | ||
EasyCodefRequest request, | ||
long delayMs, | ||
SingleReqFacade facade | ||
) { | ||
return scheduleDelayedExecution(delayMs) | ||
.thenComposeAsync( | ||
ignored -> executeRequest(request, facade), | ||
virtualThreadExecutor | ||
); | ||
} | ||
|
||
private CompletableFuture<Void> scheduleDelayedExecution(long delayMs) { | ||
CompletableFuture<Void> future = new CompletableFuture<>(); | ||
scheduler.schedule( | ||
() -> future.complete(null), | ||
delayMs, | ||
TimeUnit.MILLISECONDS | ||
); | ||
return future; | ||
} | ||
|
||
private CompletableFuture<EasyCodefResponse> executeRequest( | ||
EasyCodefRequest request, | ||
SingleReqFacade facade | ||
) { | ||
return CompletableFuture.supplyAsync( | ||
() -> facade.requestProduct(request), | ||
virtualThreadExecutor | ||
); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
scheduler.shutdown(); | ||
} | ||
} |
Oops, something went wrong.