Skip to content

Commit fd0d33b

Browse files
committed
fix: apply spotless on publisher-subscriber design pattern (#2898)
1 parent bb5f9a6 commit fd0d33b

File tree

11 files changed

+49
-44
lines changed

11 files changed

+49
-44
lines changed

publish-subscribe/src/main/java/com/iluwatar/publish/subscribe/App.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,31 @@
1212
import com.iluwatar.publish.subscribe.subscriber.WeatherSubscriber;
1313

1414
/**
15-
* <p>The Publish and Subscribe pattern is a messaging paradigm used in software architecture with
16-
* several key points: <li>Decoupling of publishers and subscribers: Publishers and subscribers
17-
* operate independently, and there's no direct link between them. This enhances the scalability and
18-
* * modularity of applications.</li><li>Event-driven communication: The pattern facilitates
19-
* event-driven architectures by allowing publishers to broadcast events without concerning
20-
* themselves with who receives the events.</li><li>Dynamic subscription: Subscribers can
21-
* dynamically choose to listen for specific events or messages they are interested in, often by
22-
* subscribing to a particular topic or channel.</li><li>Asynchronous processing: The pattern
23-
* inherently supports asynchronous message processing, enabling efficient handling of events and
24-
* improving application responsiveness.</li><li>Scalability: By decoupling senders and receivers,
25-
* the pattern can support a large number of publishers and subscribers, making it suitable for
26-
* scalable systems.</li><li>Flexibility and adaptability: New subscribers or publishers can be
27-
* added to the system without significant changes to the existing components, making the system
28-
* highly adaptable to evolving requirements.</li></p>
15+
* The Publish and Subscribe pattern is a messaging paradigm used in software architecture with
16+
* several key points:
17+
* <li>Decoupling of publishers and subscribers: Publishers and subscribers operate independently,
18+
* and there's no direct link between them. This enhances the scalability and * modularity of
19+
* applications.
20+
* <li>Event-driven communication: The pattern facilitates event-driven architectures by allowing
21+
* publishers to broadcast events without concerning themselves with who receives the events.
22+
* <li>Dynamic subscription: Subscribers can dynamically choose to listen for specific events or
23+
* messages they are interested in, often by subscribing to a particular topic or channel.
24+
* <li>Asynchronous processing: The pattern inherently supports asynchronous message processing,
25+
* enabling efficient handling of events and improving application responsiveness.
26+
* <li>Scalability: By decoupling senders and receivers, the pattern can support a large number of
27+
* publishers and subscribers, making it suitable for scalable systems.
28+
* <li>Flexibility and adaptability: New subscribers or publishers can be added to the system
29+
* without significant changes to the existing components, making the system highly adaptable to
30+
* evolving requirements.
2931
*
30-
* <p>In this example we will create two {@link TopicName}s WEATHER and CUSTOMER_SUPPORT.
31-
* Then we will register those topics in the {@link Publisher}.
32-
* After that we will create two {@link WeatherSubscriber}s to WEATHER {@link Topic}.
33-
* Also, we will create two {@link CustomerSupportSubscriber}s to CUSTOMER_SUPPORT {@link Topic}.
34-
* Now we can publish the two {@link Topic}s with different content in the {@link Message}s.
35-
* And we can observe the output in the log where,
36-
* {@link WeatherSubscriber} will output the message with {@link WeatherContent}.
37-
* {@link CustomerSupportSubscriber} will output the message with {@link CustomerSupportContent}.
38-
* Each subscriber is only listening to the subscribed topic.
32+
* <p>In this example we will create two {@link TopicName}s WEATHER and CUSTOMER_SUPPORT. Then
33+
* we will register those topics in the {@link Publisher}. After that we will create two {@link
34+
* WeatherSubscriber}s to WEATHER {@link Topic}. Also, we will create two {@link
35+
* CustomerSupportSubscriber}s to CUSTOMER_SUPPORT {@link Topic}. Now we can publish the two
36+
* {@link Topic}s with different content in the {@link Message}s. And we can observe the output
37+
* in the log where, {@link WeatherSubscriber} will output the message with {@link
38+
* WeatherContent}. {@link CustomerSupportSubscriber} will output the message with {@link
39+
* CustomerSupportContent}. Each subscriber is only listening to the subscribed topic.
3940
*/
4041
public class App {
4142

@@ -71,4 +72,4 @@ public static void main(String[] args) {
7172
publisher.publish(weatherTopic, new Message(WeatherContent.earthquake));
7273
publisher.publish(supportTopic, new Message(CustomerSupportContent.DE));
7374
}
74-
}
75+
}

publish-subscribe/src/main/java/com/iluwatar/publish/subscribe/model/CustomerSupportContent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/** This enum defines the content for {@link Topic} CUSTOMER_SUPPORT. */
44
public enum CustomerSupportContent {
5-
65
76
87

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.iluwatar.publish.subscribe.model;
22

33
/** This class represents a Message that holds the published content. */
4-
public record Message(Object content) {
5-
}
4+
public record Message(Object content) {}

publish-subscribe/src/main/java/com/iluwatar/publish/subscribe/publisher/Publisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public interface Publisher {
2020
* @param message message with content to be published
2121
*/
2222
void publish(Topic topic, Message message);
23-
}
23+
}

publish-subscribe/src/main/java/com/iluwatar/publish/subscribe/subscriber/CustomerSupportSubscriber.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public void onMessage(Message message) {
2222
if (message.content() instanceof CustomerSupportContent content) {
2323
logger.info("Subscriber: {} sent the email to: {}", subscriberName, content.getEmail());
2424
} else {
25-
logger.error("Unknown content type: {} expected: {}", message.content().getClass(),
25+
logger.error(
26+
"Unknown content type: {} expected: {}",
27+
message.content().getClass(),
2628
CustomerSupportContent.class);
2729
}
2830
}

publish-subscribe/src/main/java/com/iluwatar/publish/subscribe/subscriber/WeatherSubscriber.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public void onMessage(Message message) {
2323
if (message.content() instanceof WeatherContent content) {
2424
logger.info("Subscriber: {} issued message: {}", subscriberName, content.getMessage());
2525
} else {
26-
logger.error("Unknown content type: {} expected: {}", message.content().getClass(),
26+
logger.error(
27+
"Unknown content type: {} expected: {}",
28+
message.content().getClass(),
2729
CustomerSupportContent.class);
2830
}
2931
}

publish-subscribe/src/test/java/com/iluwatar/publish/subscribe/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public class AppTest {
88

99
@Test
1010
void shouldExecuteApplicationWithoutException() {
11-
assertDoesNotThrow(() -> App.main(new String[]{}));
11+
assertDoesNotThrow(() -> App.main(new String[] {}));
1212
}
1313
}

publish-subscribe/src/test/java/com/iluwatar/publish/subscribe/LoggerExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public List<String> getMessages() {
3333
}
3434

3535
public List<String> getFormattedMessages() {
36-
return listAppender.list.stream().map(e -> e.getFormattedMessage())
36+
return listAppender.list.stream()
37+
.map(e -> e.getFormattedMessage())
3738
.collect(Collectors.toList());
3839
}
39-
}
40+
}

publish-subscribe/src/test/java/com/iluwatar/publish/subscribe/model/MessageTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.junit.jupiter.api.Test;
66

7-
87
public class MessageTest {
98

109
@Test

publish-subscribe/src/test/java/com/iluwatar/publish/subscribe/publisher/PublisherTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
public class PublisherTest {
1717

18-
@RegisterExtension
19-
public LoggerExtension loggerExtension = new LoggerExtension();
18+
@RegisterExtension public LoggerExtension loggerExtension = new LoggerExtension();
2019

2120
@Test
2221
void testRegisterTopic() throws NoSuchFieldException, IllegalAccessException {
@@ -52,8 +51,8 @@ void testPublishUnregisteredTopic() {
5251
Topic topicUnregistered = new Topic(TopicName.CUSTOMER_SUPPORT);
5352
Message message = new Message("support");
5453
publisher.publish(topicUnregistered, message);
55-
assertEquals("This topic is not registered: CUSTOMER_SUPPORT",
54+
assertEquals(
55+
"This topic is not registered: CUSTOMER_SUPPORT",
5656
loggerExtension.getFormattedMessages().getFirst());
57-
5857
}
5958
}

0 commit comments

Comments
 (0)