Skip to content

Commit

Permalink
Polish (#5)
Browse files Browse the repository at this point in the history
- unify usage of logger
- change language in comment (ko -> en)
- add assign not used parameter in constructor
- remove unnecessary `toString()`
- other auto formatting by checkstyle
  • Loading branch information
chanhyeong authored Nov 11, 2022
1 parent 739f8fd commit 758eac3
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ private static synchronized void scanAndInitialize() {
String aggregateRootBasePackage = EventeriaProperties.getAggregateRootBasePackage();
Reflections reflections = new Reflections(aggregateRootBasePackage);
Set<Class<?>> aggregateHandlerTypes = reflections.getTypesAnnotatedWith(AnnotatedAggregateHandler.class, true);
for (Class<?> handlerType : aggregateHandlerTypes) {
if (AggregateRoot.class.isAssignableFrom(handlerType)) {
if (!META_MODELS.containsKey(handlerType)) {
AnnotatedAggregateMetaModel metaModel = AnnotatedAggregateMetaModel.newAggregateMetaModel(
(Class<AggregateRoot>)handlerType);
metaModelMap.put((Class<? extends AggregateRoot>)handlerType, metaModel);
}
}
}

aggregateHandlerTypes.stream()
.filter(AggregateRoot.class::isAssignableFrom)
.filter(handlerType -> !META_MODELS.containsKey(handlerType))
.forEach(handlerType -> {
AnnotatedAggregateMetaModel metaModel = AnnotatedAggregateMetaModel.newAggregateMetaModel(
(Class<AggregateRoot>)handlerType);
metaModelMap.put((Class<? extends AggregateRoot>)handlerType, metaModel);
});

META_MODELS.putAll(metaModelMap);
INITIALIZED = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public FakeKafkaBindingMessageHandler(

@Override
public void handleMessageInternal(org.springframework.messaging.Message<?> message) {
// dlq 는 outbound 를 기록하지 않는다.
// Do not record outbound published for DLQ
if (this.outboundChannelName != null) {
this.kafkaMessageAccumulator.published(
this.outboundChannelName,
Expand Down Expand Up @@ -229,7 +229,7 @@ private void sendToDlq(
@org.springframework.lang.Nullable
private BatchListenerFailedException getBatchListenerFailedException(Throwable throwableArg) {
if (throwableArg == null || throwableArg instanceof BatchListenerFailedException) {
return (BatchListenerFailedException) throwableArg;
return (BatchListenerFailedException)throwableArg;
}

BatchListenerFailedException target = null;
Expand All @@ -241,7 +241,7 @@ private BatchListenerFailedException getBatchListenerFailedException(Throwable t
checked.add(throwable);

if (throwable instanceof BatchListenerFailedException) {
target = (BatchListenerFailedException) throwable;
target = (BatchListenerFailedException)throwable;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void initializeBinding() {
}
});

// 같은 토픽끼리 Channel Binding
// bind channels among the same topics
topicInboundChannels.forEach((key, inboundChannels) -> {
List<FakeBindingSubscribableChannel> outboundChannels =
topicOutboundChannels.getOrDefault(key, Collections.emptyList());
Expand Down Expand Up @@ -168,7 +168,7 @@ private void initializeBinding() {
);
});

// Inbound 채널이 없을 경우 가상 Channel 을 만들어 Binding
// If there is no inbound channel, create a virtual inbound channel and bind
topicOutboundChannels.entrySet().stream()
.filter(entry -> !topicInboundChannels.containsKey(entry.getKey()))
.forEach(entry -> entry.getValue().forEach(outbound -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public FakeKafkaMessageAccumulator() {
this.cloudEventMessageReaderWriter = null;
}

public FakeKafkaMessageAccumulator(CloudEventMessageReaderWriter cloudEventMessageReaderWriter) {
public FakeKafkaMessageAccumulator(@Nullable CloudEventMessageReaderWriter cloudEventMessageReaderWriter) {
this.cloudEventMessageReaderWriter = cloudEventMessageReaderWriter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected AbstractCommand() {
this.id = UUID.randomUUID().toString();
}

// Aggregate 가 아직 만들어지지 않은 대상에 발생시키는 명령은 sourceId 가 없다.
// There is no sourceId in the Command which raises to target that is not created an Aggregate.
protected AbstractCommand(@Nullable String sourceId) {
this.id = UUID.randomUUID().toString();
this.sourceId = sourceId;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void setOccurrenceTime(OffsetDateTime occurrenceTime) {
this.occurrenceTime = occurrenceTime;
}

// Aggregate 가 아직 만들어지지 않은 대상에 발생시키는 명령은 sourceId 가 없다.
// There is no sourceId in the Command which raises to target that is not created an Aggregate.
@Nullable
@Override
public String getSourceId() {
Expand Down Expand Up @@ -216,17 +216,17 @@ public void appendExtension(String extensionName, @Nullable Object extensionValu
this.extensions.put(extensionName.toLowerCase(), extensionValue);
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

protected Map<String, Object> getExtensions() {
if (this.extensions == null) {
this.extensions = new HashMap<>();
}
return this.extensions;
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

@Override
public String getPartitionKey() {
if (this.partitionKey == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ protected SimpleCommand(
this.sourceId = sourceId;
this.sourceVersion = sourceVersion;
this.sourceType = sourceType;
this.dataSchema = dataSchema;
this.subject = subject;
this.partitionKey = partitionKey;
this.correlationId = correlationId;
this.operationId = operationId;
this.payload = payload;
Expand Down Expand Up @@ -291,17 +294,17 @@ public void appendExtension(String extensionName, @Nullable Object extensionValu
this.extensions.put(extensionName.toLowerCase(), extensionValue);
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

protected Map<String, Object> getExtensions() {
if (this.extensions == null) {
this.extensions = new HashMap<>();
}
return this.extensions;
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ protected SimpleEvent(
this.sourceId = sourceId;
this.sourceVersion = sourceVersion;
this.sourceType = sourceType;
this.dataSchema = dataSchema;
this.subject = subject;
this.partitionKey = partitionKey;
this.correlationId = correlationId;
this.operationId = operationId;
this.payload = payload;
Expand Down Expand Up @@ -289,17 +292,17 @@ public void appendExtension(String extensionName, @Nullable Object extensionValu
this.extensions.put(extensionName.toLowerCase(), extensionValue);
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

protected Map<String, Object> getExtensions() {
if (this.extensions == null) {
this.extensions = new HashMap<>();
}
return this.extensions;
}

protected void setExtensions(Map<String, Object> extensions) {
extensions.forEach(this::appendExtension);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@
import org.slf4j.LoggerFactory;

public class EventeriaProperties {
private static final Logger log = LoggerFactory.getLogger(EventeriaProperties.class);
private static final Logger LOG = LoggerFactory.getLogger(EventeriaProperties.class);
private static final String EVENTERIA_META_INF_PROPERTIES = "/META-INF/eventeria.properties";

private static final Properties PROPERTIES;

private static String BASE_PACKAGE;
private static String AGGREGATE_ROOT_BASE_PACKAGE;
private static String EVENT_BASE_PACKAGE;
private static String COMMAND_BASE_PACKAGE;
private static final String BASE_PACKAGE;
private static final String AGGREGATE_ROOT_BASE_PACKAGE;
private static final String EVENT_BASE_PACKAGE;
private static final String COMMAND_BASE_PACKAGE;

static {
Properties properties = new Properties();
try (InputStream propertiesIs = EventeriaProperties.class.getResourceAsStream(EVENTERIA_META_INF_PROPERTIES)) {
if (propertiesIs != null) {
properties.load(propertiesIs);
log.info("Load {}. {}", EVENTERIA_META_INF_PROPERTIES, properties.toString());
LOG.info("Load {}. {}", EVENTERIA_META_INF_PROPERTIES, properties);
}
} catch (IOException e) {
log.error("Can not load properties from " + EVENTERIA_META_INF_PROPERTIES, e);
LOG.error("Can not load properties from " + EVENTERIA_META_INF_PROPERTIES, e);
}

PROPERTIES = properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class CloudEventKafkaTest {
BROKER = new EmbeddedKafkaBroker(1, true, 1)
.kafkaPorts(0)
.brokerProperty(KafkaConfig.OffsetsTopicReplicationFactorProp(), (short)1)
.brokerProperty("transaction.state.log.replication.factor", (short)1)
.brokerProperty("transaction.state.log.min.isr", 1);
.brokerProperty(KafkaConfig.TransactionsTopicReplicationFactorProp(), (short)1)
.brokerProperty(KafkaConfig.TransactionsTopicMinISRProp(), 1);
BROKER.afterPropertiesSet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.navercorp.eventeria.timer.contract.store.TimerMessageStoreValue;

public class RedisCloudEventTimerMessageStore implements TimerMessageStore {
private final Logger logger = LoggerFactory.getLogger(RedisCloudEventTimerMessageStore.class);
private static final Logger LOG = LoggerFactory.getLogger(RedisCloudEventTimerMessageStore.class);

private final String redisKeyPrefix;
private final RedisOperations<String, String> redisIndexOperations;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void remove(UUID storeValueId, @Nullable Integer partition) {
String valueKey = this.generateKey(storeValueId, partition);
this.redisValueOperations.delete(valueKey);
} catch (Exception ex) {
logger.warn("Remove timer message value has error. But it would be ignore. storeValueId: {}, partition: {}",
LOG.warn("Remove timer message value has error. But it would be ignore. storeValueId: {}, partition: {}",
storeValueId, partition, ex);
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ public List<TimerMessageStoreValue> findReleaseValues(
result.add(this.toTimerMessageStoreValue(redisStoreValue));
}
} catch (Throwable throwable) {
logger.error("timer handler persisted value can not be deserialize to cloudEvent. "
LOG.error("timer handler persisted value can not be deserialize to cloudEvent. "
+ "This message would be ignored and deleted from store. "
+ "indexKey: {}, storeValueId: {}, score: {}", indexKey, storeValueId, tuple.getScore(), throwable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public SpecVersion getSpecVersion() {

@Override
public String getId() {
return message.getId().toString();
return message.getId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
import com.navercorp.eventeria.messaging.extension.MessageCategoryExtension.MessageCategory;

public final class DeserializeMessageFailureMessageCategoryFallback implements DeserializeMessageFailureFallback {
private static final Logger logger =
LoggerFactory.getLogger(DeserializeMessageFailureMessageCategoryFallback.class);
private static final Logger LOG = LoggerFactory.getLogger(DeserializeMessageFailureMessageCategoryFallback.class);

private final MessageDeserializer messageDeserializer;

Expand All @@ -45,7 +44,7 @@ public DeserializeMessageFailureMessageCategoryFallback(MessageDeserializer mess

@Override
public Message fallback(CloudEvent cloudEvent, Throwable throwable) {
logger.warn(
LOG.warn(
"Deserialize message is failed. [FALLBACK] deserialize simple message by message category. cloudEvent: {}",
cloudEvent,
throwable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,18 @@

@ParametersAreNonnullByDefault
public final class MessageCategoryExtension implements CloudEventExtension {
private final Logger log = LoggerFactory.getLogger(this.getClass());

public static final String MESSAGE_CATEGORY_EXTENSION = "messagecategory";
public static final Set<String> MESSAGE_CATEGORY_EXTENSION_KEYS = Collections.singleton(MESSAGE_CATEGORY_EXTENSION);
public static final String MESSAGE_CATEGORY_DELIMITER = ",";

public enum MessageCategory {
MESSAGE, COMMAND, EVENT, DOMAIN_EVENT, INTEGRATION_EVENT, TIMER
}

private Set<MessageCategory> messageCategories;
private static final Logger LOG = LoggerFactory.getLogger(MessageCategoryExtension.class);

static {
ExtensionProvider.getInstance()
.registerExtension(MessageCategoryExtension.class, MessageCategoryExtension::new);
}

private Set<MessageCategory> messageCategories;

public static MessageCategoryExtension parseExtension(CloudEventExtensions cloudEventExtensions) {
return ExtensionProvider.getInstance().parseExtension(MessageCategoryExtension.class, cloudEventExtensions);
}
Expand All @@ -77,7 +72,7 @@ public void readFrom(CloudEventExtensions extensions) {
try {
categories.add(MessageCategory.valueOf(category));
} catch (Exception ex) {
log.warn("Can not find MessageCategory enum value. category: {}", category, ex);
LOG.warn("Can not find MessageCategory enum value. category: {}", category, ex);
}
}

Expand Down Expand Up @@ -129,4 +124,8 @@ public String toString() {
+ "messageCategories='" + messageCategories + '\''
+ '}';
}

public enum MessageCategory {
MESSAGE, COMMAND, EVENT, DOMAIN_EVENT, INTEGRATION_EVENT, TIMER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.navercorp.eventeria.timer.contract.store.TimerMessageStoreValue;

public class DistributedTimerMessageHandler implements TimerMessageHandler {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private static final Logger LOG = LoggerFactory.getLogger(DistributedTimerMessageHandler.class);

private final TimerMessageStore timerMessageStore;
private final int countPerRelease;
Expand Down Expand Up @@ -129,7 +129,7 @@ private List<Integer> schedulePersistedMessages(
return;
}

// 추가 처리할 데이터가 더 있기 때문에 reschedule partition 으로 추가합니다.
// add partition to reschedulePartition because there are remaining data to process
if (releaseValues.size() == this.countPerRelease) {
reschedulePartitions.add(partition);
}
Expand All @@ -143,13 +143,13 @@ private List<Integer> schedulePersistedMessages(
this.timerMessageStore.remove(releaseValue.getId(), partition);
successCount++;
} catch (Throwable throwable) {
logger.error("timer handler release message is failed. "
LOG.error("timer handler release message is failed. "
+ "This message would be ignored and retry next scheduling. storeValue: "
+ releaseValue);
}
}

// Message Release 대상 중 release 에 성공한 Message 가 없다면, reschedule 하지 않는다.
// If there is no succeed message among release targets, do not reschedule.
if (successCount == 0 && reschedulePartitions.contains(partition)) {
reschedulePartitions.remove(partition);
}
Expand Down
Loading

0 comments on commit 758eac3

Please sign in to comment.