Resolves checkstyle errors for event-* (#1070)

* Reduces checkstyle errors in event-aggregator

* Reduces checkstyle errors in event-asynchronous

* Reduces checkstyle errors in event-driven-architecture

* Reduces checkstyle errors in event-queue

* Reduces checkstyle errors in event-sourcing
This commit is contained in:
Anurag Agarwal
2019-11-10 23:07:10 +05:30
committed by Ilkka Seppälä
parent 7c888e8886
commit 5ae2ce6e2e
38 changed files with 208 additions and 229 deletions

View File

@ -42,13 +42,13 @@ import org.slf4j.LoggerFactory;
* transactional data, and maintain full audit trails and history that can enable compensating
* actions.
*
* This App class is an example usage of Event Sourcing pattern. As an example, two bank account is
* created, then some money deposit and transfer actions are taken so a new state of accounts is
* <p>This App class is an example usage of Event Sourcing pattern. As an example, two bank account
* is created, then some money deposit and transfer actions are taken so a new state of accounts is
* created. At that point, state is cleared in order to represent a system shot down. After the shot
* down, system state is recovered by re-creating the past events from event journal. Then state is
* printed so a user can view the last state is same with the state before system shot down.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class App {
@ -86,10 +86,10 @@ public class App {
LOGGER.info("Do some money operations............");
eventProcessor.process(new MoneyDepositEvent(
2, new Date().getTime(), ACCOUNT_OF_DAENERYS, new BigDecimal("100000")));
2, new Date().getTime(), ACCOUNT_OF_DAENERYS, new BigDecimal("100000")));
eventProcessor.process(new MoneyDepositEvent(
3, new Date().getTime(), ACCOUNT_OF_JON, new BigDecimal("100")));
3, new Date().getTime(), ACCOUNT_OF_JON, new BigDecimal("100")));
eventProcessor.process(new MoneyTransferEvent(
4, new Date().getTime(), new BigDecimal("10000"), ACCOUNT_OF_DAENERYS,

View File

@ -32,11 +32,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the Account class that holds the account info, the account number,
* account owner name and money of the account. Account class also have the business logic of events
* that effects this account.
* This is the Account class that holds the account info, the account number, account owner name and
* money of the account. Account class also have the business logic of events that effects this
* account.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class Account {
@ -45,14 +45,15 @@ public class Account {
private final int accountNo;
private final String owner;
private BigDecimal money;
private static final String MSG = "Some external api for only realtime execution could be called here.";
private static final String MSG =
"Some external api for only realtime execution could be called here.";
/**
* Instantiates a new Account.
*
* @param accountNo the account no
* @param owner the owner
* @param owner the owner
*/
public Account(int accountNo, String owner) {
this.accountNo = accountNo;

View File

@ -27,12 +27,11 @@ import com.iluwatar.event.sourcing.domain.Account;
import com.iluwatar.event.sourcing.state.AccountAggregate;
/**
* This is the class that implements account create event.
* Holds the necessary info for an account create event.
* Implements the process function that finds the event related
* domain objects and calls the related domain object's handle event functions
* This is the class that implements account create event. Holds the necessary info for an account
* create event. Implements the process function that finds the event related domain objects and
* calls the related domain object's handle event functions
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class AccountCreateEvent extends DomainEvent {
@ -42,10 +41,10 @@ public class AccountCreateEvent extends DomainEvent {
/**
* Instantiates a new Account create event.
*
* @param sequenceId the sequence id
* @param sequenceId the sequence id
* @param createdTime the created time
* @param accountNo the account no
* @param owner the owner
* @param accountNo the account no
* @param owner the owner
*/
public AccountCreateEvent(long sequenceId, long createdTime, int accountNo, String owner) {
super(sequenceId, createdTime, "AccountCreateEvent");

View File

@ -28,7 +28,7 @@ import java.io.Serializable;
/**
* This is the base class for domain events. All events must extend this class.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public abstract class DomainEvent implements Serializable {
@ -40,8 +40,8 @@ public abstract class DomainEvent implements Serializable {
/**
* Instantiates a new Domain event.
*
* @param sequenceId the sequence id
* @param createdTime the created time
* @param sequenceId the sequence id
* @param createdTime the created time
* @param eventClassName the event class name
*/
public DomainEvent(long sequenceId, long createdTime, String eventClassName) {

View File

@ -28,12 +28,11 @@ import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
/**
* This is the class that implements money deposit event.
* Holds the necessary info for a money deposit event.
* Implements the process function that finds the event related
* domain objects and calls the related domain object's handle event functions
* This is the class that implements money deposit event. Holds the necessary info for a money
* deposit event. Implements the process function that finds the event related domain objects and
* calls the related domain object's handle event functions
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class MoneyDepositEvent extends DomainEvent {
@ -43,10 +42,10 @@ public class MoneyDepositEvent extends DomainEvent {
/**
* Instantiates a new Money deposit event.
*
* @param sequenceId the sequence id
* @param sequenceId the sequence id
* @param createdTime the created time
* @param accountNo the account no
* @param money the money
* @param accountNo the account no
* @param money the money
*/
public MoneyDepositEvent(long sequenceId, long createdTime, int accountNo, BigDecimal money) {
super(sequenceId, createdTime, "MoneyDepositEvent");

View File

@ -28,12 +28,11 @@ import com.iluwatar.event.sourcing.state.AccountAggregate;
import java.math.BigDecimal;
/**
* This is the class that implements money transfer event.
* Holds the necessary info for a money transfer event.
* Implements the process function that finds the event related
* domain objects and calls the related domain object's handle event functions
* This is the class that implements money transfer event. Holds the necessary info for a money
* transfer event. Implements the process function that finds the event related domain objects and
* calls the related domain object's handle event functions
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class MoneyTransferEvent extends DomainEvent {
@ -44,14 +43,14 @@ public class MoneyTransferEvent extends DomainEvent {
/**
* Instantiates a new Money transfer event.
*
* @param sequenceId the sequence id
* @param createdTime the created time
* @param money the money
* @param sequenceId the sequence id
* @param createdTime the created time
* @param money the money
* @param accountNoFrom the account no from
* @param accountNoTo the account no to
* @param accountNoTo the account no to
*/
public MoneyTransferEvent(long sequenceId, long createdTime, BigDecimal money, int accountNoFrom,
int accountNoTo) {
int accountNoTo) {
super(sequenceId, createdTime, "MoneyTransferEvent");
this.money = money;
this.accountNoFrom = accountNoFrom;

View File

@ -26,11 +26,10 @@ package com.iluwatar.event.sourcing.processor;
import com.iluwatar.event.sourcing.event.DomainEvent;
/**
* This is the implementation of event processor.
* All events are processed by this class.
* This processor uses processorJournal to persist and recover events.
* This is the implementation of event processor. All events are processed by this class. This
* processor uses processorJournal to persist and recover events.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class DomainEventProcessor {

View File

@ -43,15 +43,14 @@ import java.util.ArrayList;
import java.util.List;
/**
* This is the implementation of event journal.
* This implementation serialize/deserialize the events with JSON
* and writes/reads them on a Journal.json file at the working directory.
* This is the implementation of event journal. This implementation serialize/deserialize the events
* with JSON and writes/reads them on a Journal.json file at the working directory.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class JsonFileJournal {
private final File aFile;
private final File file;
private final List<String> events = new ArrayList<>();
private int index = 0;
@ -59,10 +58,10 @@ public class JsonFileJournal {
* Instantiates a new Json file journal.
*/
public JsonFileJournal() {
aFile = new File("Journal.json");
if (aFile.exists()) {
file = new File("Journal.json");
if (file.exists()) {
try (BufferedReader input = new BufferedReader(
new InputStreamReader(new FileInputStream(aFile), "UTF-8"))) {
new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
String line;
while ((line = input.readLine()) != null) {
events.add(line);
@ -88,14 +87,14 @@ public class JsonFileJournal {
jsonElement = gson.toJsonTree(domainEvent, AccountCreateEvent.class);
} else if (domainEvent instanceof MoneyDepositEvent) {
jsonElement = gson.toJsonTree(domainEvent, MoneyDepositEvent.class);
} else if (domainEvent instanceof MoneyTransferEvent) {
} else if (domainEvent instanceof MoneyTransferEvent) {
jsonElement = gson.toJsonTree(domainEvent, MoneyTransferEvent.class);
} else {
throw new RuntimeException("Journal Event not recegnized");
}
try (Writer output = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(aFile, true), "UTF-8"))) {
new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"))) {
String eventString = jsonElement.toString();
output.write(eventString + "\r\n");
} catch (IOException e) {
@ -108,7 +107,7 @@ public class JsonFileJournal {
* Reset.
*/
public void reset() {
aFile.delete();
file.delete();
}
@ -135,7 +134,7 @@ public class JsonFileJournal {
domainEvent = gson.fromJson(jsonElement, MoneyDepositEvent.class);
} else if (eventClassName.equals("MoneyTransferEvent")) {
domainEvent = gson.fromJson(jsonElement, MoneyTransferEvent.class);
} else {
} else {
throw new RuntimeException("Journal Event not recegnized");
}

View File

@ -28,10 +28,9 @@ import java.util.HashMap;
import java.util.Map;
/**
* This is the static accounts map holder class.
* This class holds the state of the accounts.
* This is the static accounts map holder class. This class holds the state of the accounts.
*
* Created by Serdar Hamzaogullari on 06.08.2017.
* <p>Created by Serdar Hamzaogullari on 06.08.2017.
*/
public class AccountAggregate {