Skip to content

Commit c6354c4

Browse files
author
Serdar Hamzaoğulları
committed
- removed optional classes and interfaces in order to simplify the example
- final fields are marked as final - removed unnecessary temp variables - added private constructor for not instantiated static class AccountAggregate - path of te test file is corrected
1 parent 82d7e57 commit c6354c4

22 files changed

+191
-915
lines changed

event-sourcing/etc/event-sourcing.png

-44.4 KB
Loading

event-sourcing/etc/event-sourcing.ucls

+40-180
Large diffs are not rendered by default.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/AccountService.java

-56
This file was deleted.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/MoneyTransactionService.java

-85
This file was deleted.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/SequenceIdGenerator.java

-42
This file was deleted.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/api/EventProcessor.java

-48
This file was deleted.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/api/ProcessorJournal.java

-48
This file was deleted.

event-sourcing/src/main/java/com/iluwatar/event/sourcing/app/App.java

+30-20
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
*/
2323
package com.iluwatar.event.sourcing.app;
2424

25-
import com.iluwatar.event.sourcing.journal.JsonFileJournal;
25+
import com.iluwatar.event.sourcing.event.AccountCreateEvent;
26+
import com.iluwatar.event.sourcing.event.MoneyDepositEvent;
27+
import com.iluwatar.event.sourcing.event.MoneyTransferEvent;
2628
import com.iluwatar.event.sourcing.processor.DomainEventProcessor;
27-
import com.iluwatar.event.sourcing.AccountService;
28-
import com.iluwatar.event.sourcing.MoneyTransactionService;
2929
import com.iluwatar.event.sourcing.state.AccountAggregate;
3030
import java.math.BigDecimal;
31+
import java.util.Date;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

@@ -51,7 +52,13 @@
5152
public class App {
5253

5354
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
55+
/**
56+
* The constant ACCOUNT OF DAENERYS.
57+
*/
5458
public static final int ACCOUNT_OF_DAENERYS = 1;
59+
/**
60+
* The constant ACCOUNT OF JON.
61+
*/
5562
public static final int ACCOUNT_OF_JON = 2;
5663

5764
/**
@@ -61,28 +68,31 @@ public class App {
6168
*/
6269
public static void main(String[] args) {
6370

64-
DomainEventProcessor domainEventProcessor = new DomainEventProcessor();
65-
JsonFileJournal jsonFileJournal = new JsonFileJournal();
66-
domainEventProcessor.setPrecessorJournal(jsonFileJournal);
67-
AccountService accountService = new AccountService(domainEventProcessor);
68-
MoneyTransactionService moneyTransactionService = new MoneyTransactionService(
69-
domainEventProcessor);
71+
DomainEventProcessor eventProcessor = new DomainEventProcessor();
72+
7073

7174
LOGGER.info("Running the system first time............");
72-
jsonFileJournal.reset();
75+
eventProcessor.reset();
7376

7477
LOGGER.info("Creating th accounts............");
7578

76-
accountService.createAccount(ACCOUNT_OF_DAENERYS, "Daenerys Targaryen");
77-
accountService.createAccount(ACCOUNT_OF_JON, "Jon Snow");
79+
eventProcessor.process(new AccountCreateEvent(
80+
0, new Date().getTime(), ACCOUNT_OF_DAENERYS, "Daenerys Targaryen"));
81+
82+
eventProcessor.process(new AccountCreateEvent(
83+
1, new Date().getTime(), ACCOUNT_OF_JON, "Jon Snow"));
7884

7985
LOGGER.info("Do some money operations............");
8086

81-
moneyTransactionService.depositMoney(ACCOUNT_OF_DAENERYS, new BigDecimal("100000"));
82-
moneyTransactionService.depositMoney(ACCOUNT_OF_JON, new BigDecimal("100"));
87+
eventProcessor.process(new MoneyDepositEvent(
88+
2, new Date().getTime(), ACCOUNT_OF_DAENERYS, new BigDecimal("100000")));
89+
90+
eventProcessor.process(new MoneyDepositEvent(
91+
3, new Date().getTime(), ACCOUNT_OF_JON, new BigDecimal("100")));
8392

84-
moneyTransactionService.transferMoney(ACCOUNT_OF_DAENERYS, ACCOUNT_OF_JON, new BigDecimal("10000"));
85-
moneyTransactionService.withdrawalMoney(ACCOUNT_OF_JON, new BigDecimal("1000"));
93+
eventProcessor.process(new MoneyTransferEvent(
94+
4, new Date().getTime(), new BigDecimal("10000"), ACCOUNT_OF_DAENERYS,
95+
ACCOUNT_OF_JON));
8696

8797
LOGGER.info("...............State:............");
8898
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString());
@@ -93,13 +103,13 @@ public static void main(String[] args) {
93103

94104
LOGGER.info("Recover the system by the events in journal file............");
95105

96-
domainEventProcessor = new DomainEventProcessor();
97-
jsonFileJournal = new JsonFileJournal();
98-
domainEventProcessor.setPrecessorJournal(jsonFileJournal);
99-
domainEventProcessor.recover();
106+
eventProcessor = new DomainEventProcessor();
107+
eventProcessor.recover();
100108

101109
LOGGER.info("...............Recovered State:............");
102110
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_DAENERYS).toString());
103111
LOGGER.info(AccountAggregate.getAccount(ACCOUNT_OF_JON).toString());
104112
}
113+
114+
105115
}

0 commit comments

Comments
 (0)