Skip to content

Commit f59920f

Browse files
committed
Build core-common on JDK 11
Possible to create multirelease jar Signed-off-by: Jan Supol <jan.supol@oracle.com>
1 parent 08c5fa2 commit f59920f

File tree

13 files changed

+1260
-26
lines changed

13 files changed

+1260
-26
lines changed

core-common/pom.xml

+386-6
Large diffs are not rendered by default.

core-common/src/main/java/org/glassfish/jersey/internal/util/JerseyPublisher.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -25,21 +25,23 @@
2525
import java.util.function.Consumer;
2626

2727
import org.glassfish.jersey.internal.LocalizationMessages;
28+
import org.glassfish.jersey.internal.jsr166.SubmissionPublisherFactory;
29+
import org.glassfish.jersey.internal.jsr166.SubmittableFlowPublisher;
2830
import org.glassfish.jersey.internal.jsr166.Flow;
29-
import org.glassfish.jersey.internal.jsr166.SubmissionPublisher;
30-
3131

3232
/**
3333
* Implementation of {@link Flow.Publisher} corresponding to reactive streams specification.
3434
* <p>
35-
* Delegates to {@link SubmissionPublisher} repackaged from jsr166.
35+
* Delegates to {@link SubmittableFlowPublisher} implementation either repackaged from jsr166 for jdk8, or a facade of jdk9
36+
* {@code SubmissionPublisher}
3637
*
3738
* @author Adam Lindenthal (adam.lindenthal at oracle.com)
3839
*/
39-
public class JerseyPublisher<T> implements Flow.Publisher<T> {
40+
public class JerseyPublisher<T> implements SubmittableFlowPublisher<T> {
4041

4142
private static final int DEFAULT_BUFFER_CAPACITY = 256;
42-
private SubmissionPublisher<T> submissionPublisher = new SubmissionPublisher<>();
43+
private SubmittableFlowPublisher<T> submissionPublisher = SubmissionPublisherFactory.createSubmissionPublisher();
44+
4345

4446
private final PublisherStrategy strategy;
4547

@@ -90,7 +92,7 @@ public JerseyPublisher(final Executor executor) {
9092
*/
9193
public JerseyPublisher(final Executor executor, final PublisherStrategy strategy) {
9294
this.strategy = strategy;
93-
submissionPublisher = new SubmissionPublisher<>(executor, DEFAULT_BUFFER_CAPACITY);
95+
submissionPublisher = SubmissionPublisherFactory.createSubmissionPublisher(executor, DEFAULT_BUFFER_CAPACITY);
9496
}
9597

9698

@@ -128,7 +130,7 @@ public JerseyPublisher(final int maxBufferCapacity) {
128130
*/
129131
public JerseyPublisher(final Executor executor, final int maxBufferCapacity, PublisherStrategy strategy) {
130132
this.strategy = strategy;
131-
submissionPublisher = new SubmissionPublisher<>(executor, maxBufferCapacity);
133+
submissionPublisher = SubmissionPublisherFactory.createSubmissionPublisher(executor, maxBufferCapacity);
132134
}
133135

134136
@Override
@@ -147,7 +149,7 @@ public void subscribe(final Flow.Subscriber<? super T> subscriber) {
147149
* @throws NullPointerException if data is null
148150
* @throws java.util.concurrent.RejectedExecutionException if thrown by Executor
149151
*/
150-
private int submit(final T data) {
152+
public int submit(final T data) {
151153
return submissionPublisher.submit(data);
152154
}
153155

@@ -203,7 +205,7 @@ public CompletableFuture<Void> consume(final Consumer<? super T> consumer) {
203205
* @throws NullPointerException if item is null
204206
* @throws RejectedExecutionException if thrown by Executor
205207
*/
206-
private int offer(T item, BiPredicate<Flow.Subscriber<? super T>, ? super T> onDrop) {
208+
public int offer(T item, BiPredicate<Flow.Subscriber<? super T>, ? super T> onDrop) {
207209
return offer(item, 0, TimeUnit.MILLISECONDS, onDrop);
208210
}
209211

@@ -252,7 +254,7 @@ private int offer(T item, BiPredicate<Flow.Subscriber<? super T>, ? super T> onD
252254
* @throws NullPointerException if item is null
253255
* @throws RejectedExecutionException if thrown by Executor
254256
*/
255-
private int offer(T item,
257+
public int offer(T item,
256258
long timeout,
257259
TimeUnit unit,
258260
BiPredicate<Flow.Subscriber<? super T>, ? super T> onDrop) {

core-common/src/main/java/org/glassfish/jersey/internal/jsr166/SubmissionPublisher.java core-common/src/main/java8/org/glassfish/jersey/internal/jsr166/SubmissionPublisher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
* @author Doug Lea
135135
* @since 9
136136
*/
137-
public class SubmissionPublisher<T> implements Flow.Publisher<T>,
137+
public class SubmissionPublisher<T> implements Flow.Publisher<T>, SubmittableFlowPublisher<T>,
138138
AutoCloseable {
139139
/*
140140
* Most mechanics are handled by BufferedSubscription. This class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.internal.jsr166;
18+
19+
import java.util.concurrent.Executor;
20+
import java.util.concurrent.ForkJoinPool;
21+
import java.util.function.BiConsumer;
22+
23+
/**
24+
* Factory creating JDK8 compatible SubmissionPublisher (Jdk8SubmissionPublisher) or JDK 9+ SubmissionPublisher
25+
*/
26+
public class SubmissionPublisherFactory {
27+
28+
/**
29+
* Creates a new SubmissionPublisher using the {@link
30+
* ForkJoinPool#commonPool()} for async delivery to subscribers
31+
* (unless it does not support a parallelism level of at least two,
32+
* in which case, a new Thread is created to run each task), with
33+
* maximum buffer capacity of {@link Flow#defaultBufferSize}, and no
34+
* handler for Subscriber exceptions in method {@link
35+
* Flow.Subscriber#onNext(Object) onNext}.
36+
*/
37+
public static <T> SubmittableFlowPublisher<T> createSubmissionPublisher() {
38+
return new SubmissionPublisher<T>();
39+
}
40+
41+
public static <T> SubmittableFlowPublisher<T> createSubmissionPublisher(Executor executor,
42+
int maxBufferCapacity) {
43+
return new SubmissionPublisher<T>(executor, maxBufferCapacity);
44+
}
45+
46+
public static <T> SubmittableFlowPublisher<T> createSubmissionPublisher(Executor executor,
47+
int maxBufferCapacity,
48+
BiConsumer<? super Flow.Subscriber<? super T>,
49+
? super Throwable> handler) {
50+
return new SubmissionPublisher<T>(executor, maxBufferCapacity, handler);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)