Skip to content

Commit 043e28b

Browse files
nebhalerobertroeser
authored andcommitted
Shadow JCTools (#476)
Previously, a number of classes from JCTools had been copied and pasted into the code in order to avoid a JAR-level dependencies on the project. While the goal was worthy, the implementation led itself to divergence as the classes in JCTools were improved and bugs were fixed. Even the JCTools project discourages this behavior, instead recommending that you shadow/shade in the dependency. From the RSocket perspective, this has the advantage of allowing the dependency to be specified and kept up to date in the same way that all the other dependencies of the projects are, and yet still not resulting in a JAR-level dependency on JCTools. This change updates the code to use JCTools directly as a dependency and introduces the shadow plugin, configured to include just the types needed by the code.
1 parent c9eade5 commit 043e28b

File tree

9 files changed

+27
-3366
lines changed

9 files changed

+27
-3366
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ subprojects {
4747
dependency 'io.aeron:aeron-all:1.4.1'
4848
dependency 'org.hamcrest:hamcrest-library:1.3'
4949
dependency 'org.hdrhistogram:HdrHistogram:2.1.10'
50+
dependency 'org.jctools:jctools-core:2.1.2'
5051
dependency 'org.mockito:mockito-core:2.16.0'
5152
dependency 'org.openjdk.jmh:jmh-core:1.20'
5253

rsocket-core/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
api 'io.projectreactor:reactor-core'
3030

3131
implementation 'com.google.code.findbugs:jsr305'
32+
implementation 'org.jctools:jctools-core'
3233
implementation 'org.slf4j:slf4j-api'
3334

3435
testImplementation 'io.projectreactor:reactor-test'
@@ -37,6 +38,26 @@ dependencies {
3738
testImplementation 'org.mockito:mockito-core'
3839
}
3940

41+
jar {
42+
enabled = false
43+
dependsOn(shadowJar { classifier = null })
44+
}
45+
46+
shadowJar {
47+
dependencies {
48+
include(dependency('org.jctools:jctools-core'))
49+
}
50+
51+
include '*.jar'
52+
include 'io/rsocket/**'
53+
include 'org/jctools/maps/ConcurrentAutoTable*.class'
54+
include 'org/jctools/maps/NonBlockingHashMapLong*.class'
55+
include 'org/jctools/util/RangeUtil*.class'
56+
include 'org/jctools/util/UnsafeAccess*.class'
57+
58+
relocate 'org.jctools', 'io.rsocket.shadowed.org.jctools'
59+
}
60+
4061
description = "Core functionality for the RSocket library"
4162

4263
apply from: 'jmh.gradle'

rsocket-core/src/main/java/io/rsocket/RSocketClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
import io.rsocket.exceptions.Exceptions;
2222
import io.rsocket.internal.LimitableRequestPublisher;
2323
import io.rsocket.internal.UnboundedProcessor;
24-
import io.rsocket.util.NonBlockingHashMapLong;
2524
import java.time.Duration;
2625
import java.util.concurrent.atomic.AtomicBoolean;
2726
import java.util.concurrent.atomic.AtomicInteger;
2827
import java.util.function.Consumer;
2928
import java.util.function.Function;
3029
import java.util.function.Supplier;
3130
import javax.annotation.Nullable;
31+
32+
import org.jctools.maps.NonBlockingHashMapLong;
3233
import org.reactivestreams.Publisher;
3334
import org.reactivestreams.Subscriber;
3435
import reactor.core.Disposable;

rsocket-core/src/main/java/io/rsocket/RSocketServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import io.rsocket.exceptions.ApplicationException;
2626
import io.rsocket.internal.LimitableRequestPublisher;
2727
import io.rsocket.internal.UnboundedProcessor;
28-
import io.rsocket.util.NonBlockingHashMapLong;
2928
import java.util.function.Consumer;
3029
import java.util.function.Function;
30+
31+
import org.jctools.maps.NonBlockingHashMapLong;
3132
import org.reactivestreams.Publisher;
3233
import org.reactivestreams.Subscriber;
3334
import org.reactivestreams.Subscription;

rsocket-core/src/main/java/io/rsocket/fragmentation/FragmentationDuplexConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.rsocket.DuplexConnection;
2020
import io.rsocket.Frame;
2121
import io.rsocket.frame.FrameHeaderFlyweight;
22-
import io.rsocket.util.NonBlockingHashMapLong;
22+
import org.jctools.maps.NonBlockingHashMapLong;
2323
import org.reactivestreams.Publisher;
2424
import reactor.core.publisher.Flux;
2525
import reactor.core.publisher.Mono;

rsocket-core/src/main/java/io/rsocket/util/ConcurrentAutoTable.java

Lines changed: 0 additions & 243 deletions
This file was deleted.

0 commit comments

Comments
 (0)