Use LogAccessor from SF

* Change main classes to use a `LogAccessor` API to simplify code flow
* Fix tests according `LogAccessor` property
* Fix some Sonar smells
This commit is contained in:
Artem Bilan
2020-10-06 13:56:50 -04:00
parent a66e82b0aa
commit c7ff99a4e8
95 changed files with 1165 additions and 1432 deletions

View File

@@ -19,6 +19,8 @@ package org.springframework.integration.redis.inbound;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
@@ -172,13 +174,14 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport
private void handlePopException(Exception e) {
this.listening = false;
if (this.active) {
logger.error("Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval
+ " milliseconds.", e);
logger.error(e, () ->
"Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval
+ " milliseconds.");
publishException(e);
sleepBeforeRecoveryAttempt();
}
else {
logger.debug("Failed to execute listening task. " + e.getClass() + ": " + e.getMessage());
logger.debug(() -> "Failed to execute listening task. " + e.getClass() + ": " + e.getMessage());
}
}
@@ -216,7 +219,6 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport
@SuppressWarnings("unchecked")
private void getRequestSendAndProduceReply(byte[] value, String uuid) {
Message<Object> requestMessage;
if (!this.active) {
this.template.boundListOps(uuid).rightPush(value);
byte[] serialized = StringRedisSerializer.UTF_8.serialize(uuid);
@@ -225,12 +227,38 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport
}
return;
}
Message<Object> requestMessage = prepareRequestMessage(value);
if (requestMessage != null) {
Message<?> replyMessage = sendAndReceiveMessage(requestMessage);
if (replyMessage != null) {
byte[] replyPayload = null;
if (this.extractPayload) {
replyPayload = extractReplyPayload(replyMessage);
}
else {
if (this.serializer != null) {
replyPayload = ((RedisSerializer<Object>) this.serializer).serialize(replyMessage);
}
}
if (replyPayload != null) {
this.template.boundListOps(uuid + QUEUE_NAME_SUFFIX).leftPush(replyPayload);
}
}
}
}
@Nullable
@SuppressWarnings("unchecked")
private Message<Object> prepareRequestMessage(byte[] value) {
Message<Object> requestMessage;
if (this.extractPayload) {
Object payload = value;
if (this.serializer != null) {
payload = this.serializer.deserialize(value);
if (payload == null) {
return;
return null;
}
}
requestMessage = getMessageBuilderFactory().withPayload(payload).build();
@@ -239,28 +267,14 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport
try {
requestMessage = (Message<Object>) this.serializer.deserialize(value);
if (requestMessage == null) {
return;
return null;
}
}
catch (Exception e) {
throw new MessagingException("Deserialization of Message failed.", e);
}
}
Message<?> replyMessage = sendAndReceiveMessage(requestMessage);
if (replyMessage != null) {
byte[] replyPayload = null;
if (this.extractPayload) {
replyPayload = extractReplyPayload(replyMessage);
}
else {
if (this.serializer != null) {
replyPayload = ((RedisSerializer<Object>) this.serializer).serialize(replyMessage);
}
}
if (replyPayload != null) {
this.template.boundListOps(uuid + QUEUE_NAME_SUFFIX).leftPush(replyPayload);
}
}
return requestMessage;
}
@SuppressWarnings("unchecked")
@@ -310,9 +324,7 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport
this.applicationEventPublisher.publishEvent(new RedisExceptionEvent(this, e));
}
else {
if (logger.isDebugEnabled()) {
logger.debug("No application event publisher for exception: " + e.getMessage());
}
logger.debug(() -> "No application event publisher for exception: " + e.getMessage());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 the original author or authors.
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -241,16 +241,17 @@ public class RedisQueueMessageDrivenEndpoint extends MessageProducerSupport
value = this.boundListOperations.leftPop(this.receiveTimeout, TimeUnit.MILLISECONDS);
}
}
catch (Exception e) {
catch (Exception ex) {
this.listening = false;
if (this.active) {
logger.error("Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval
+ " milliseconds.", e);
publishException(e);
logger.error(ex,
"Failed to execute listening task. Will attempt to resubmit in " + this.recoveryInterval
+ " milliseconds.");
publishException(ex);
sleepBeforeRecoveryAttempt();
}
else {
logger.debug("Failed to execute listening task. " + e.getClass() + ": " + e.getMessage());
logger.debug(() -> "Failed to execute listening task. " + ex.getClass() + ": " + ex.getMessage());
}
}
return value;
@@ -285,9 +286,7 @@ public class RedisQueueMessageDrivenEndpoint extends MessageProducerSupport
this.applicationEventPublisher.publishEvent(new RedisExceptionEvent(this, e));
}
else {
if (logger.isDebugEnabled()) {
logger.debug("No application event publisher for exception: " + e.getMessage());
}
logger.debug(() -> "No application event publisher for exception: " + e.getMessage());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,9 +44,9 @@ public class RedisQueueOutboundGateway extends AbstractReplyProducingMessageHand
private static final int TIMEOUT = 1000;
private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator();
private static final IdGenerator DEFAULT_ID_GENERATOR = new AlternativeJdkIdGenerator();
private static final RedisSerializer<String> stringSerializer = new StringRedisSerializer();
private static final RedisSerializer<String> STRING_SERIALIZER = new StringRedisSerializer();
private final RedisTemplate<String, Object> template = new RedisTemplate<>();
@@ -109,19 +109,17 @@ public class RedisQueueOutboundGateway extends AbstractReplyProducingMessageHand
Object beforeSerialization = value;
if (!(value instanceof byte[])) {
if (value instanceof String && !this.serializerExplicitlySet) {
value = stringSerializer.serialize((String) value);
value = STRING_SERIALIZER.serialize((String) value);
}
else {
value = ((RedisSerializer<Object>) this.serializer).serialize(value);
}
}
if (value == null) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Serializer produced null for " + beforeSerialization);
}
this.logger.debug(() -> "Serializer produced null for " + beforeSerialization);
return null;
}
String uuid = defaultIdGenerator.generateId().toString();
String uuid = DEFAULT_ID_GENERATOR.generateId().toString();
byte[] uuidByte = uuid.getBytes();
this.boundListOps.leftPush(uuidByte);