Skip to content

Commit

Permalink
[ISSUE #3146]Replace LoggerFactory#getLogger with lombok @slf4j
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm committed Feb 16, 2023
1 parent 959d2b0 commit 7e08a4e
Show file tree
Hide file tree
Showing 162 changed files with 1,107 additions and 1,186 deletions.
5 changes: 4 additions & 1 deletion eventmesh-admin/eventmesh-admin-rocketmq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ dependencies {

implementation project(":eventmesh-connector-plugin:eventmesh-connector-api")

testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation project(":eventmesh-connector-plugin:eventmesh-connector-api")
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.net.httpserver.HttpServer;

public class AdminController {
import lombok.extern.slf4j.Slf4j;

private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
@Slf4j
public class AdminController {

public AdminController() {
}
Expand All @@ -39,6 +38,6 @@ public void run(HttpServer server) throws IOException {

server.createContext(TOPIC_MANAGE_PATH, new TopicsHandler());

logger.info("EventMesh-Admin Controller server context created successfully");
log.info("EventMesh-Admin Controller server context created successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
import java.io.IOException;
import java.io.OutputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TopicsHandler implements HttpHandler {
private static final Logger logger = LoggerFactory.getLogger(TopicsHandler.class);

@Override
public void handle(HttpExchange httpExchange) throws IOException {
Expand All @@ -55,7 +54,7 @@ public void handle(HttpExchange httpExchange) throws IOException {
OutputStream out = httpExchange.getResponseBody();
httpExchange.sendResponseHeaders(500, 0);
String result = String.format("Please check your request url: %s", httpExchange.getRequestURI());
logger.error(result);
log.error(result);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
}

Expand All @@ -69,31 +68,31 @@ public void createTopicHandler(HttpExchange httpExchange) throws IOException {

if (StringUtils.isBlank(topic)) {
result = "Create topic failed. Parameter topic not found.";
logger.error(result);
log.error(result);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
return;
}

//TBD: A new rocketmq service will be implemented for creating topics
TopicResponse topicResponse = null;
if (topicResponse != null) {
logger.info("create a new topic: {}", topic);
log.info("create a new topic: {}", topic);
httpExchange.getResponseHeaders().add(CONTENT_TYPE, APPLICATION_JSON);
NetUtils.sendSuccessResponseHeaders(httpExchange);
result = JsonUtils.toJSONString(topicResponse);
logger.info(result);
log.info(result);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
} else {
httpExchange.sendResponseHeaders(500, 0);
result = TOPIC_ERROR;
logger.error(result);
log.error(result);
out.write(result.getBytes(Constants.DEFAULT_CHARSET));
}
} catch (Exception e) {
httpExchange.getResponseHeaders().add(CONTENT_TYPE, APPLICATION_JSON);
httpExchange.sendResponseHeaders(500, 0);
result = TOPIC_ERROR;
logger.error(result, e);
log.error(result, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@
import java.util.TreeMap;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.extern.slf4j.Slf4j;

import inet.ipaddr.IPAddress;

/**
* Use to map the field clazz and the converter for the field clazz
*/
@Slf4j
public class ConverterMap {

public static final Logger LOGGER = LoggerFactory.getLogger(ConverterMap.class);

private static final ObjectConverter objectConverter = new ObjectConverter();

private static final Map<Class<?>, ConvertValue<?>> classToConverter = new HashMap<>();
Expand Down Expand Up @@ -107,7 +106,7 @@ public static ConvertValue<?> getFieldConverter(Field field) {
ConvertValue<?> convertValue = (ConvertValue<?>) converter1.newInstance();
register(convertValue, converter1);
} catch (Exception e) {
LOGGER.error("The converter failed to register.", e);
log.error("The converter failed to register.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WatchFileManager {
import lombok.extern.slf4j.Slf4j;

private static final Logger LOGGER = LoggerFactory.getLogger(WatchFileManager.class);
@Slf4j
public class WatchFileManager {

private static final AtomicBoolean CLOSED = new AtomicBoolean(false);

private static final Map<String, WatchFileTask> WATCH_FILE_TASK_MAP = new HashMap<>();

static {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOGGER.warn("[WatchFileManager] WatchFileManager closed");
log.warn("[WatchFileManager] WatchFileManager closed");
shutdown();
}));
}
Expand Down Expand Up @@ -63,22 +62,22 @@ private static void shutdown() {
return;
}

if (LOGGER.isInfoEnabled()) {
LOGGER.info("[WatchFileManager] start close");
if (log.isInfoEnabled()) {
log.info("[WatchFileManager] start close");
}

for (Map.Entry<String, WatchFileTask> entry : WATCH_FILE_TASK_MAP.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[WatchFileManager] start to shutdown : {}", entry.getKey());
if (log.isInfoEnabled()) {
log.info("[WatchFileManager] start to shutdown : {}", entry.getKey());
}

try {
entry.getValue().shutdown();
} catch (Exception ex) {
LOGGER.error("[WatchFileManager] shutdown has error : ", ex);
log.error("[WatchFileManager] shutdown has error : ", ex);
}
}
WATCH_FILE_TASK_MAP.clear();
LOGGER.warn("[WatchFileManager] already closed");
log.warn("[WatchFileManager] already closed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WatchFileTask extends Thread {
import lombok.extern.slf4j.Slf4j;

private static final Logger LOGGER = LoggerFactory.getLogger(WatchFileTask.class);
@Slf4j
public class WatchFileTask extends Thread {

private static final FileSystem FILE_SYSTEM = FileSystems.getDefault();

Expand Down Expand Up @@ -89,8 +88,8 @@ public void run() {
for (WatchEvent<?> event : events) {
WatchEvent.Kind<?> kind = event.kind();
if (kind.equals(StandardWatchEventKinds.OVERFLOW)) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("[WatchFileTask] file overflow: {}", event.context());
if (log.isWarnEnabled()) {
log.warn("[WatchFileTask] file overflow: {}", event.context());
}
continue;
}
Expand All @@ -99,12 +98,12 @@ public void run() {
} catch (InterruptedException ex) {
boolean interrupted = Thread.interrupted();
if (interrupted) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("[WatchFileTask] file watch is interrupted");
if (log.isDebugEnabled()) {
log.debug("[WatchFileTask] file watch is interrupted");
}
}
} catch (Exception ex) {
LOGGER.error("[WatchFileTask] an exception occurred during file listening : ", ex);
log.error("[WatchFileTask] an exception occurred during file listening : ", ex);
}
}
}
Expand All @@ -121,7 +120,7 @@ private void precessWatchEvent(WatchEvent<?> event) {
}
}
} catch (Exception ex) {
LOGGER.error("[WatchFileTask] file change event callback error : ", ex);
log.error("[WatchFileTask] file change event callback error : ", ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.extern.slf4j.Slf4j;

/**
* This selector use random strategy.
* Each selection will randomly give one from the given list
*
* @param <T> Target type
*/
@Slf4j
public class RandomLoadBalanceSelector<T> implements LoadBalanceSelector<T> {

private static final Logger LOG = LoggerFactory.getLogger(RandomLoadBalanceSelector.class);

private final transient List<T> clusterGroup;

public RandomLoadBalanceSelector(List<T> clusterGroup) {
Expand All @@ -44,7 +43,7 @@ public RandomLoadBalanceSelector(List<T> clusterGroup) {
@Override
public T select() {
if (CollectionUtils.isEmpty(clusterGroup)) {
LOG.warn("No servers available");
log.warn("No servers available");
return null;
}
return clusterGroup.get(ThreadLocalRandom.current().nextInt(clusterGroup.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.extern.slf4j.Slf4j;

/**
* This selector use the weighted round robin strategy to select from list.
* If the weight is greater, the probability of being selected is larger.
*
* @param <T> Target type
*/
@Slf4j
public class WeightRoundRobinLoadBalanceSelector<T> implements LoadBalanceSelector<T> {

private static final Logger LOG = LoggerFactory.getLogger(WeightRoundRobinLoadBalanceSelector.class);

private final transient List<Weight<T>> clusterGroup;

private final transient int totalWeight;
Expand All @@ -52,7 +51,7 @@ public WeightRoundRobinLoadBalanceSelector(List<Weight<T>> clusterGroup) {
@SuppressWarnings("ConstantConditions")
public T select() {
if (CollectionUtils.isEmpty(clusterGroup)) {
LOG.warn("No servers available");
log.warn("No servers available");
return null;
}
Weight<T> targetWeight = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
import java.util.List;
import java.util.TimeZone;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
Expand All @@ -48,8 +45,10 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.base.Preconditions;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Codec {
private static final Logger LOG = LoggerFactory.getLogger(Codec.class);

private static final int FRAME_MAX_LENGTH = 1024 * 1024 * 4;

Expand Down Expand Up @@ -78,8 +77,8 @@ public void encode(ChannelHandlerContext ctx, Package pkg, ByteBuf out) throws E
Preconditions.checkNotNull(pkg, "TcpPackage cannot be null");
final Header header = pkg.getHeader();
Preconditions.checkNotNull(header, "TcpPackage header cannot be null", header);
if (LOG.isDebugEnabled()) {
LOG.debug("Encoder pkg={}", JsonUtils.toJSONString(pkg));
if (log.isDebugEnabled()) {
log.debug("Encoder pkg={}", JsonUtils.toJSONString(pkg));
}

final byte[] headerData = serializeBytes(OBJECT_MAPPER.writeValueAsString(header));
Expand Down Expand Up @@ -134,7 +133,7 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) thro
Package pkg = new Package(header, body);
out.add(pkg);
} catch (Exception e) {
LOG.error(String.format("decode error| receive: %s.", deserializeBytes(in.array())), e);
log.error(String.format("decode error| receive: %s.", deserializeBytes(in.array())), e);
throw e;
}
}
Expand All @@ -157,8 +156,8 @@ private Header parseHeader(ByteBuf in, int headerLength) throws JsonProcessingEx
}
final byte[] headerData = new byte[headerLength];
in.readBytes(headerData);
if (LOG.isDebugEnabled()) {
LOG.debug("Decode headerJson={}", deserializeBytes(headerData));
if (log.isDebugEnabled()) {
log.debug("Decode headerJson={}", deserializeBytes(headerData));
}
return OBJECT_MAPPER.readValue(deserializeBytes(headerData), Header.class);
}
Expand All @@ -169,8 +168,8 @@ private Object parseBody(ByteBuf in, Header header, int bodyLength) throws JsonP
}
final byte[] bodyData = new byte[bodyLength];
in.readBytes(bodyData);
if (LOG.isDebugEnabled()) {
LOG.debug("Decode bodyJson={}", deserializeBytes(bodyData));
if (log.isDebugEnabled()) {
log.debug("Decode bodyJson={}", deserializeBytes(bodyData));
}
return deserializeBody(deserializeBytes(bodyData), header);
}
Expand Down Expand Up @@ -211,8 +210,8 @@ private static Object deserializeBody(String bodyJsonString, Header header) thro
case REDIRECT_TO_CLIENT:
return OBJECT_MAPPER.readValue(bodyJsonString, RedirectInfo.class);
default:
if (LOG.isWarnEnabled()) {
LOG.warn("Invalidate TCP command: {}", command);
if (log.isWarnEnabled()) {
log.warn("Invalidate TCP command: {}", command);
}
return null;
}
Expand Down
Loading

0 comments on commit 7e08a4e

Please sign in to comment.