reactor.netty.NettyInbound Java Examples

The following examples show how to use reactor.netty.NettyInbound. 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 vote down vote up
@Override
@SuppressWarnings("unchecked")
public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound) {
	inbound.withConnection(conn -> {
		if (logger.isDebugEnabled()) {
			logger.debug("Connected to " + conn.address());
		}
	});
	DirectProcessor<Void> completion = DirectProcessor.create();
	TcpConnection<P> connection = new ReactorNettyTcpConnection<>(inbound, outbound,  codec, completion);
	scheduler.schedule(() -> this.connectionHandler.afterConnected(connection));

	inbound.withConnection(conn -> conn.addHandler(new StompMessageDecoder<>(codec)));

	inbound.receiveObject()
			.cast(Message.class)
			.publishOn(scheduler, PUBLISH_ON_BUFFER_SIZE)
			.subscribe(
					this.connectionHandler::handleMessage,
					this.connectionHandler::handleFailure,
					this.connectionHandler::afterConnectionClosed);

	return completion;
}
 
Example #2
Source File: ReactorNettyTcpClient.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound) {
	inbound.withConnection(conn -> {
		if (logger.isDebugEnabled()) {
			logger.debug("Connected to " + conn.address());
		}
	});
	DirectProcessor<Void> completion = DirectProcessor.create();
	TcpConnection<P> connection = new ReactorNettyTcpConnection<>(inbound, outbound,  codec, completion);
	scheduler.schedule(() -> this.connectionHandler.afterConnected(connection));

	inbound.withConnection(conn -> conn.addHandler(new StompMessageDecoder<>(codec)));

	inbound.receiveObject()
			.cast(Message.class)
			.publishOn(scheduler, PUBLISH_ON_BUFFER_SIZE)
			.subscribe(
					this.connectionHandler::handleMessage,
					this.connectionHandler::handleFailure,
					this.connectionHandler::afterConnectionClosed);

	return completion;
}
 
Example #3
Source File: ReactorNettyTcpConnection.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public ReactorNettyTcpConnection(NettyInbound inbound, NettyOutbound outbound,
		ReactorNettyCodec<P> codec, DirectProcessor<Void> closeProcessor) {

	this.inbound = inbound;
	this.outbound = outbound;
	this.codec = codec;
	this.closeProcessor = closeProcessor;
}
 
Example #4
Source File: ClientResponse.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
ClientResponse(HttpClientResponse response, NettyInbound inbound, ExchangeStrategies exchangeStrategies,
               ClientRequest clientRequest, List<ResponseFunction> responseFunctions) {
    this.response = response;
    this.inbound = inbound;
    this.exchangeStrategies = exchangeStrategies;
    this.clientRequest = clientRequest;
    this.responseFunctions = responseFunctions;
}
 
Example #5
Source File: TcpClient.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(Connection c) {
	if (log.isDebugEnabled()) {
		log.debug(format(c.channel(), "Handler is being applied: {}"), handler);
	}

	Mono.fromDirect(handler.apply((NettyInbound) c, (NettyOutbound) c))
	    .subscribe(c.disposeSubscriber());
}
 
Example #6
Source File: ReactorNettyTcpConnection.java    From java-technology-stack with MIT License 4 votes vote down vote up
public ReactorNettyTcpConnection(NettyInbound inbound, NettyOutbound outbound,
		ReactorNettyCodec<P> codec, DirectProcessor<Void> closeProcessor) {

	this.inbound = inbound;
	this.outbound = outbound;
	this.codec = codec;
	this.closeProcessor = closeProcessor;
}
 
Example #7
Source File: ReactorClientHttpConnector.java    From java-technology-stack with MIT License 4 votes vote down vote up
private ClientHttpResponse adaptResponse(HttpClientResponse response, NettyInbound nettyInbound,
		ByteBufAllocator allocator) {

	return new ReactorClientHttpResponse(response, nettyInbound, allocator);
}
 
Example #8
Source File: ReactorClientHttpResponse.java    From java-technology-stack with MIT License 4 votes vote down vote up
public ReactorClientHttpResponse(HttpClientResponse response, NettyInbound inbound, ByteBufAllocator alloc) {
	this.response = response;
	this.inbound = inbound;
	this.bufferFactory = new NettyDataBufferFactory(alloc);
}
 
Example #9
Source File: ChannelOperations.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Override
public NettyInbound inbound() {
	return this;
}
 
Example #10
Source File: TcpClient.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
OnConnectedHandle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	this.handler = handler;
}
 
Example #11
Source File: ReactorClientHttpResponse.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ReactorClientHttpResponse(HttpClientResponse response, NettyInbound inbound, ByteBufAllocator alloc) {
	this.response = response;
	this.inbound = inbound;
	this.bufferFactory = new NettyDataBufferFactory(alloc);
}
 
Example #12
Source File: TcpServer.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
OnConnectionHandle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	this.handler = handler;
}
 
Example #13
Source File: HttpClientTcpConfig.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Override
public TcpClient handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	throw new UnsupportedOperationException();
}
 
Example #14
Source File: HttpServerTcpConfig.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Override
public TcpServer handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	httpServer = httpServer.handle(handler);
	return this;
}
 
Example #15
Source File: TcpServerTests.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Test
public void exposesNettyPipelineConfiguration() throws InterruptedException {
	final int port = SocketUtils.findAvailableTcpPort();
	final CountDownLatch latch = new CountDownLatch(2);

	final TcpClient client = TcpClient.create().port(port);

	BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>
			serverHandler = (in, out) -> {
		in.receive()
		  .asString()
		  .subscribe(data -> {
		      log.info("data " + data + " on " + in);
		      latch.countDown();
		  });
		return Flux.never();
	};

	TcpServer server = TcpServer.create()
	                            .doOnConnection(c -> c.addHandlerLast("codec",
	                                                                  new LineBasedFrameDecoder(8 * 1024)))
	                            .port(port);

	DisposableServer connected = server.handle(serverHandler)
	                                   .wiretap(true)
	                                   .bindNow();

	assertNotNull(connected);

	Connection clientContext =
			client.handle((in, out) -> out.sendString(Flux.just("Hello World!\n", "Hello 11!\n")))
			      .wiretap(true)
			      .connectNow();

	assertNotNull(clientContext);

	assertTrue("Latch was counted down", latch.await(10, TimeUnit.SECONDS));

	connected.disposeNow();
	clientContext.disposeNow();
}
 
Example #16
Source File: ReactorClientHttpConnector.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private ClientHttpResponse adaptResponse(HttpClientResponse response, NettyInbound nettyInbound,
		ByteBufAllocator allocator) {

	return new ReactorClientHttpResponse(response, nettyInbound, allocator);
}
 
Example #17
Source File: TcpClient.java    From reactor-netty with Apache License 2.0 2 votes vote down vote up
/**
 * Attach an IO handler to react on connected client
 *
 * @param handler an IO handler that can dispose underlying connection when {@link
 * Publisher} terminates.
 *
 * @return a new {@link TcpClient}
 */
public TcpClient handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	Objects.requireNonNull(handler, "handler");
	return doOnConnected(new OnConnectedHandle(handler));
}
 
Example #18
Source File: TcpServer.java    From reactor-netty with Apache License 2.0 2 votes vote down vote up
/**
 * Attaches an I/O handler to react on a connected client
 *
 * @param handler an I/O handler that can dispose underlying connection when
 * {@link Publisher} terminates.
 *
 * @return a new {@link TcpServer}
 */
public TcpServer handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
	Objects.requireNonNull(handler, "handler");
	return doOnConnection(new OnConnectionHandle(handler));
}