Skip to content

Commit

Permalink
refactor: 비즈니스 로직 퍼사드 패턴 분리 & 로깅 로직 분리 (#38)
Browse files Browse the repository at this point in the history
* 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
h-beeen authored Nov 26, 2024
1 parent 300a8dd commit b67e166
Show file tree
Hide file tree
Showing 21 changed files with 493 additions and 375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/src/main/resources/logback-test.xml
*.java.hsp
*.sonarj
*.sw*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<p align="center">
<a href="https://github.com/codef-io/easycodef-java-v2/actions?query=branch%3Amaster"><img align="center" src="https://img.shields.io/github/actions/workflow/status/codef-io/easycodef-java-v2/publish.yml?style=for-the-badge&logo=gradle&color=02303A" alt="Build Status"/></a>
<a href="https://github.com/codef-io/easycodef-java-v2"><img align="center" src="https://img.shields.io/github/last-commit/codef-io/easycodef-java-v2/master?style=for-the-badge&label=LAST%20BUILD&logo=Github&color=181717" alt="Last Commit"/></a>
<a href="https://central.sonatype.com/artifact/io.codef.api/easycodef-java-v2/2.0.0-beta-003"><img align="center" src="https://img.shields.io/maven-central/v/io.codef.api/easycodef-java-v2.svg?style=for-the-badge&label=Maven%20Central&logo=apache-maven&color=C71A36" alt="Maven Central"/></a>
<a href="https://central.sonatype.com/artifact/io.codef.api/easycodef-java-v2/2.0.0-beta-004"><img align="center" src="https://img.shields.io/maven-central/v/io.codef.api/easycodef-java-v2.svg?style=for-the-badge&label=Maven%20Central&logo=apache-maven&color=C71A36" alt="Maven Central"/></a>
</p>

<br><br>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {


group = "io.codef.api"
version = "2.0.0-beta-003"
version = "2.0.0-beta-004"

signing {
useInMemoryPgpKeys(
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/io/codef/api/CodefExecutorManager.java
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();
}
}
Loading

0 comments on commit b67e166

Please sign in to comment.