-
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.
refactor: 비즈니스 로직 퍼사드 패턴 분리 & 로깅 로직 분리 (#38)
* chore: update .gitignore * feat: reqCertification 로직에 CF-12872, CF-03002 응답일 때, warn 로깅 추가 * refactor: 불필요 함수형 인터페이스 제거 * refactor: 실행기 / 요청기 객체 성격에 맞게 분리 * refactor: EasyCodef 객체 Facade Pattern 분리 * refactor: 로깅부 로직 분리 * chore: 로깅부 개선 * release: v2.0.0-beta-004
- Loading branch information
Showing
21 changed files
with
493 additions
and
375 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
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.