Skip to content

Commit b67e166

Browse files
authored
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
1 parent 300a8dd commit b67e166

21 files changed

+493
-375
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/src/main/resources/logback-test.xml
12
*.java.hsp
23
*.sonarj
34
*.sw*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<p align="center">
2626
<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>
2727
<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>
28-
<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>
28+
<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>
2929
</p>
3030

3131
<br><br>

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010

1111

1212
group = "io.codef.api"
13-
version = "2.0.0-beta-003"
13+
version = "2.0.0-beta-004"
1414

1515
signing {
1616
useInMemoryPgpKeys(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package io.codef.api;
2+
3+
import io.codef.api.dto.EasyCodefRequest;
4+
import io.codef.api.dto.EasyCodefResponse;
5+
import io.codef.api.facade.SingleReqFacade;
6+
import java.util.concurrent.CompletableFuture;
7+
import java.util.concurrent.Executor;
8+
import java.util.concurrent.Executors;
9+
import java.util.concurrent.ScheduledExecutorService;
10+
import java.util.concurrent.TimeUnit;
11+
12+
// 실행기 관리를 위한 클래스
13+
public class CodefExecutorManager implements AutoCloseable {
14+
private final ScheduledExecutorService scheduler;
15+
private final Executor virtualThreadExecutor;
16+
17+
private CodefExecutorManager(ScheduledExecutorService scheduler, Executor virtualThreadExecutor) {
18+
this.scheduler = scheduler;
19+
this.virtualThreadExecutor = virtualThreadExecutor;
20+
}
21+
22+
public static CodefExecutorManager create() {
23+
return new CodefExecutorManager(
24+
Executors.newScheduledThreadPool(1),
25+
Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory())
26+
);
27+
}
28+
29+
public CompletableFuture<EasyCodefResponse> scheduleRequest(
30+
EasyCodefRequest request,
31+
long delayMs,
32+
SingleReqFacade facade
33+
) {
34+
return scheduleDelayedExecution(delayMs)
35+
.thenComposeAsync(
36+
ignored -> executeRequest(request, facade),
37+
virtualThreadExecutor
38+
);
39+
}
40+
41+
private CompletableFuture<Void> scheduleDelayedExecution(long delayMs) {
42+
CompletableFuture<Void> future = new CompletableFuture<>();
43+
scheduler.schedule(
44+
() -> future.complete(null),
45+
delayMs,
46+
TimeUnit.MILLISECONDS
47+
);
48+
return future;
49+
}
50+
51+
private CompletableFuture<EasyCodefResponse> executeRequest(
52+
EasyCodefRequest request,
53+
SingleReqFacade facade
54+
) {
55+
return CompletableFuture.supplyAsync(
56+
() -> facade.requestProduct(request),
57+
virtualThreadExecutor
58+
);
59+
}
60+
61+
@Override
62+
public void close() {
63+
scheduler.shutdown();
64+
}
65+
}

0 commit comments

Comments
 (0)