@@ -63,41 +63,32 @@ public class ReactiveAdapterRegistry {
63
63
*/
64
64
public ReactiveAdapterRegistry () {
65
65
66
+ ClassLoader classLoader = ReactiveAdapterRegistry .class .getClassLoader ();
67
+
66
68
// Reactor
67
69
boolean reactorRegistered = false ;
68
- try {
70
+ if ( ClassUtils . isPresent ( "reactor.core.publisher.Flux" , classLoader )) {
69
71
new ReactorRegistrar ().registerAdapters (this );
70
72
reactorRegistered = true ;
71
73
}
72
- catch (Throwable ex ) {
73
- // Ignore
74
- }
75
74
this .reactorPresent = reactorRegistered ;
76
75
77
76
// RxJava1
78
- try {
77
+ if ( ClassUtils . isPresent ( "rx.Observable" , classLoader )) {
79
78
new RxJava1Registrar ().registerAdapters (this );
80
79
}
81
- catch (Throwable ex ) {
82
- // Ignore
83
- }
84
80
85
81
// RxJava2
86
- try {
82
+ if ( ClassUtils . isPresent ( "io.reactivex.Flowable" , classLoader )) {
87
83
new RxJava2Registrar ().registerAdapters (this );
88
84
}
89
- catch (Throwable ex ) {
90
- // Ignore
91
- }
92
85
93
86
// Java 9+ Flow.Publisher
94
- try {
87
+ if ( ClassUtils . isPresent ( "java.util.concurrent.Flow.Publisher" , classLoader )) {
95
88
new ReactorJdkFlowAdapterRegistrar ().registerAdapter (this );
96
89
}
97
- catch (Throwable ex ) {
98
- // Ignore for the time being...
99
- // We can fall back on "reactive-streams-flow-bridge" (once released)
100
- }
90
+ // If not present, do nothing for the time being...
91
+ // We can fall back on "reactive-streams-flow-bridge" (once released)
101
92
}
102
93
103
94
@@ -276,24 +267,29 @@ void registerAdapters(ReactiveAdapterRegistry registry) {
276
267
277
268
private static class ReactorJdkFlowAdapterRegistrar {
278
269
279
- void registerAdapter (ReactiveAdapterRegistry registry ) throws Exception {
270
+ void registerAdapter (ReactiveAdapterRegistry registry ) {
280
271
// TODO: remove reflection when build requires JDK 9+
281
272
282
- String publisherName = "java.util.concurrent.Flow.Publisher" ;
283
- Class <?> publisherClass = ClassUtils .forName (publisherName , getClass ().getClassLoader ());
273
+ try {
274
+ String publisherName = "java.util.concurrent.Flow.Publisher" ;
275
+ Class <?> publisherClass = ClassUtils .forName (publisherName , getClass ().getClassLoader ());
284
276
285
- String adapterName = "reactor.adapter.JdkFlowAdapter" ;
286
- Class <?> flowAdapterClass = ClassUtils .forName (adapterName , getClass ().getClassLoader ());
277
+ String adapterName = "reactor.adapter.JdkFlowAdapter" ;
278
+ Class <?> flowAdapterClass = ClassUtils .forName (adapterName , getClass ().getClassLoader ());
287
279
288
- Method toFluxMethod = flowAdapterClass .getMethod ("flowPublisherToFlux" , publisherClass );
289
- Method toFlowMethod = flowAdapterClass .getMethod ("publisherToFlowPublisher" , Publisher .class );
290
- Object emptyFlow = ReflectionUtils .invokeMethod (toFlowMethod , null , Flux .empty ());
280
+ Method toFluxMethod = flowAdapterClass .getMethod ("flowPublisherToFlux" , publisherClass );
281
+ Method toFlowMethod = flowAdapterClass .getMethod ("publisherToFlowPublisher" , Publisher .class );
282
+ Object emptyFlow = ReflectionUtils .invokeMethod (toFlowMethod , null , Flux .empty ());
291
283
292
- registry .registerReactiveType (
293
- ReactiveTypeDescriptor .multiValue (publisherClass , () -> emptyFlow ),
294
- source -> (Publisher <?>) ReflectionUtils .invokeMethod (toFluxMethod , null , source ),
295
- publisher -> ReflectionUtils .invokeMethod (toFlowMethod , null , publisher )
296
- );
284
+ registry .registerReactiveType (
285
+ ReactiveTypeDescriptor .multiValue (publisherClass , () -> emptyFlow ),
286
+ source -> (Publisher <?>) ReflectionUtils .invokeMethod (toFluxMethod , null , source ),
287
+ publisher -> ReflectionUtils .invokeMethod (toFlowMethod , null , publisher )
288
+ );
289
+ }
290
+ catch (Throwable ex ) {
291
+ // Ignore
292
+ }
297
293
}
298
294
}
299
295
0 commit comments