|
3 | 3 | import io.reactivesocket.ConnectionSetupPayload; |
4 | 4 | import io.reactivesocket.ReactiveSocket; |
5 | 5 | import io.reactivesocket.ReactiveSocketFactory; |
6 | | -import io.reactivesocket.internal.rx.EmptySubscription; |
7 | 6 | import io.reactivesocket.rx.Completable; |
8 | 7 | import org.reactivestreams.Publisher; |
9 | 8 | import org.reactivestreams.Subscriber; |
10 | 9 | import org.reactivestreams.Subscription; |
11 | 10 | import org.slf4j.Logger; |
12 | 11 | import org.slf4j.LoggerFactory; |
| 12 | +import rx.Observable; |
| 13 | +import rx.RxReactiveStreams; |
13 | 14 | import uk.co.real_logic.agrona.LangUtil; |
14 | 15 |
|
15 | 16 | import java.net.*; |
16 | 17 | import java.util.Enumeration; |
17 | | -import java.util.concurrent.CountDownLatch; |
18 | 18 | import java.util.concurrent.TimeUnit; |
19 | 19 | import java.util.function.Consumer; |
20 | 20 |
|
@@ -47,55 +47,45 @@ public AeronReactiveSocketFactory(String host, int port, ConnectionSetupPayload |
47 | 47 |
|
48 | 48 | @Override |
49 | 49 | public Publisher<ReactiveSocket> call(SocketAddress address, long timeout, TimeUnit timeUnit) { |
50 | | - Publisher<AeronClientDuplexConnection> aeronClientDuplexConnection |
| 50 | + Publisher<AeronClientDuplexConnection> connection |
51 | 51 | = AeronClientDuplexConnectionFactory.getInstance().createAeronClientDuplexConnection(address); |
52 | 52 |
|
53 | | - return (Subscriber<? super ReactiveSocket> s) -> { |
54 | | - s.onSubscribe(EmptySubscription.INSTANCE); |
55 | | - aeronClientDuplexConnection |
56 | | - .subscribe(new Subscriber<AeronClientDuplexConnection>() { |
57 | | - |
58 | | - @Override |
59 | | - public void onSubscribe(Subscription s) { |
60 | | - s.request(1); |
61 | | - } |
62 | | - |
63 | | - @Override |
64 | | - public void onNext(AeronClientDuplexConnection connection) { |
65 | | - ReactiveSocket reactiveSocket = ReactiveSocket.fromClientConnection(connection, connectionSetupPayload, errorStream); |
66 | | - CountDownLatch latch = new CountDownLatch(1); |
67 | | - reactiveSocket.start(new Completable() { |
68 | | - @Override |
69 | | - public void success() { |
70 | | - latch.countDown(); |
71 | | - s.onNext(reactiveSocket); |
72 | | - s.onComplete(); |
73 | | - } |
74 | | - |
75 | | - @Override |
76 | | - public void error(Throwable e) { |
77 | | - s.onError(e); |
78 | | - } |
79 | | - }); |
80 | | - |
81 | | - try { |
82 | | - latch.await(timeout, timeUnit); |
83 | | - } catch (InterruptedException e) { |
84 | | - logger.error(e.getMessage(), e); |
| 53 | + Observable<ReactiveSocket> result = Observable.create(s -> |
| 54 | + connection.subscribe(new Subscriber<AeronClientDuplexConnection>() { |
| 55 | + @Override |
| 56 | + public void onSubscribe(Subscription s) { |
| 57 | + s.request(1); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public void onNext(AeronClientDuplexConnection connection) { |
| 62 | + ReactiveSocket reactiveSocket = ReactiveSocket.fromClientConnection(connection, connectionSetupPayload, errorStream); |
| 63 | + reactiveSocket.start(new Completable() { |
| 64 | + @Override |
| 65 | + public void success() { |
| 66 | + s.onNext(reactiveSocket); |
| 67 | + s.onCompleted(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void error(Throwable e) { |
85 | 72 | s.onError(e); |
86 | 73 | } |
87 | | - } |
88 | | - |
89 | | - @Override |
90 | | - public void onError(Throwable t) { |
91 | | - s.onError(t); |
92 | | - } |
93 | | - |
94 | | - @Override |
95 | | - public void onComplete() { |
96 | | - } |
97 | | - }); |
98 | | - }; |
| 74 | + }); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public void onError(Throwable t) { |
| 79 | + s.onError(t); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public void onComplete() { |
| 84 | + } |
| 85 | + }) |
| 86 | + ); |
| 87 | + |
| 88 | + return RxReactiveStreams.toPublisher(result.timeout(timeout, timeUnit)); |
99 | 89 | } |
100 | 90 |
|
101 | 91 | private static InetAddress getIPv4InetAddress() { |
|
0 commit comments