mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 22:59:43 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
+4
-6
@@ -28,9 +28,9 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* A centralized store for logs. It collects logs from various services and stores them.
|
||||
* This class is thread-safe, ensuring that logs from different services are safely stored
|
||||
* concurrently without data races.
|
||||
* A centralized store for logs. It collects logs from various services and stores them. This class
|
||||
* is thread-safe, ensuring that logs from different services are safely stored concurrently without
|
||||
* data races.
|
||||
*/
|
||||
@Slf4j
|
||||
public class CentralLogStore {
|
||||
@@ -50,9 +50,7 @@ public class CentralLogStore {
|
||||
logs.offer(logEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all logs currently stored in the central log store.
|
||||
*/
|
||||
/** Displays all logs currently stored in the central log store. */
|
||||
public void displayLogs() {
|
||||
LOGGER.info("----- Centralized Logs -----");
|
||||
for (LogEntry logEntry : logs) {
|
||||
|
||||
+16
-17
@@ -32,11 +32,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Responsible for collecting and buffering logs from different services.
|
||||
* Once the logs reach a certain threshold or after a certain time interval,
|
||||
* they are flushed to the central log store. This class ensures logs are collected
|
||||
* and processed asynchronously and efficiently, providing both an immediate collection
|
||||
* and periodic flushing.
|
||||
* Responsible for collecting and buffering logs from different services. Once the logs reach a
|
||||
* certain threshold or after a certain time interval, they are flushed to the central log store.
|
||||
* This class ensures logs are collected and processed asynchronously and efficiently, providing
|
||||
* both an immediate collection and periodic flushing.
|
||||
*/
|
||||
@Slf4j
|
||||
public class LogAggregator {
|
||||
@@ -84,8 +83,7 @@ public class LogAggregator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the log aggregator service and flushes any remaining logs to
|
||||
* the central log store.
|
||||
* Stops the log aggregator service and flushes any remaining logs to the central log store.
|
||||
*
|
||||
* @throws InterruptedException If any thread has interrupted the current thread.
|
||||
*/
|
||||
@@ -106,15 +104,16 @@ public class LogAggregator {
|
||||
}
|
||||
|
||||
private void startBufferFlusher() {
|
||||
executorService.execute(() -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
Thread.sleep(5000); // Flush every 5 seconds.
|
||||
flushBuffer();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
executorService.execute(
|
||||
() -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
Thread.sleep(5000); // Flush every 5 seconds.
|
||||
flushBuffer();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Represents a single log entry, capturing essential details like the service name,
|
||||
* log level, message, and the timestamp when the log was generated.
|
||||
* Represents a single log entry, capturing essential details like the service name, log level,
|
||||
* message, and the timestamp when the log was generated.
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
||||
+9
-6
@@ -25,14 +25,17 @@
|
||||
package com.iluwatar.logaggregation;
|
||||
|
||||
/**
|
||||
* Enum representing different log levels.
|
||||
* Defines the severity of a log message, helping in filtering and prioritization.
|
||||
* Enum representing different log levels. Defines the severity of a log message, helping in
|
||||
* filtering and prioritization.
|
||||
*
|
||||
* <ul>
|
||||
* <li>DEBUG: Detailed information, typically of interest only when diagnosing problems.</li>
|
||||
* <li>INFO: Confirmation that things are working as expected.</li>
|
||||
* <li>ERROR: Indicates a problem that needs attention.</li>
|
||||
* <li>DEBUG: Detailed information, typically of interest only when diagnosing problems.
|
||||
* <li>INFO: Confirmation that things are working as expected.
|
||||
* <li>ERROR: Indicates a problem that needs attention.
|
||||
* </ul>
|
||||
*/
|
||||
public enum LogLevel {
|
||||
DEBUG, INFO, ERROR
|
||||
DEBUG,
|
||||
INFO,
|
||||
ERROR
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Represents a service that produces logs.
|
||||
* The logs are generated based on certain activities or events within the service.
|
||||
* Once a log is generated, it's passed on to the aggregator for further processing.
|
||||
* Represents a service that produces logs. The logs are generated based on certain activities or
|
||||
* events within the service. Once a log is generated, it's passed on to the aggregator for further
|
||||
* processing.
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
|
||||
Reference in New Issue
Block a user