Skip to content

Commit 4b3435c

Browse files
author
Serdar Hamzaoğulları
committed
Code formating
1 parent 64824d6 commit 4b3435c

22 files changed

+1409
-461
lines changed

event-sourcing/etc/.gitkeep

Whitespace-only changes.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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

event-sourcing/src/.gitkeep

Whitespace-only changes.
Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.event.sourcing.api;
224

325
import java.io.Serializable;
@@ -6,36 +28,72 @@
628
* Created by serdarh on 06.08.2017.
729
*/
830
public abstract class DomainEvent implements Serializable {
9-
private final long sequenceId;
10-
private final long createdTime;
11-
private boolean realTime = true;
12-
private final String eventClassName;
13-
14-
public DomainEvent(long sequenceId, long createdTime, String eventClassName) {
15-
this.sequenceId = sequenceId;
16-
this.createdTime = createdTime;
17-
this.eventClassName = eventClassName;
18-
}
19-
20-
public long getSequenceId() {
21-
return sequenceId;
22-
}
23-
24-
public long getCreatedTime() {
25-
return createdTime;
26-
}
27-
28-
public boolean isRealTime() {
29-
return realTime;
30-
}
31-
32-
public void setRealTime(boolean realTime) {
33-
this.realTime = realTime;
34-
}
35-
36-
public abstract void process();
37-
38-
public String getEventClassName() {
39-
return eventClassName;
40-
}
31+
32+
private final long sequenceId;
33+
private final long createdTime;
34+
private final String eventClassName;
35+
private boolean realTime = true;
36+
37+
/**
38+
* Instantiates a new Domain event.
39+
*
40+
* @param sequenceId the sequence id
41+
* @param createdTime the created time
42+
* @param eventClassName the event class name
43+
*/
44+
public DomainEvent(long sequenceId, long createdTime, String eventClassName) {
45+
this.sequenceId = sequenceId;
46+
this.createdTime = createdTime;
47+
this.eventClassName = eventClassName;
48+
}
49+
50+
/**
51+
* Gets sequence id.
52+
*
53+
* @return the sequence id
54+
*/
55+
public long getSequenceId() {
56+
return sequenceId;
57+
}
58+
59+
/**
60+
* Gets created time.
61+
*
62+
* @return the created time
63+
*/
64+
public long getCreatedTime() {
65+
return createdTime;
66+
}
67+
68+
/**
69+
* Is real time boolean.
70+
*
71+
* @return the boolean
72+
*/
73+
public boolean isRealTime() {
74+
return realTime;
75+
}
76+
77+
/**
78+
* Sets real time.
79+
*
80+
* @param realTime the real time
81+
*/
82+
public void setRealTime(boolean realTime) {
83+
this.realTime = realTime;
84+
}
85+
86+
/**
87+
* Process.
88+
*/
89+
public abstract void process();
90+
91+
/**
92+
* Gets event class name.
93+
*
94+
* @return the event class name
95+
*/
96+
public String getEventClassName() {
97+
return eventClassName;
98+
}
4199
}
Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
123
package com.iluwatar.event.sourcing.api;
224

325
/**
426
* Created by serdarh on 06.08.2017.
527
*/
628
public interface EventProcessor {
7-
void process(DomainEvent domainEvent);
8-
void setPrecessorJournal(ProcessorJournal precessorJournal);
9-
void recover();
29+
30+
/**
31+
* Process.
32+
*
33+
* @param domainEvent the domain event
34+
*/
35+
void process(DomainEvent domainEvent);
36+
37+
/**
38+
* Sets precessor journal.
39+
*
40+
* @param precessorJournal the precessor journal
41+
*/
42+
void setPrecessorJournal(ProcessorJournal precessorJournal);
43+
44+
/**
45+
* Recover.
46+
*/
47+
void recover();
1048
}

0 commit comments

Comments
 (0)