org.springframework.messaging.tcp.ReconnectStrategy Java Examples
The following examples show how to use
org.springframework.messaging.tcp.ReconnectStrategy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactorNettyTcpClient.java From spring-analysis-note with MIT License | 6 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<P> handler, ReconnectStrategy strategy) { Assert.notNull(handler, "TcpConnectionHandler is required"); Assert.notNull(strategy, "ReconnectStrategy is required"); if (this.stopping) { return handleShuttingDownConnectFailure(handler); } // Report first connect to the ListenableFuture MonoProcessor<Void> connectMono = MonoProcessor.create(); this.tcpClient .handle(new ReactorNettyHandler(handler)) .connect() .doOnNext(updateConnectMono(connectMono)) .doOnError(updateConnectMono(connectMono)) .doOnError(handler::afterConnectFailure) // report all connect failures to the handler .flatMap(Connection::onDispose) // post-connect issues .retryWhen(reconnectFunction(strategy)) .repeatWhen(reconnectFunction(strategy)) .subscribe(); return new MonoToListenableFutureAdapter<>(connectMono); }
Example #2
Source File: ReactorNettyTcpClient.java From java-technology-stack with MIT License | 6 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<P> handler, ReconnectStrategy strategy) { Assert.notNull(handler, "TcpConnectionHandler is required"); Assert.notNull(strategy, "ReconnectStrategy is required"); if (this.stopping) { return handleShuttingDownConnectFailure(handler); } // Report first connect to the ListenableFuture MonoProcessor<Void> connectMono = MonoProcessor.create(); this.tcpClient .handle(new ReactorNettyHandler(handler)) .connect() .doOnNext(updateConnectMono(connectMono)) .doOnError(updateConnectMono(connectMono)) .doOnError(handler::afterConnectFailure) // report all connect failures to the handler .flatMap(Connection::onDispose) // post-connect issues .retryWhen(reconnectFunction(strategy)) .repeatWhen(reconnectFunction(strategy)) .subscribe(); return new MonoToListenableFutureAdapter<>(connectMono); }
Example #3
Source File: Reactor2TcpClient.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<P> connectionHandler, ReconnectStrategy strategy) { Assert.notNull(connectionHandler, "TcpConnectionHandler must not be null"); Assert.notNull(strategy, "ReconnectStrategy must not be null"); TcpClient<Message<P>, Message<P>> tcpClient; synchronized (this.tcpClients) { if (this.stopping) { IllegalStateException ex = new IllegalStateException("Shutting down."); connectionHandler.afterConnectFailure(ex); return new PassThroughPromiseToListenableFutureAdapter<Void>(Promises.<Void>error(ex)); } tcpClient = NetStreams.tcpClient(REACTOR_TCP_CLIENT_TYPE, this.tcpClientSpecFactory); this.tcpClients.add(tcpClient); } Stream<Tuple2<InetSocketAddress, Integer>> stream = tcpClient.start( new MessageChannelStreamHandler<P>(connectionHandler), new ReactorReconnectAdapter(strategy)); return new PassThroughPromiseToListenableFutureAdapter<Void>(stream.next().after()); }
Example #4
Source File: ReactorNettyTcpClient.java From spring-analysis-note with MIT License | 5 votes |
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) { return flux -> flux .scan(1, (count, element) -> count++) .flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt)) .map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler)) .orElse(Mono.empty())); }
Example #5
Source File: ReactorNettyTcpClient.java From java-technology-stack with MIT License | 5 votes |
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) { return flux -> flux .scan(1, (count, element) -> count++) .flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt)) .map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler)) .orElse(Mono.empty())); }
Example #6
Source File: StompBrokerRelayMessageHandlerTests.java From spring-analysis-note with MIT License | 4 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<byte[]> handler, ReconnectStrategy strategy) { this.connectionHandler = handler; handler.afterConnected(this.connection); return getVoidFuture(); }
Example #7
Source File: StompBrokerRelayMessageHandlerTests.java From java-technology-stack with MIT License | 4 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<byte[]> handler, ReconnectStrategy strategy) { this.connectionHandler = handler; handler.afterConnected(this.connection); return getVoidFuture(); }
Example #8
Source File: Reactor2TcpClient.java From spring4-understanding with Apache License 2.0 | 4 votes |
public ReactorReconnectAdapter(ReconnectStrategy strategy) { this.strategy = strategy; }
Example #9
Source File: StompBrokerRelayMessageHandlerTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public ListenableFuture<Void> connect(TcpConnectionHandler<byte[]> handler, ReconnectStrategy strategy) { this.connectionHandler = handler; handler.afterConnected(this.connection); return getVoidFuture(); }