|
3 | 3 | import com.fasterxml.jackson.core.type.TypeReference; |
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
5 | 5 | import com.google.common.base.Throwables; |
6 | | -import io.rsocket.Closeable; |
7 | 6 | import io.rsocket.Payload; |
8 | | -import reactor.core.Disposable; |
9 | | -import reactor.core.publisher.Flux; |
10 | | -import reactor.core.publisher.Mono; |
11 | | - |
12 | 7 | import java.io.IOException; |
13 | 8 | import java.util.Map; |
14 | 9 | import java.util.concurrent.atomic.AtomicReference; |
15 | | -import java.util.function.Consumer; |
| 10 | +import reactor.core.Disposable; |
| 11 | +import reactor.core.publisher.Flux; |
| 12 | +import reactor.core.publisher.Mono; |
16 | 13 |
|
17 | 14 | public class JsonUtil { |
18 | | - public static Map<String, Object> parseTCKMessage(Payload content, String messageType) { |
19 | | - ObjectMapper mapper = new ObjectMapper(); |
20 | | - try { |
21 | | - Map<String, Map<String, Object>> message = mapper.readValue(content.getDataUtf8(), new TypeReference<Map<String, Map<String, Object>>>() { |
22 | | - }); |
23 | | - return message.get(messageType); |
24 | | - } catch (IOException e) { |
25 | | - throw Throwables.propagate(e); |
26 | | - } |
| 15 | + public static Map<String, Object> parseTCKMessage(Payload content, String messageType) { |
| 16 | + ObjectMapper mapper = new ObjectMapper(); |
| 17 | + try { |
| 18 | + Map<String, Map<String, Object>> message = |
| 19 | + mapper.readValue( |
| 20 | + content.getDataUtf8(), new TypeReference<Map<String, Map<String, Object>>>() {}); |
| 21 | + return message.get(messageType); |
| 22 | + } catch (IOException e) { |
| 23 | + throw Throwables.propagate(e); |
27 | 24 | } |
| 25 | + } |
| 26 | + |
| 27 | + public static void main(String[] args) throws InterruptedException { |
| 28 | + Flux<String> server = Flux.just("1", "2", "3"); |
| 29 | + |
| 30 | + Flux<String> client = |
| 31 | + server.transform( |
| 32 | + s -> { |
| 33 | + AtomicReference<Disposable> closeable = new AtomicReference<>(); |
| 34 | + Flux<String> hotServer = s.publish().autoConnect(1, closeable::set); |
| 35 | + |
| 36 | + return hotServer |
| 37 | + .take(1) |
| 38 | + .single() |
| 39 | + .flatMap(x -> Mono.just(x + "a")) |
| 40 | + .doFinally(sig -> closeable.get().dispose()); |
| 41 | + }); |
28 | 42 |
|
29 | | - public static void main(String[] args) throws InterruptedException { |
30 | | - Flux<String> server = Flux.just("1", "2", "3"); |
31 | | - |
32 | | - Flux<String> client = server.transform(s -> { |
33 | | - AtomicReference<Disposable> closeable = new AtomicReference<>(); |
34 | | - Flux<String> hotServer = s.publish().autoConnect(1, closeable::set); |
35 | | - |
36 | | - return hotServer.take(1).single().flatMap(x -> Mono.just(x + "a")).doFinally(sig -> closeable.get().dispose()); |
37 | | - }); |
38 | | - |
39 | | - System.out.println(client.blockFirst()); |
| 43 | + System.out.println(client.blockFirst()); |
40 | 44 |
|
41 | | - Thread.sleep(1000); |
42 | | - } |
| 45 | + Thread.sleep(1000); |
| 46 | + } |
43 | 47 | } |
0 commit comments