reactor/reactor — pull request #267 by jbrisbin (2014-01-29 21:25:33+00:00)
Title: Fixes #232 by providing a flexible Allocator API for doing object pooling.

Included are a ReferenceCountingAllocator that manages objects based on reference counts (when the refCnt is zero, the object is able to be reclaimed and handed back out) and a RingBufferAllocator which uses the LMAX Disruptor RingBuffer to do object pooling. This component has the added advantage of being able to accept event and error handlers to hook into the RingBuffer's event lifecycle.

As a consequence of having the Allocators available, the Dispatchers have been re-written to take advantage of them. As much common functionality from each of the Dispatcher implementations has been extracted into a common and re-usable abstract implementation. The different Dispatchers only need to implement the functionality that is specific to their use case. Benchmark tests show that these changes have a negligible impact on overall throughput, though there is a slight variation in this version of the dispatchers compared to previous versions. But the advantages of better memory management due to the allocators is probably worth the small price of a slight change in throughput. It's likely that future changes to these allocators could even make these versions faster than those that used the LoadingPool.