📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -47,22 +47,17 @@ SOFTWARE.
|
||||
|
||||
package com.iluwatar.databus;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Base for data to send via the Data-Bus.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class AbstractDataType implements DataType {
|
||||
|
||||
private DataBus dataBus;
|
||||
|
||||
@Override
|
||||
public DataBus getDataBus() {
|
||||
return dataBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataBus(DataBus dataBus) {
|
||||
this.dataBus = dataBus;
|
||||
}
|
||||
}
|
||||
|
@ -25,24 +25,20 @@ package com.iluwatar.databus.data;
|
||||
|
||||
import com.iluwatar.databus.AbstractDataType;
|
||||
import com.iluwatar.databus.DataType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* An event raised when a string message is sent.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class MessageData extends AbstractDataType {
|
||||
|
||||
private final String message;
|
||||
|
||||
public MessageData(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static DataType of(final String message) {
|
||||
return new MessageData(message);
|
||||
}
|
||||
|
@ -26,24 +26,20 @@ package com.iluwatar.databus.data;
|
||||
import com.iluwatar.databus.AbstractDataType;
|
||||
import com.iluwatar.databus.DataType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* An event raised when applications starts, containing the start time of the application.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class StartingData extends AbstractDataType {
|
||||
|
||||
private final LocalDateTime when;
|
||||
|
||||
public StartingData(LocalDateTime when) {
|
||||
this.when = when;
|
||||
}
|
||||
|
||||
public LocalDateTime getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
public static DataType of(final LocalDateTime when) {
|
||||
return new StartingData(when);
|
||||
}
|
||||
|
@ -26,24 +26,20 @@ package com.iluwatar.databus.data;
|
||||
import com.iluwatar.databus.AbstractDataType;
|
||||
import com.iluwatar.databus.DataType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* An event raised when applications stops, containing the stop time of the application.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class StoppingData extends AbstractDataType {
|
||||
|
||||
private final LocalDateTime when;
|
||||
|
||||
public StoppingData(LocalDateTime when) {
|
||||
this.when = when;
|
||||
}
|
||||
|
||||
public LocalDateTime getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
public static DataType of(final LocalDateTime when) {
|
||||
return new StoppingData(when);
|
||||
}
|
||||
|
@ -28,17 +28,16 @@ import com.iluwatar.databus.Member;
|
||||
import com.iluwatar.databus.data.MessageData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Receiver of Data-Bus events that collects the messages from each {@link MessageData}.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Slf4j
|
||||
public class MessageCollectorMember implements Member {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MessageCollectorMember.class.getName());
|
||||
|
||||
private final String name;
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
@ -55,7 +54,7 @@ public class MessageCollectorMember implements Member {
|
||||
}
|
||||
|
||||
private void handleEvent(MessageData data) {
|
||||
LOGGER.info(String.format("%s sees message %s", name, data.getMessage()));
|
||||
LOGGER.info("{} sees message {}", name, data.getMessage());
|
||||
messages.add(data.getMessage());
|
||||
}
|
||||
|
||||
|
@ -29,27 +29,26 @@ import com.iluwatar.databus.data.MessageData;
|
||||
import com.iluwatar.databus.data.StartingData;
|
||||
import com.iluwatar.databus.data.StoppingData;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Receiver of Data-Bus events.
|
||||
*
|
||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||
*/
|
||||
@Getter
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class StatusMember implements Member {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(StatusMember.class.getName());
|
||||
|
||||
private final int id;
|
||||
|
||||
private LocalDateTime started;
|
||||
|
||||
private LocalDateTime stopped;
|
||||
|
||||
public StatusMember(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(final DataType data) {
|
||||
if (data instanceof StartingData) {
|
||||
@ -61,21 +60,14 @@ public class StatusMember implements Member {
|
||||
|
||||
private void handleEvent(StartingData data) {
|
||||
started = data.getWhen();
|
||||
LOGGER.info(String.format("Receiver #%d sees application started at %s", id, started));
|
||||
LOGGER.info("Receiver {} sees application started at {}", id, started);
|
||||
}
|
||||
|
||||
private void handleEvent(StoppingData data) {
|
||||
stopped = data.getWhen();
|
||||
LOGGER.info(String.format("Receiver #%d sees application stopping at %s", id, stopped));
|
||||
LOGGER.info(String.format("Receiver #%d sending goodbye message", id));
|
||||
LOGGER.info("Receiver {} sees application stopping at {}", id, stopped);
|
||||
LOGGER.info("Receiver {} sending goodbye message", id);
|
||||
data.getDataBus().publish(MessageData.of(String.format("Goodbye cruel world from #%d!", id)));
|
||||
}
|
||||
|
||||
public LocalDateTime getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
public LocalDateTime getStopped() {
|
||||
return stopped;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user