-
Notifications
You must be signed in to change notification settings - Fork 266
Put all Collector actions in one execute #365
Conversation
private val count = new AtomicInteger(0) | ||
|
||
def put(item: T): Int = { | ||
queue.add(item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was your intention for this to block if queue
is an ArrayBlockingQueue
with a fixed size? What actually will happen is that a java.lang.IllegalStateException: Queue full
exception will be thrown instead of it actually blocking (you would need to call put
instead for the blocking behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice!
// always increment after this | ||
protected def add(t: T): Unit | ||
// always decrement after this | ||
protected def pollOrNull: T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its an always, why not bake the behavior into these rather than at touch points?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we supply a more scala idiomatic one, return Option[T] and internally do the decrement if not null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to make it easy to get that right, but if we require every subclass to call decrement, some will get it wrong. By contrast, if we do it below, we can audit it and test it once. This method is just for the adapter to existing java classes.
Option I'll do. That was we being OCD about allocations.... bad move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with the the atomic thing, i was thinking it might be more have the downstream api but then final functions which call them and do the decrement/increment. Such that there is only 2 places we need to ensure correctness. Not a big thing, its only a tiny class anyway.
Looks great, nice work. All comments are really very minor |
This is looking good to me, if no one has any other comments by tomorrow morning i'm pretty happy to merge it |
Put all Collector actions in one execute
Bump from 2.11.2 to 2.11.4
No description provided.