Comments (10)
The DomainEventPublisher (here) is a static and synchronous component where events are published synchronously in the same thread - and subscribed to by the same thread. The ThreadLocal is used to have storage specific to each thread, so different threads can publish at the same time without conflicting.
from iddd_samples.
I totally missed the original comment. The DomainEventPublisher has a static (class-level) interface for obtaining the instance that belongs to the current thread. However, there are also the instance methods publish(), subscribe(), reset(), that operate on the ThreadLocal instance. In any given thread there is likely only one or a few subscribers registered, so it's not a lot of overhead. Also note that at some point when a thread is assigned to an incoming server request, the subscriber list for the thread must be reset using DomainEventPublisher.instance().reset() so that subscriber(s) from the previous request using the same thread will not be left on the subscriber list.
from iddd_samples.
Looking at the implementation of the DomainEventPublisher I struggle to understand why do you have the publishing lock. Because you are running one instance per thread there are no potential concurrency issues. Why would you want to have a lock like that?
Probably I'm missing some fundamental concept. But it seems to me quite redundant based on the fact that you have one instance per Thread (thanks to ThreadLocal).
from iddd_samples.
The DomainEventPublisher must protect itself from the subscribers. For
example, when a subscriber's handle() method has been called back on, the
handle() method could attempt to register another subscriber. Even though
it's all happening on a single thread, that would cause a
ConcurrentModificationException on the collection.
On Thu, Oct 24, 2013 at 3:40 AM, Leonardo Fernandez <
[email protected]> wrote:
Looking at the implementation of the DomainEventPublisher I struggle to
understand why do you have the publishing lock. Because you are running one
instance per thread there are no potential concurrency issues. Why would
you want to have a lock like that?Probably I'm missing some fundamental concept. But it seems to me quite
redundant based on the fact that you have one instance per Thread (thanks
to ThreadLocal).—
Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-26978779
.
from iddd_samples.
Yeah! I see.
from iddd_samples.
Please see Chapter 8 of my book.
from iddd_samples.
Hum, I am reading this book at now, and thank you very much! It has been translated into Chinese.
from iddd_samples.
what if
thread_A subscribe(payEventSubscriber)
thread_B publish(payEvent)
it can`t work...
from iddd_samples.
from iddd_samples.
i have known that after reading the code.
thanks
from iddd_samples.
Related Issues (20)
- Constructor vs Static Factory Method HOT 1
- How do I open this project in java? HOT 2
- What's the point of com.saasovation.identityaccess.application.command? HOT 1
- Reference for functional programming
- Can't enable Mysql in EventStoreProvider HOT 1
- [question] implicit dependency from iddd_agilepm to iddd_identityaccess HOT 1
- Store aggregates: mongodb or postgres json
- Why didn't handle the situation that the user doesn't have the role
- Getting Peer not authenticated error when I'm trying to run gradlew build HOT 1
- why some entities in equals(..) use many properties and not only their ID? HOT 3
- Where is the aggregate root? HOT 1
- sprint.commit vs. backlogItem.commitTo HOT 5
- Why do some contexts contain port & adapter modules and others don't? HOT 3
- A duplicated tracker is created when retrying ProductDiscussionRequest HOT 2
- Build fails because of the version of tools
- The setup script fails
- Updating multiple aggregates in the same transaction? HOT 3
- Post on a closed discussion or closed forum
- How to use ValidationNotificationHandler HOT 1
- State in domain services HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iddd_samples.