mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 12:59:00 +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:
@@ -51,10 +51,7 @@ package com.iluwatar.databus;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Base for data to send via the Data-Bus.
|
||||
*
|
||||
*/
|
||||
/** Base for data to send via the Data-Bus. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class AbstractDataType implements DataType {
|
||||
|
||||
@@ -35,26 +35,25 @@ import java.time.LocalDateTime;
|
||||
* The Data Bus pattern.
|
||||
*
|
||||
* @see <a href="http://wiki.c2.com/?DataBusPattern">http://wiki.c2.com/?DataBusPattern</a>
|
||||
* <p>The Data-Bus pattern provides a method where different parts of an application may
|
||||
* pass messages between each other without needing to be aware of the other's existence.</p>
|
||||
* <p>The Data-Bus pattern provides a method where different parts of an application may pass
|
||||
* messages between each other without needing to be aware of the other's existence.
|
||||
* <p>Similar to the {@code ObserverPattern}, members register themselves with the {@link
|
||||
* DataBus} and may then receive each piece of data that is published to the Data-Bus. The
|
||||
* member may react to any given message or not.</p>
|
||||
* <p>It allows for Many-to-Many distribution of data, as there may be any number of
|
||||
* publishers to a Data-Bus, and any number of members receiving the data. All members will
|
||||
* receive the same data, the order each receives a given piece of data, is an implementation
|
||||
* detail.</p>
|
||||
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.</p>
|
||||
* <p>This example of the pattern implements a Synchronous Data-Bus, meaning that
|
||||
* when data is published to the Data-Bus, the publish method will not return until all members
|
||||
* have received the data and returned.</p>
|
||||
* <p>The {@link DataBus} class is a Singleton.</p>
|
||||
* <p>Members of the Data-Bus must implement the {@link Member} interface.</p>
|
||||
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.</p>
|
||||
* <p>The {@code data} package contains example {@link DataType} implementations.</p>
|
||||
* <p>The {@code members} package contains example {@link Member} implementations.</p>
|
||||
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message
|
||||
* to the Data-Bus when it receives a message.</p>
|
||||
* member may react to any given message or not.
|
||||
* <p>It allows for Many-to-Many distribution of data, as there may be any number of publishers
|
||||
* to a Data-Bus, and any number of members receiving the data. All members will receive the
|
||||
* same data, the order each receives a given piece of data, is an implementation detail.
|
||||
* <p>Members may unsubscribe from the Data-Bus to stop receiving data.
|
||||
* <p>This example of the pattern implements a Synchronous Data-Bus, meaning that when data is
|
||||
* published to the Data-Bus, the publish method will not return until all members have received
|
||||
* the data and returned.
|
||||
* <p>The {@link DataBus} class is a Singleton.
|
||||
* <p>Members of the Data-Bus must implement the {@link Member} interface.
|
||||
* <p>Data to be published via the Data-Bus must implement the {@link DataType} interface.
|
||||
* <p>The {@code data} package contains example {@link DataType} implementations.
|
||||
* <p>The {@code members} package contains example {@link Member} implementations.
|
||||
* <p>The {@link StatusMember} demonstrates using the DataBus to publish a message to the
|
||||
* Data-Bus when it receives a message.
|
||||
*/
|
||||
class App {
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@ import java.util.Set;
|
||||
/**
|
||||
* The Data-Bus implementation.
|
||||
*
|
||||
* <p>This implementation uses a Singleton.</p>
|
||||
*
|
||||
* <p>This implementation uses a Singleton.
|
||||
*/
|
||||
public class DataBus {
|
||||
|
||||
|
||||
@@ -48,11 +48,7 @@ SOFTWARE.
|
||||
|
||||
package com.iluwatar.databus;
|
||||
|
||||
/**
|
||||
* Events are sent via the Data-Bus.
|
||||
*
|
||||
*/
|
||||
|
||||
/** Events are sent via the Data-Bus. */
|
||||
public interface DataType {
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,10 +50,7 @@ package com.iluwatar.databus;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Members receive events from the Data-Bus.
|
||||
*
|
||||
*/
|
||||
/** Members receive events from the Data-Bus. */
|
||||
public interface Member extends Consumer<DataType> {
|
||||
|
||||
void accept(DataType event);
|
||||
|
||||
@@ -29,10 +29,7 @@ import com.iluwatar.databus.DataType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* An event raised when a string message is sent.
|
||||
*
|
||||
*/
|
||||
/** An event raised when a string message is sent. */
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class MessageData extends AbstractDataType {
|
||||
|
||||
@@ -30,10 +30,7 @@ import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* An event raised when applications starts, containing the start time of the application.
|
||||
*
|
||||
*/
|
||||
/** An event raised when applications starts, containing the start time of the application. */
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class StartingData extends AbstractDataType {
|
||||
|
||||
@@ -30,10 +30,7 @@ import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* An event raised when applications stops, containing the stop time of the application.
|
||||
*
|
||||
*/
|
||||
/** An event raised when applications stops, containing the stop time of the application. */
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class StoppingData extends AbstractDataType {
|
||||
|
||||
@@ -31,10 +31,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Receiver of Data-Bus events that collects the messages from each {@link MessageData}.
|
||||
*
|
||||
*/
|
||||
/** Receiver of Data-Bus events that collects the messages from each {@link MessageData}. */
|
||||
@Slf4j
|
||||
public class MessageCollectorMember implements Member {
|
||||
|
||||
|
||||
@@ -34,10 +34,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Receiver of Data-Bus events.
|
||||
*
|
||||
*/
|
||||
/** Receiver of Data-Bus events. */
|
||||
@Getter
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@@ -69,5 +66,4 @@ public class StatusMember implements Member {
|
||||
LOGGER.info("Receiver {} sending goodbye message", id);
|
||||
data.getDataBus().publish(MessageData.of(String.format("Goodbye cruel world from #%d!", id)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user