22 |
|
static class Sub implements Flow.Subscriber<Boolean> { |
23 |
|
Flow.Subscription sn; |
24 |
|
int count; |
25 |
< |
public void onSubscribe(Flow.Subscription s) { |
26 |
< |
(sn = s).request(CAP); |
25 |
> |
public void onSubscribe(Flow.Subscription s) { |
26 |
> |
(sn = s).request(CAP); |
27 |
|
} |
28 |
< |
public void onNext(Boolean t) { |
28 |
> |
public void onNext(Boolean t) { |
29 |
|
if ((++count & (CAP - 1)) == (CAP >>> 1)) |
30 |
|
sn.request(CAP); |
31 |
|
} |
32 |
|
public void onError(Throwable t) { t.printStackTrace(); } |
33 |
< |
public void onComplete() { |
33 |
> |
public void onComplete() { |
34 |
|
if (count != ITEMS) |
35 |
|
System.out.println("Error: remaining " + (ITEMS - count)); |
36 |
< |
phaser.arrive(); |
36 |
> |
phaser.arrive(); |
37 |
|
} |
38 |
|
} |
39 |
|
|
40 |
|
static final class Pub extends RecursiveAction { |
41 |
< |
final SubmissionPublisher<Boolean> pub = |
41 |
> |
final SubmissionPublisher<Boolean> pub = |
42 |
|
new SubmissionPublisher<Boolean>(ForkJoinPool.commonPool(), CAP); |
43 |
|
public void compute() { |
44 |
|
SubmissionPublisher<Boolean> p = pub; |
45 |
|
for (int i = 0; i < CONSUMERS; ++i) |
46 |
|
p.subscribe(new Sub()); |
47 |
< |
for (int i = 0; i < ITEMS; ++i) |
47 |
> |
for (int i = 0; i < ITEMS; ++i) |
48 |
|
p.submit(Boolean.TRUE); |
49 |
|
p.close(); |
50 |
|
} |
56 |
|
int reps = REPS; |
57 |
|
if (args.length > 0) |
58 |
|
reps = Integer.parseInt(args[0]); |
59 |
< |
|
60 |
< |
System.out.println("ITEMS: " + ITEMS + |
59 |
> |
|
60 |
> |
System.out.println("ITEMS: " + ITEMS + |
61 |
|
" CONSUMERS: " + CONSUMERS + |
62 |
|
" CAP: " + CAP); |
63 |
|
|