-
Notifications
You must be signed in to change notification settings - Fork 46
/
Bootstrap.java
86 lines (72 loc) · 3.22 KB
/
Bootstrap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package io.vlingo.xoom.examples.eventjournal;
import io.vlingo.xoom.symbio.store.journal.jdbc.JDBCDispatcherControlDelegate;
import io.vlingo.xoom.symbio.store.journal.jdbc.JDBCJournalInstantWriter;
import org.flywaydb.core.Flyway;
import io.vlingo.xoom.actors.Definition;
import io.vlingo.xoom.actors.World;
import io.vlingo.xoom.examples.eventjournal.counter.Counter;
import io.vlingo.xoom.examples.eventjournal.counter.CounterActor;
import io.vlingo.xoom.examples.eventjournal.counter.CounterQuery;
import io.vlingo.xoom.examples.eventjournal.counter.CounterQueryActor;
import io.vlingo.xoom.examples.eventjournal.interest.NoopConfigurationInterest;
import io.vlingo.xoom.examples.eventjournal.interest.NoopEventJournalDispatcher;
import io.vlingo.xoom.symbio.Entry;
import io.vlingo.xoom.symbio.EntryAdapterProvider;
import io.vlingo.xoom.symbio.store.DataFormat;
import io.vlingo.xoom.symbio.store.common.jdbc.Configuration;
import io.vlingo.xoom.symbio.store.common.jdbc.DatabaseType;
import io.vlingo.xoom.symbio.store.journal.Journal;
import io.vlingo.xoom.symbio.store.journal.JournalReader;
import io.vlingo.xoom.symbio.store.journal.jdbc.JDBCJournalActor;
import java.util.Arrays;
public class Bootstrap {
private static final String DB_URL = "jdbc:postgresql://[::1]:5432/";
private static final String DB_USER = "xoom_test";
private static final String DB_PWD = "xoom123";
private static final String DB_NAME = "xoom_test";
public static void main(String[] args) throws Exception {
Flyway.configure().dataSource(DB_URL, DB_USER, DB_PWD).load().migrate();
final Configuration configuration = new Configuration(
DatabaseType.Postgres,
new NoopConfigurationInterest(),
"org.postgresql.Driver",
DataFormat.Text,
DB_URL,
DB_NAME,
DB_USER,
DB_PWD,
false,
"",
false
);
final World world = World.startWithDefaults("event-journal");
final NoopEventJournalDispatcher journalDispatcher = new NoopEventJournalDispatcher();
Journal<String> journal = Journal.using(world.stage(), JDBCJournalActor.class, journalDispatcher, configuration);
final Counter counter = world.actorFor(
Counter.class,
Definition.has(CounterActor.class, Definition.parameters(DB_NAME, journal))
);
final CounterQuery counterQuery = world.actorFor(
CounterQuery.class,
Definition.has(CounterQueryActor.class, Definition.parameters(journal.journalReader(DB_NAME).<JournalReader<Entry<?>>>await(), new EntryAdapterProvider()))
);
for (int i = 0; i < 5000; i++) {
if (i % 10 == 0) {
counter.decrease();
} else {
counter.increase();
}
pause();
counterQuery.counter().andThenConsume(System.out::println);
}
world.terminate();
}
// This shouldn't be done in production code. It's to simulate some load on the
// reader
static void pause() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}