Git Product home page Git Product logo

Comments (6)

JerryShea avatar JerryShea commented on July 25, 2024

The current rule is that loopFinished is called exactly once and then close is called exactly once on an event handler when it is either removed from an event loop, or the event loop is stopped.
Please review EventGroupTest - this enforces this contract.
It needs to be better documented - will do so tomorrow.

from chronicle-threads.

minborg avatar minborg commented on July 25, 2024

Ok. What is the rationale of having two different methods being invoked on the same event?

loopFinished() {
  a();
}

close() {
 b()
}

But instead we might as well just have:

close() {
  a();
  b();
}

from chronicle-threads.

JerryShea avatar JerryShea commented on July 25, 2024

@minborg there is some history here - OpenHFT/Chronicle-Network#45

In a nutshell, you can't rely on close() to release resources because the action method may still be executing in another thread.

We could make a rule that if an EventHandler implements Closeable then it is only allowed to be called by the event loop? Then we could do away with loopFinished.

from chronicle-threads.

minborg avatar minborg commented on July 25, 2024

In general, we should have a consistent life-cycle for both the EventLoop and EventHandler. Either an EventHandler is managed by an EventLoop or by its creating entity. This is of particular importance in this case because of thread visibility issues.

Letting the EventLoop invoke close() creates a dissonance in my opinion as the EventHandler is created by another entity using another thread but then handed over to the EventLoop. Either the creating entity should invoke close() or the EventLoop should create the EventHandler, potentially via a provided Supplier<EventHandler>.

I think it would be more consistent to let the creating entity manage the lifecycle of the EventHandler and remove the magic invocation of close() and instead have:

  • onAdded()
  • onRemoved()

which are invoked exactly one time by the EventLoop (using.the event loop's thread). These methods can then be used to initialize and clean up the EventHandler with no concurrency issues.

from chronicle-threads.

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

The behaviour for closeable is that should expect to be called one or more times and ignore any duplicates. SimpleCloseable can assist.

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.