Extend Multiverse BasicRef rather than wrap ProgrammaticRef
Instead of wrapping the Multiverse Programmatic Ref, you can also extend the org.multiverse.transactional.ref.BasicRef.
This prevents creating an additional wrapper object per reference. If you extend the Multiverse ref, the akka user doesn't need to have a direct dependency on Multiverse.
So something like:
interface AkkaRef extends Ref{}
class BasicAkkaRef extends BasicRef implements AkkaRef{}
Extending is (now) possible because the Ref class is not final (but its methods are.. else I can't do certain bytecode optimizations that are important).
I also have refs for all primitive types (prevents unwanted autoboxing) [see #249]
And you can also expose the transactional collections that can be found in org.multiverse.transactional [see #209]
This prevents creating an additional wrapper object per reference. If you extend the Multiverse ref, the akka user doesn't need to have a direct dependency on Multiverse.
So something like:
interface AkkaRef extends Ref{}
class BasicAkkaRef extends BasicRef implements AkkaRef{}
Extending is (now) possible because the Ref class is not final (but its methods are.. else I can't do certain bytecode optimizations that are important).
I also have refs for all primitive types (prevents unwanted autoboxing) [see #249]
And you can also expose the transactional collections that can be found in org.multiverse.transactional [see #209]
Leave a comment
on 2010-06-09 21:37 *
By Peter Vlugter
Just thinking about this: the biggest change that jumps out for me straight away is ref.get. In the Akka wrapper ref.get returns an option type (wrapping the underlying ref.isNull check and ref.get). If we're extending BasicRef then ref.get returns the value directly (possibly null).
I don't see the cost of a wrapper for refs as a problem. And I prefer Option in Scala over null checking so feel that it's worthwhile. What do others think?
I don't see the cost of a wrapper for refs as a problem. And I prefer Option in Scala over null checking so feel that it's worthwhile. What do others think?
Can't you provide an additional method in akka that has the signature you want it to have? You are free to provide your own interface and extend your implementation from the Multiverse Ref.
The disadvantage of wrapping is that more space is used (1 object per reference). Another disadvantage is that it gets harder for the instrumentation to do all kinds of optimizations (like enhancing the methods so that the threadlocal transaction doesn't need to be retrieved from the threadlocal, but can be passed as additional argument (I enhance methods by generating multiple copies that remove some of the overhead).
So just wrapping for the sake of a better interface could be a dangerous choice.
The disadvantage of wrapping is that more space is used (1 object per reference). Another disadvantage is that it gets harder for the instrumentation to do all kinds of optimizations (like enhancing the methods so that the threadlocal transaction doesn't need to be retrieved from the threadlocal, but can be passed as additional argument (I enhance methods by generating multiple copies that remove some of the overhead).
So just wrapping for the sake of a better interface could be a dangerous choice.
on 2010-06-09 22:47 *
By Peter Vlugter
Yes, we can provide an additional method that returns an Option.
on 2010-06-23 05:58 *
By Peter Vlugter
Interested to hear what others think about this... Extending BasicRef creates a breaking change for ref.get. Atm get returns an option, it would change to returning the value directly (possibly null). Should we have a new method that returns an option - getOpt? I haven't looked closer yet to see if there's anything else to consider.
on 2010-07-12 22:12 *
By Peter Vlugter
Related association with ticket #327 was added
on 2010-07-13 06:34 *
By Heiko Seeberger
on 2010-07-13 22:31 *
By Peter Vlugter
Yes, it would cover #327 as well. At the moment the Akka ref wraps a Multiverse ref and returns an option for ref.get (with underlying ref.isNull check). Peter Veentjer has made it possible to extend the Multiverse ref (rather than wrap it), in which case ref.get will return the value directly.
on 2010-07-14 04:39 *
By Heiko Seeberger
Ah, that sounds great: You will do all the hard work and I have more free time ;-)
Thank you!
Thank you!
(In revision:3e423acf8397963c31656aea6c89a2cfbfebd797) Ref extends Multiverse BasicRef (closes #253)
Branch: master
Branch: master