1
+ @startuml
2
+ package com . iluwatar . event . sourcing . journal {
3
+ class JsonFileJournal {
4
+ - aFile : File
5
+ - events : List<String>
6
+ - index : int
7
+ + JsonFileJournal ()
8
+ + readNext () : DomainEvent
9
+ + reset ()
10
+ + write(domainEvent : DomainEvent)
11
+ }
12
+ }
13
+ package com . iluwatar . event . sourcing . processor {
14
+ class DomainEventProcessor {
15
+ - precessorJournal : ProcessorJournal
16
+ + DomainEventProcessor ()
17
+ + process(domainEvent : DomainEvent)
18
+ + recover ()
19
+ + setPrecessorJournal(precessorJournal : ProcessorJournal)
20
+ }
21
+ }
22
+ package com . iluwatar . event . sourcing . service {
23
+ class AccountService {
24
+ - eventProcessor : EventProcessor
25
+ + AccountService(eventProcessor : EventProcessor)
26
+ + createAccount(accountNo : int, owner : String)
27
+ }
28
+ class MoneyTransactionService {
29
+ - eventProcessor : EventProcessor
30
+ + MoneyTransactionService(eventProcessor : EventProcessor)
31
+ + depositMoney(accountNo : int, money : BigDecimal)
32
+ + transferMoney(accountNoFrom : int, accountNoTo : int, money : BigDecimal)
33
+ + withdrawalMoney(accountNo : int, money : BigDecimal)
34
+ }
35
+ class SequenceIdGenerator {
36
+ - sequenceId : long {static}
37
+ + SequenceIdGenerator ()
38
+ + nextSequenceId() : long {static}
39
+ }
40
+ }
41
+ package com . iluwatar . event . sourcing . event {
42
+ class AccountCreateEvent {
43
+ - accountNo : int
44
+ - owner : String
45
+ + AccountCreateEvent(sequenceId : long, createdTime : long, accountNo : int, owner : String)
46
+ + getAccountNo () : int
47
+ + getOwner () : String
48
+ + process ()
49
+ }
50
+ class MoneyDepositEvent {
51
+ - accountNo : int
52
+ - money : BigDecimal
53
+ + MoneyDepositEvent(sequenceId : long, createdTime : long, accountNo : int, money : BigDecimal)
54
+ + getAccountNo () : int
55
+ + getMoney () : BigDecimal
56
+ + process ()
57
+ }
58
+ class MoneyTransferEvent {
59
+ - accountNoFrom : int
60
+ - accountNoTo : int
61
+ - money : BigDecimal
62
+ + MoneyTransferEvent(sequenceId : long, createdTime : long, money : BigDecimal, accountNoFrom : int, accountNoTo : int)
63
+ + getAccountNoFrom () : int
64
+ + getAccountNoTo () : int
65
+ + getMoney () : BigDecimal
66
+ + process ()
67
+ }
68
+ class MoneyWithdrawalEvent {
69
+ - accountNo : int
70
+ - money : BigDecimal
71
+ + MoneyWithdrawalEvent(sequenceId : long, createdTime : long, accountNo : int, money : BigDecimal)
72
+ + getAccountNo () : int
73
+ + getMoney () : BigDecimal
74
+ + process ()
75
+ }
76
+ }
77
+ package com . iluwatar . event . sourcing . gateway {
78
+ class AccountCreateContractSender {
79
+ + AccountCreateContractSender ()
80
+ + sendContractInfo(account : Account)
81
+ }
82
+ class Gateways {
83
+ - accountCreateContractSender : AccountCreateContractSender {static}
84
+ - transactionLogger : TransactionLogger {static}
85
+ + Gateways ()
86
+ + getAccountCreateContractSender() : AccountCreateContractSender {static}
87
+ + getTransactionLogger() : TransactionLogger {static}
88
+ }
89
+ class TransactionLogger {
90
+ + TransactionLogger ()
91
+ + log(transaction : Transaction)
92
+ }
93
+ }
94
+ package com . iluwatar . event . sourcing . app {
95
+ class App {
96
+ + App ()
97
+ + main(args : String[]) {static}
98
+ }
99
+ }
100
+ package com . iluwatar . event . sourcing . state {
101
+ class AccountAggregate {
102
+ - accounts : Map<Integer, Account> {static}
103
+ + AccountAggregate ()
104
+ + getAccount(accountNo : int) : Account {static}
105
+ + putAccount(account : Account) {static}
106
+ + resetState() {static}
107
+ }
108
+ }
109
+ package com . iluwatar . event . sourcing . domain {
110
+ class Account {
111
+ - accountNo : int
112
+ - money : BigDecimal
113
+ - owner : String
114
+ - transactions : List<Transaction>
115
+ + Account(accountNo : int, owner : String)
116
+ + copy () : Account
117
+ - depositMoney(money : BigDecimal) : Transaction
118
+ + getAccountNo () : int
119
+ + getMoney () : BigDecimal
120
+ + getOwner () : String
121
+ + getTransactions() : List<Transaction>
122
+ - handleDeposit(money : BigDecimal, realTime : boolean)
123
+ + handleEvent(accountCreateEvent : AccountCreateEvent)
124
+ + handleEvent(moneyDepositEvent : MoneyDepositEvent)
125
+ + handleEvent(moneyWithdrawalEvent : MoneyWithdrawalEvent)
126
+ + handleTransferFromEvent(moneyTransferEvent : MoneyTransferEvent)
127
+ + handleTransferToEvent(moneyTransferEvent : MoneyTransferEvent)
128
+ - handleWithdrawal(money : BigDecimal, realTime : boolean)
129
+ + setMoney(money : BigDecimal)
130
+ + setTransactions(transactions : List<Transaction>)
131
+ + toString () : String
132
+ - withdrawMoney(money : BigDecimal) : Transaction
133
+ }
134
+ class Transaction {
135
+ - accountNo : int
136
+ - lastBalance : BigDecimal
137
+ - moneyIn : BigDecimal
138
+ - moneyOut : BigDecimal
139
+ + Transaction(accountNo : int, moneyIn : BigDecimal, moneyOut : BigDecimal, lastBalance : BigDecimal)
140
+ + getAccountNo () : int
141
+ + getLastBalance () : BigDecimal
142
+ + getMoneyIn () : BigDecimal
143
+ + getMoneyOut () : BigDecimal
144
+ + toString () : String
145
+ }
146
+ }
147
+ package com . iluwatar . event . sourcing . api {
148
+ abstract class DomainEvent {
149
+ - createdTime : long
150
+ - eventClassName : String
151
+ - realTime : boolean
152
+ - sequenceId : long
153
+ + DomainEvent(sequenceId : long, createdTime : long, eventClassName : String)
154
+ + getCreatedTime () : long
155
+ + getEventClassName () : String
156
+ + getSequenceId () : long
157
+ + isRealTime () : boolean
158
+ + process() {abstract}
159
+ + setRealTime(realTime : boolean)
160
+ }
161
+ interface EventProcessor {
162
+ + process (DomainEvent ) {abstract }
163
+ + recover () {abstract }
164
+ + setPrecessorJournal (ProcessorJournal ) {abstract }
165
+ }
166
+ interface ProcessorJournal {
167
+ + readNext () : DomainEvent {abstract }
168
+ + reset () {abstract }
169
+ + write (DomainEvent ) {abstract }
170
+ }
171
+ }
172
+ Gateways --> "- accountCreateContractSender " AccountCreateContractSender
173
+ DomainEventProcessor --> "- precessorJournal " ProcessorJournal
174
+ Account --> "- transactions " Transaction
175
+ Gateways --> "- transactionLogger " TransactionLogger
176
+ AccountService --> "- eventProcessor " EventProcessor
177
+ MoneyTransactionService --> "- eventProcessor " EventProcessor
178
+ AccountCreateEvent --|> DomainEvent
179
+ MoneyDepositEvent --|> DomainEvent
180
+ MoneyTransferEvent --|> DomainEvent
181
+ MoneyWithdrawalEvent --|> DomainEvent
182
+ JsonFileJournal ..|> ProcessorJournal
183
+ DomainEventProcessor ..|> EventProcessor
184
+ @enduml
0 commit comments