1
1
/*
2
- * Copyright 2015-2018 the original author or authors.
2
+ * Copyright 2015-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package io .rsocket .transport .netty .server ;
18
18
19
19
import io .rsocket .Closeable ;
20
+ import java .lang .reflect .Method ;
20
21
import java .net .InetSocketAddress ;
21
22
import java .util .Objects ;
22
23
import reactor .core .publisher .Mono ;
28
29
*/
29
30
public final class CloseableChannel implements Closeable {
30
31
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
+
31
43
private final DisposableChannel channel ;
32
44
33
45
/**
@@ -47,7 +59,15 @@ public final class CloseableChannel implements Closeable {
47
59
* @see DisposableChannel#address()
48
60
*/
49
61
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
+ }
51
71
}
52
72
53
73
@ Override
0 commit comments