Description
Registration is a simple interface, which is quite easy to get wrong due to simple lamdas not being idempotent:
Registration reg = () -> {
// not idempotent!
};
reg.close() // executes the block
reg.close() // also executes the block!
Current way of doing this is quite verbose:
var reg = AbstractRegistration() { @Override protected void removeRegistration() { // idempotent } }; reg.close() // executes the block reg.close() // does nothing
Add Registration.of(Runnable) utility method which wraps a callback and executes it just once, backed by AbstractRegistration logic. This allows users to use lambdas (and method references) and wrap them with a guard:
var reg = Registration.of(() -> { // idempotent }); reg.close() // executes the block reg.close() // does nothing
The same patterns applies to ObjectRegistration and ListenerRegistration.
Attachments
Gerrit Reviews
| # | Subject | Branch | Project | Status | CR | V |
|---|---|---|---|---|---|---|
| 105250,2 | Improve Registration usability | master | yangtools | Status: NEW | 0 | +1 |