22
22
*/
23
23
package com .iluwatar .event .sourcing .app ;
24
24
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 ;
26
28
import com .iluwatar .event .sourcing .processor .DomainEventProcessor ;
27
- import com .iluwatar .event .sourcing .AccountService ;
28
- import com .iluwatar .event .sourcing .MoneyTransactionService ;
29
29
import com .iluwatar .event .sourcing .state .AccountAggregate ;
30
30
import java .math .BigDecimal ;
31
+ import java .util .Date ;
31
32
import org .slf4j .Logger ;
32
33
import org .slf4j .LoggerFactory ;
33
34
51
52
public class App {
52
53
53
54
private static final Logger LOGGER = LoggerFactory .getLogger (App .class );
55
+ /**
56
+ * The constant ACCOUNT OF DAENERYS.
57
+ */
54
58
public static final int ACCOUNT_OF_DAENERYS = 1 ;
59
+ /**
60
+ * The constant ACCOUNT OF JON.
61
+ */
55
62
public static final int ACCOUNT_OF_JON = 2 ;
56
63
57
64
/**
@@ -61,28 +68,31 @@ public class App {
61
68
*/
62
69
public static void main (String [] args ) {
63
70
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
+
70
73
71
74
LOGGER .info ("Running the system first time............" );
72
- jsonFileJournal .reset ();
75
+ eventProcessor .reset ();
73
76
74
77
LOGGER .info ("Creating th accounts............" );
75
78
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" ));
78
84
79
85
LOGGER .info ("Do some money operations............" );
80
86
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" )));
83
92
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 ));
86
96
87
97
LOGGER .info ("...............State:............" );
88
98
LOGGER .info (AccountAggregate .getAccount (ACCOUNT_OF_DAENERYS ).toString ());
@@ -93,13 +103,13 @@ public static void main(String[] args) {
93
103
94
104
LOGGER .info ("Recover the system by the events in journal file............" );
95
105
96
- domainEventProcessor = new DomainEventProcessor ();
97
- jsonFileJournal = new JsonFileJournal ();
98
- domainEventProcessor .setPrecessorJournal (jsonFileJournal );
99
- domainEventProcessor .recover ();
106
+ eventProcessor = new DomainEventProcessor ();
107
+ eventProcessor .recover ();
100
108
101
109
LOGGER .info ("...............Recovered State:............" );
102
110
LOGGER .info (AccountAggregate .getAccount (ACCOUNT_OF_DAENERYS ).toString ());
103
111
LOGGER .info (AccountAggregate .getAccount (ACCOUNT_OF_JON ).toString ());
104
112
}
113
+
114
+
105
115
}
0 commit comments