Bindgen 2.0 Released
My hobby project bindgen just got a new release: 2.0.
bindgen provides expression language-like capabilities, but with type-safe method calls instead of opaque strings like OGNL.
Stateless Bindings
The biggest change is that bindings can now be stateless.
Previously, a binding could only be bound to 1 instance at a time, making them not safe for use across multiple threads. You could reuse them within a thread, with a set(instance)
-based idiom like:
FooBinding fb = new FooBinding();
StringBinding nb = fb.name(); // could be more complex, e.g. fb.bar().name()
Foo foo = new Foo("foo");
fb.set(foo); // binds fb to the foo instance
nb.get(); // returns "foo"
But the gap between fb.set
and nb.get()
meant another thread could step in and interleave a set
behind your back.
Now there are getWithRoot
and setWithRoot
methods that are stateless and so thread-safe:
FooBinding fb = new FooBinding();
StringBinding nb = fb.name();
Foo foo = new Foo("foo");
nb.getWithRoot(foo); // returns "foo"
This means you can instantiate a binding just once and reuse it across many instances/threads.
Joist is starting to use these stateless bindings for its validation rules. The iterative nature (e.g. foo.employer().name()
) of bindgen is more flexible than Joist’s previous approach.
Links
Checkout more at:
- github
- Joist’s bindgen pages: