Java Code Examples for reactor.netty.resources.ConnectionProvider#elastic()

The following examples show how to use reactor.netty.resources.ConnectionProvider#elastic() . 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 5 votes vote down vote up
/**
 * Simple constructor with the host and port to use to connect to.
 * <p>This constructor manages the lifecycle of the {@link TcpClient} and
 * underlying resources such as {@link ConnectionProvider},
 * {@link LoopResources}, and {@link ChannelGroup}.
 * <p>For full control over the initialization and lifecycle of the
 * TcpClient, use {@link #ReactorNettyTcpClient(TcpClient, ReactorNettyCodec)}.
 * @param host the host to connect to
 * @param port the port to connect to
 * @param codec for encoding and decoding the input/output byte streams
 * @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
 */
public ReactorNettyTcpClient(String host, int port, ReactorNettyCodec<P> codec) {
	Assert.notNull(host, "host is required");
	Assert.notNull(codec, "ReactorNettyCodec is required");

	this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
	this.loopResources = LoopResources.create("tcp-client-loop");
	this.poolResources = ConnectionProvider.elastic("tcp-client-pool");
	this.codec = codec;

	this.tcpClient = TcpClient.create(this.poolResources)
			.host(host).port(port)
			.runOn(this.loopResources, false)
			.doOnConnected(conn -> this.channelGroup.add(conn.channel()));
}
 
Example 2
Source File: ReactorNettyTcpClient.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * A variant of {@link #ReactorNettyTcpClient(String, int, ReactorNettyCodec)}
 * that still manages the lifecycle of the {@link TcpClient} and underlying
 * resources, but allows for direct configuration of other properties of the
 * client through a {@code Function<TcpClient, TcpClient>}.
 * @param clientConfigurer the configurer function
 * @param codec for encoding and decoding the input/output byte streams
 * @since 5.1.3
 * @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
 */
public ReactorNettyTcpClient(Function<TcpClient, TcpClient> clientConfigurer, ReactorNettyCodec<P> codec) {
	Assert.notNull(codec, "ReactorNettyCodec is required");

	this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
	this.loopResources = LoopResources.create("tcp-client-loop");
	this.poolResources = ConnectionProvider.elastic("tcp-client-pool");
	this.codec = codec;

	this.tcpClient = clientConfigurer.apply(TcpClient
			.create(this.poolResources)
			.runOn(this.loopResources, false)
			.doOnConnected(conn -> this.channelGroup.add(conn.channel())));
}
 
Example 3
Source File: ReactorNettyTcpClient.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Simple constructor with the host and port to use to connect to.
 * <p>This constructor manages the lifecycle of the {@link TcpClient} and
 * underlying resources such as {@link ConnectionProvider},
 * {@link LoopResources}, and {@link ChannelGroup}.
 * <p>For full control over the initialization and lifecycle of the
 * TcpClient, use {@link #ReactorNettyTcpClient(TcpClient, ReactorNettyCodec)}.
 * @param host the host to connect to
 * @param port the port to connect to
 * @param codec for encoding and decoding the input/output byte streams
 * @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
 */
public ReactorNettyTcpClient(String host, int port, ReactorNettyCodec<P> codec) {
	Assert.notNull(host, "host is required");
	Assert.notNull(codec, "ReactorNettyCodec is required");

	this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
	this.loopResources = LoopResources.create("tcp-client-loop");
	this.poolResources = ConnectionProvider.elastic("tcp-client-pool");
	this.codec = codec;

	this.tcpClient = TcpClient.create(this.poolResources)
			.host(host).port(port)
			.runOn(this.loopResources, false)
			.doOnConnected(conn -> this.channelGroup.add(conn.channel()));
}
 
Example 4
Source File: ReactorNettyTcpClient.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * A variant of {@link #ReactorNettyTcpClient(String, int, ReactorNettyCodec)}
 * that still manages the lifecycle of the {@link TcpClient} and underlying
 * resources, but allows for direct configuration of other properties of the
 * client through a {@code Function<TcpClient, TcpClient>}.
 * @param clientConfigurer the configurer function
 * @param codec for encoding and decoding the input/output byte streams
 * @since 5.1.3
 * @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
 */
public ReactorNettyTcpClient(Function<TcpClient, TcpClient> clientConfigurer, ReactorNettyCodec<P> codec) {
	Assert.notNull(codec, "ReactorNettyCodec is required");

	this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
	this.loopResources = LoopResources.create("tcp-client-loop");
	this.poolResources = ConnectionProvider.elastic("tcp-client-pool");
	this.codec = codec;

	this.tcpClient = clientConfigurer.apply(TcpClient
			.create(this.poolResources)
			.runOn(this.loopResources, false)
			.doOnConnected(conn -> this.channelGroup.add(conn.channel())));
}