Skip to content

Commit 814c279

Browse files
authored
Forward compatibility with Reactor Netty 1.0 (#851)
1 parent 3f17a45 commit 814c279

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/server/CloseableChannel.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package io.rsocket.transport.netty.server;
1818

1919
import io.rsocket.Closeable;
20+
import java.lang.reflect.Method;
2021
import java.net.InetSocketAddress;
2122
import java.util.Objects;
2223
import reactor.core.publisher.Mono;
@@ -28,6 +29,17 @@
2829
*/
2930
public final class CloseableChannel implements Closeable {
3031

32+
/** For forward compatibility: remove when RSocket compiles against Reactor 1.0. */
33+
private static final Method channelAddressMethod;
34+
35+
static {
36+
try {
37+
channelAddressMethod = DisposableChannel.class.getMethod("address");
38+
} catch (NoSuchMethodException ex) {
39+
throw new IllegalStateException("Expected address method", ex);
40+
}
41+
}
42+
3143
private final DisposableChannel channel;
3244

3345
/**
@@ -47,7 +59,15 @@ public final class CloseableChannel implements Closeable {
4759
* @see DisposableChannel#address()
4860
*/
4961
public InetSocketAddress address() {
50-
return channel.address();
62+
try {
63+
return channel.address();
64+
} catch (NoSuchMethodError e) {
65+
try {
66+
return (InetSocketAddress) channelAddressMethod.invoke(this.channel);
67+
} catch (Exception ex) {
68+
throw new IllegalStateException("Unable to obtain address", ex);
69+
}
70+
}
5171
}
5272

5373
@Override

0 commit comments

Comments
 (0)