static void registerForClose(boolean shouldCleanupOnClose, String name, Connection context) { if (!shouldCleanupOnClose) return; context.onTerminate().subscribe(null, null, () -> context.removeHandler(name)); }
static void registerForClose(boolean shouldCleanupOnClose, String name, Connection context) { if (!shouldCleanupOnClose) return; context.onTerminate().subscribe(null, null, () -> context.removeHandler(name)); }
private Mono<Void> closeConnections() { return Mono.defer( () -> Mono.when( connections .stream() .map( connection -> { connection.dispose(); return connection .onTerminate() .doOnError(e -> LOGGER.warn("Failed to close connection: " + e)) .onErrorResume(e -> Mono.empty()); }) .collect(Collectors.toList())) .doOnTerminate(connections::clear)); }
private Mono<Void> closeConnections() { return Mono.defer( () -> Mono.when( connections .stream() .map( connection -> { connection.dispose(); return connection .onTerminate() .doOnError(e -> LOGGER.warn("Failed to close connection: " + e)) .onErrorResume(e -> Mono.empty()); }) .collect(Collectors.toList())) .doOnTerminate(connections::clear)); }
@Override public Mono<Void> stop() { return Mono.defer( () -> { List<Mono<Void>> stopList = new ArrayList<>(); //noinspection unchecked stopList.add(FutureMono.from((Future) ((EventLoopGroup) bossGroup).shutdownGracefully())); connections .stream() .collect( () -> stopList, (list, connection) -> { connection.dispose(); list.add(connection.onTerminate()); }, (monos1, monos2) -> { // no-op }); if (server != null) { server.dispose(); stopList.add(server.onClose()); } return Mono.when(stopList); }); } }
static void autoAddHttpExtractor(Connection c, String name, ChannelHandler handler){ if (handler instanceof ByteToMessageDecoder || handler instanceof ByteToMessageCodec || handler instanceof CombinedChannelDuplexHandler) { String extractorName = name+"$extractor"; if(c.channel().pipeline().context(extractorName) != null){ return; } c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR); if(c.isPersistent()){ c.onTerminate().subscribe(null, null, () -> c.removeHandler(extractorName)); } } }
static void autoAddHttpExtractor(Connection c, String name, ChannelHandler handler){ if (handler instanceof ByteToMessageDecoder || handler instanceof ByteToMessageCodec || handler instanceof CombinedChannelDuplexHandler) { String extractorName = name+"$extractor"; if(c.channel().pipeline().context(extractorName) != null){ return; } c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR); if(c.isPersistent()){ c.onTerminate().subscribe(null, null, () -> c.removeHandler(extractorName)); } } }
/** * Lambda setter for reacting on channel close occurrence. * * @param disposable function to run when disposable would take place */ public Mono<Void> onClose(Disposable disposable) { return Mono.create( sink -> inbound.withConnection( connection -> connection .onDispose(disposable) .onTerminate() .subscribe(sink::success, sink::error, sink::success))); }