Skip to content

Commit

Permalink
fix: 의존성 해결
Browse files Browse the repository at this point in the history
- Hot Fix: 의존성 관련 부분을 해결했습니다.
  • Loading branch information
tidavid1 committed Aug 29, 2024
1 parent 10cf89a commit 2e58dd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.util.List;
import java.util.concurrent.locks.LockSupport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
* 로깅 데이터 전달 목적의 Thread-Safe Queue 구현체로, 생산과 소비 작업을 모두 지원합니다. 이 클래스는 단일 스레드 환경에서 작동하도록 설계되었으며, 효율적인
Expand All @@ -21,8 +19,6 @@
*
* @param <T> 이 큐에 저장되는 요소의 타입
*/
@Primary
@Component
public class LogQueue<T> implements EventProducer<T>, EventConsumer<T> {

// T 타입의 요소를 저장하는 list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

//@Primary
@Scope("prototype")
@Component
public class ReentrantLogQueue<T> implements EventProducer<T>, EventConsumer<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import info.logbat.common.event.EventConsumer;
import info.logbat.common.event.EventProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;

@Component
public class SingleLinkLogQueue<T> implements EventProducer<T>, EventConsumer<T> {

private final SingleLinkedList<T> queue = new SingleLinkedList<>();
private final long timeout;
private final int bulkSize;

public SingleLinkLogQueue(@Value("${jdbc.async.timeout}") Long timeout,
@Value("${jdbc.async.bulk-size}") Integer bulkSize) {
@Value("${jdbc.async.bulk-size}") Integer bulkSize) {
this.timeout = timeout;
this.bulkSize = bulkSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.function.Consumer;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
Expand All @@ -26,13 +27,16 @@ public class AsyncMultiProcessor<E> implements EventProducer<E> {
private final List<ExecutorService> flatterExecutors;
private Consumer<List<E>> saveFunction;
private final int queueCount;
private final ObjectProvider<ReentrantLogQueue<E>> objectProvider;

public AsyncMultiProcessor(@Value("${queue.count:3}") int queueCount,
@Value("${jdbc.async.timeout:5000}") Long timeout,
@Value("${jdbc.async.bulk-size:3000}") Integer bulkSize, JdbcTemplate jdbcTemplate) {
@Value("${jdbc.async.bulk-size:3000}") Integer bulkSize, JdbcTemplate jdbcTemplate,
ObjectProvider<ReentrantLogQueue<E>> objectProvider) {
this.queueCount = queueCount;
this.queues = new ArrayList<>(queueCount);
this.flatterExecutors = new ArrayList<>(queueCount);
this.objectProvider = objectProvider;
int poolSize = getPoolSize(jdbcTemplate);
setup(queueCount, timeout, bulkSize, poolSize);
}
Expand All @@ -51,14 +55,12 @@ public void produce(List<E> data) {
}

private void setup(int queueCount, Long timeout, Integer bulkSize, int poolSize) {
ExecutorService followerExecutor = Executors.newFixedThreadPool(poolSize);
ReentrantLogQueue<E> queue = new ReentrantLogQueue<>(timeout, bulkSize);

ReentrantLogQueue<E> queue = objectProvider.getObject(timeout, bulkSize);
for (int i = 0; i < queueCount; i++) {
queues.add(queue);
flatterExecutors.add(Executors.newSingleThreadExecutor());
}
CompletableFuture.runAsync(() -> leaderTask(queue, followerExecutor));
CompletableFuture.runAsync(() -> leaderTask(queue, Executors.newFixedThreadPool(poolSize)));
}

private void leaderTask(ReentrantLogQueue<E> queue, ExecutorService follower) {
Expand Down

0 comments on commit 2e58dd0

Please sign in to comment.