Git Product home page Git Product logo

Comments (8)

minborg avatar minborg commented on July 25, 2024

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.

JerryShea avatar JerryShea commented on July 25, 2024

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.

minborg avatar minborg commented on July 25, 2024

The contract would be that the Supplier is guaranteed to be invoked by the event loop thread.

from chronicle-threads.

JerryShea avatar JerryShea commented on July 25, 2024

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.

minborg avatar minborg commented on July 25, 2024

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.

minborg avatar minborg commented on July 25, 2024

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.

peter-lawrey avatar peter-lawrey commented on July 25, 2024

This facility is covered by the eventLoop(EventLoop) call however I have added a loopStarted() to make this clearer.

from chronicle-threads.

hft-team-city avatar hft-team-city commented on July 25, 2024

Released in Chronicle-Threads-2.20.43, BOM-2.20.67

from chronicle-threads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.