Skip to content

Commit

Permalink
Low level api (#17)
Browse files Browse the repository at this point in the history
* [enhancement] add low level api for special purpose.
  • Loading branch information
PhantomThief committed Nov 21, 2018
1 parent b3ed80e commit 3df65df
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,32 @@ public <E, X extends Throwable> E supply(@Nonnull Iterable<T> candidates,
* better use {@link #supply} or {@link #run} unless need to control begin and end in special situations.
* @throws NoSuchElementException if candidates is empty
*/
@Nonnull
public T begin(@Nonnull Iterable<T> candidates) {
T obj = beginWithoutRecordConcurrency(candidates);
recordBeginConcurrency(obj);
return obj;
}

/**
* this is a low level api, for special purpose or mock.
*/
@Nonnull
public T beginWithoutRecordConcurrency(@Nonnull Iterable<T> candidates) {
T obj = selectIdlest(candidates);
if (obj == null) {
throw new NoSuchElementException();
}
concurrency.merge(obj, 1, Integer::sum);
return obj;
}

/**
* this is a low level api, for special purpose or mock.
*/
public void recordBeginConcurrency(@Nonnull T obj) {
concurrency.merge(obj, 1, Integer::sum);
}

/**
* @param obj from {@link #begin}'s return
* @see #begin
Expand Down

0 comments on commit 3df65df

Please sign in to comment.