Comments (8)
A perhaps even more compelling alternative would be to add an overload method EventLoop.addHandler(Supplier<? extends EventHandler>)
that creates the EventHandler using the EventLoop's own execution thread. This way, thread-specific properties may be initialized in the constructor and may thus be final.
private final Thread actionThread;
...
public TcpEventHandler(...)
this.actionThread = Thread.currentThread();
}
from chronicle-threads.
I like the idea very much and the Supplier mechanism sounds great.
Only thing that does concern me about the Supplier solution is that the EventHandler constructor does not know whether it is being called from the event loop thread or any old thread.
from chronicle-threads.
The contract would be that the Supplier is guaranteed to be invoked by the event loop thread.
from chronicle-threads.
Yes but my point is that there is no way for the EventHandler to know if its constructor has been called by the supplier (in EL thread) or by something else (in whatever thread) - or do you propose to replace (rather than offer as an alternative)
EventLoop#addHandler(net.openhft.chronicle.core.threads.EventHandler)
with the Supplier mechanism?
from chronicle-threads.
I agree with @JerryShea that there is no way of knowing that it is the event thread that is being used in a constructor. So, it would be better to provide the event thread as a parameter to the constructor. Also, the EventHandler:eventLoop
parameter could be provided to the constructor. These two parameters are generally known by an EventLoop
.
from chronicle-threads.
Added:
/**
* Adds a handler to this EventLoop by first invoking the provided EventHandler
* constructor and then taking the constructed instance and providing it to
* the {@link #addHandler(EventHandler)} method.
* <p>
* The BiFunction's Thread is the event thread for this EventLoop
* The BiFunction's EventLoop is the same parameter later provided to EventHandler::eventLoop
* <p>
* This method improves the ability to write immutable or partly immutable EventHandler classes
* compared with the {@link #addHandler(EventHandler)} method.
*
* @param constructor to invoke when creating an EventHandler
* @param priority for the EventHandler that must match the created EventHandler's priority
* @return closeable to use for cleaning up.
* @throws IllegalStateException if the provided {@code priority} does not match the
* constructed EventHandler's priority.
*/
Closeable addHandler(@NotNull BiFunction<Thread, EventLoop, EventHandler> constructor, @NotNull HandlerPriority priority);
from chronicle-threads.
This facility is covered by the eventLoop(EventLoop)
call however I have added a loopStarted()
to make this clearer.
from chronicle-threads.
Released in Chronicle-Threads-2.20.43, BOM-2.20.67
from chronicle-threads.
Related Issues (20)
- Update figure 1 in ReadMe.adoc to the Chronicle infographic style
- False positive monitorThreadDelayed reports on almost-idle thread HOT 2
- flaky test VanillaEventLoopTest.testEnsureRemoveInvokesLoopFinishedJustOnce HOT 2
- Make image background navy
- When EventGroup startup times out, provide more information about the state of the EventLoops HOT 1
- Add a systemProperties.adoc with a table of system properties (if there are any) HOT 1
- Tuning LongPauser to be less platform sensitive
- Add paragraph to adoc about Chronicle Threads
- Add to Pauser documentation
- Add pauser graph to documentation HOT 1
- MediumEventLoop silently terminates when an IllegalStateException is thrown on startup HOT 1
- The contract for EventHandler#loopFinished is violated a lot HOT 4
- Add Information to ReadMe from landing page
- Data race between handler.eventLoop(EventLoop) and first handler execution HOT 1
- Add support for collecting the current EventLoops and their Pausers HOT 1
- EventGroup sometimes times out on start HOT 5
- Blocking loop runs jobs before event group is alive HOT 3
- EventGroupStressTest is flaky HOT 1
- NoSuchFieldException JDK 20 HOT 3
- Detect if event loop is being closed from its own thread HOT 4
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 chronicle-threads.