LSpace: unify producer methods #663
Open
+66
−212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(read NOTE below to avoid headaches)
In the same spirit as the commit that unified the logic of many consumers under
awaitValue(), this pull request does it with the producer ("enqueuer") methods.After careful comparison, all 6 producer methods versions
{out, push, put} X { timeout, no-timeout}were basically the same. The main difference being where they would add the new value (at head or tail of the queue) and whether they would clear the queue (put) or not (outandpush) and a some status flag such ashasExpirable.Now all the core logic has been unified in a single method:
private void enqueueValue(String opTag, K key, V value, long timeout, Enqueuer op)This method accepts a lambda implementing an
Enqueuerfunctional interface, where the specific differences ofout,put,pushare tackled. ThenenqueueValue()calls theEnqueuerat some specific point inside all the other common boilerplate.All tests related to
LSpacepass successfully (and all others as well)NOTE: In order to make the diffs more digestible by human eyes, this PR is split in two commits.
ba2ba8f4 LSpace: non-timeout producer methods in terms of the timeout versions.
This one mainly implements the non-timeout versions by calling the timeout versions using the constant
long NO_TIMEOUT = -1Lwhich works well as they were equivalent and thetimeoutargument is treated correctly for all cases.There's no need to spend much time with this commit; just take it as "reduce the noise for the following one"
37ad9d1 LSpace: unfiy logic of producer methods
This is the one to look at!
It introduces the functional
Enqueuerand extracts the boilerplate intoenqueueValue()