vlingo / xoom-symbio

The VLINGO XOOM platform SDK delivering Reactive storage that is scalable, high-throughput, and resilient for CQRS, Event Sourcing, Key-Value, and Objects used by services and applications.
https://vlingo.io
Mozilla Public License 2.0
40 stars 9 forks source link

Default Adapters #10

Closed VaughnVernon closed 5 years ago

VaughnVernon commented 5 years ago

Adapters do more than just serialize and deserialize, but at the beginning in most cases you don't need these extra functions as your events have version 1 and upcasting, etc., is not necessary. Therefore, you could have a factory that could be either overridden to create customized Adapters or the factory just comes into play if no custom adapter has been registered.

VaughnVernon commented 5 years ago

The default adapter is working. See the following test that uses Entity2, which does not have a specific StateAdapter registered.

https://github.com/vlingo/vlingo-symbio/blob/e7795eba9baf75f8ac411a901c7c67ac0f180736/src/test/java/io/vlingo/symbio/store/state/inmemory/InMemoryStateStoreTest.java#L244

Also note that although the StateAdapter can now be defaulted (assuming that the state is of type TextState) you must still register the store name:

https://github.com/vlingo/vlingo-symbio/blob/e7795eba9baf75f8ac411a901c7c67ac0f180736/src/test/java/io/vlingo/symbio/store/state/inmemory/InMemoryStateStoreTest.java#L270

sturmm commented 5 years ago

But that now works just with the InMemoryStateStore or does this work for other TextState based stores too?

VaughnVernon commented 5 years ago

It should work for all. Can you please try it and let me know your results?

sturmm commented 5 years ago

I've tested it with the PostgresJournalActor and it does not work. If I skip registration of all Info types containing the Adapters the I'm getting a NPE from the lattice module:

vlingo/actors: DefaultSupervisorOverride: Failure of: Address[id=15, name=(none)]
vlingo/actors: java.lang.NullPointerException
    at io.vlingo.lattice.model.sourcing.Sourced.restore(Sourced.java:353)
    at io.vlingo.lattice.model.sourcing.Sourced.start(Sourced.java:78)
    at io.vlingo.actors.LifeCycle.lambda$sendStart$0(LifeCycle.java:110)
    at io.vlingo.actors.LocalMessage.internalDeliver(LocalMessage.java:116)
    at io.vlingo.actors.LocalMessage.deliver(LocalMessage.java:49)
    at io.vlingo.actors.plugin.mailbox.concurrentqueue.ConcurrentQueueMailbox.run(ConcurrentQueueMailbox.java:96)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

When I register an Info for my test aggregate without any Adapter I'm getting this Exception:

    at io.vlingo.lattice.model.sourcing.Sourced.lambda$appendAllResultedIn$3(Sourced.java:307)
    at io.vlingo.common.Failure.otherwise(Failure.java:45)
    at io.vlingo.lattice.model.sourcing.Sourced.appendAllResultedIn(Sourced.java:303)
    at io.vlingo.symbio.store.journal.JournalAppendResultInterest__Proxy.lambda$appendAllResultedIn$1(JournalAppendResultInterest__Proxy.java:40)
    at io.vlingo.actors.LocalMessage.internalDeliver(LocalMessage.java:116)
    at io.vlingo.actors.LocalMessage.deliver(LocalMessage.java:49)
    at io.vlingo.actors.ResumingMailbox.run(ResumingMailbox.java:19)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: io.vlingo.symbio.store.StorageException: Adapter not registrered for: de.test.TestCreated
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.appendAllResultedInFailure(PostgresJournalActor.java:299)
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.lambda$appendAllWith$5(PostgresJournalActor.java:128)
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.asEntry(PostgresJournalActor.java:175)
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.asEntries(PostgresJournalActor.java:163)
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.appendAllWith(PostgresJournalActor.java:129)
    at io.vlingo.symbio.store.journal.Journal__Proxy.lambda$appendAllWith$2(Journal__Proxy.java:57)
    at io.vlingo.actors.LocalMessage.internalDeliver(LocalMessage.java:116)
    at io.vlingo.actors.LocalMessage.deliver(LocalMessage.java:49)
    at io.vlingo.actors.plugin.mailbox.concurrentqueue.ConcurrentQueueMailbox.run(ConcurrentQueueMailbox.java:96)
    ... 3 more
Caused by: java.lang.IllegalStateException: Adapter not registrered for: de.test.TestCreated
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.adapter(PostgresJournalActor.java:157)
    at io.vlingo.symbio.store.journal.jdbc.postgres.PostgresJournalActor.asEntry(PostgresJournalActor.java:171)
    ... 9 more

I will add a StateStore version to my test but for a Journal it does seem work. But I assume that the changes you made are not intended to work with a Journal

VaughnVernon commented 5 years ago

@RoadRunner120485 Sorry, my fault. This has been fixed/implemented in the PostgresJournalActor.

git pull and build, or get the latest binaries from Bintray; these are considered snapshots.

sturmm commented 5 years ago

@VaughnVernon it is working now. I just need to register an empty Info in the SourceTypeRegistry but then it works without providing any custom Adapter. I like the AdapterProviders as they allow to mix up custom and default adapter implementations.

VaughnVernon commented 5 years ago

@RoadRunner120485 Great, I am glad it works and that you like how it works! The SourceTypeRegistry is necessary to tell the Sourced entity which Journal it uses even if you don't register any adapters.

Is it ok to close this issue?

VaughnVernon commented 5 years ago

Closing as fixed.