30 |
|
if (args.length > 0) |
31 |
|
reps = Integer.parseInt(args[0]); |
32 |
|
|
33 |
< |
System.out.println("ITEMS: " + ITEMS + |
34 |
< |
" PRODUCERS: " + PRODUCERS + |
35 |
< |
" PROCESSORS: " + PROCESSORS + |
33 |
> |
System.out.println("ITEMS: " + ITEMS + |
34 |
> |
" PRODUCERS: " + PRODUCERS + |
35 |
> |
" PROCESSORS: " + PROCESSORS + |
36 |
|
" CONSUMERS: " + CONSUMERS + |
37 |
|
" CAP: " + CAP); |
38 |
|
for (int rep = 0; rep < reps; ++rep) { |
52 |
|
static final class Sub implements Flow.Subscriber<Boolean> { |
53 |
|
int count; |
54 |
|
Flow.Subscription subscription; |
55 |
< |
public void onSubscribe(Flow.Subscription s) { |
56 |
< |
(subscription = s).request(CAP); |
55 |
> |
public void onSubscribe(Flow.Subscription s) { |
56 |
> |
(subscription = s).request(CAP); |
57 |
|
} |
58 |
< |
public void onNext(Boolean b) { |
58 |
> |
public void onNext(Boolean b) { |
59 |
|
if (b && (++count & ((CAP >>> 1) - 1)) == 0) |
60 |
|
subscription.request(CAP >>> 1); |
61 |
|
} |
62 |
< |
public void onComplete() { |
62 |
> |
public void onComplete() { |
63 |
|
if (count != ITEMS) |
64 |
|
System.out.println("Error: remaining " + (ITEMS - count)); |
65 |
< |
phaser.arrive(); |
65 |
> |
phaser.arrive(); |
66 |
|
} |
67 |
|
public void onError(Throwable t) { t.printStackTrace(); } |
68 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
static final class Pub extends RecursiveAction { |
90 |
< |
final SubmissionPublisher<Boolean> pub = |
90 |
> |
final SubmissionPublisher<Boolean> pub = |
91 |
|
new SubmissionPublisher<Boolean>(ForkJoinPool.commonPool(), CAP); |
92 |
|
public void compute() { |
93 |
|
SubmissionPublisher<Boolean> p = pub; |
97 |
|
t.subscribe(new Sub()); |
98 |
|
p.subscribe(t); |
99 |
|
} |
100 |
< |
for (int i = 0; i < ITEMS; ++i) |
100 |
> |
for (int i = 0; i < ITEMS; ++i) |
101 |
|
p.submit(Boolean.TRUE); |
102 |
|
p.close(); |
103 |
|
} |