use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.
the class HttpRedirectTest method doTestHttpServerWithDomainSockets.
private void doTestHttpServerWithDomainSockets(HttpServer server, HttpClient client) {
assumeThat(LoopResources.hasNativeSupport()).isTrue();
disposableServer = server.bindAddress(() -> new DomainSocketAddress("/tmp/test.sock")).wiretap(true).route(r -> r.get("/redirect", (req, res) -> res.sendRedirect("/end")).get("/end", (req, res) -> res.sendString(Mono.just("END")))).bindNow();
String response = client.remoteAddress(disposableServer::address).wiretap(true).followRedirect(true).get().uri("/redirect").responseContent().aggregate().asString().block(Duration.ofSeconds(30));
assertThat(response).isEqualTo("END");
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.
the class ServerTransport method bind.
/**
* Binds the {@link ServerTransport} and returns a {@link Mono} of {@link DisposableServer}. If
* {@link Mono} is cancelled, the underlying binding will be aborted. Once the {@link
* DisposableServer} has been emitted and is not necessary anymore, disposing the main server
* loop must be done by the user via {@link DisposableServer#dispose()}.
*
* @return a {@link Mono} of {@link DisposableServer}
*/
public Mono<? extends DisposableServer> bind() {
CONF config = configuration();
Objects.requireNonNull(config.bindAddress(), "bindAddress");
Mono<? extends DisposableServer> mono = Mono.create(sink -> {
SocketAddress local = Objects.requireNonNull(config.bindAddress().get(), "Bind Address supplier returned null");
if (local instanceof InetSocketAddress) {
InetSocketAddress localInet = (InetSocketAddress) local;
if (localInet.isUnresolved()) {
local = AddressUtils.createResolved(localInet.getHostName(), localInet.getPort());
}
}
boolean isDomainSocket = false;
DisposableBind disposableServer;
if (local instanceof DomainSocketAddress) {
isDomainSocket = true;
disposableServer = new UdsDisposableBind(sink, config, local);
} else {
disposableServer = new InetDisposableBind(sink, config, local);
}
ConnectionObserver childObs = new ChildObserver(config.defaultChildObserver().then(config.childObserver()));
Acceptor acceptor = new Acceptor(config.childEventLoopGroup(), config.channelInitializer(childObs, null, true), config.childOptions, config.childAttrs, isDomainSocket);
TransportConnector.bind(config, new AcceptorInitializer(acceptor), local, isDomainSocket).subscribe(disposableServer);
});
if (config.doOnBind() != null) {
mono = mono.doOnSubscribe(s -> config.doOnBind().accept(config));
}
return mono;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.
the class TransportConnector method connect.
/**
* Connect a {@link Channel} to the remote peer.
*
* @param config the transport configuration
* @param remoteAddress the {@link SocketAddress} to connect to
* @param resolverGroup the resolver which will resolve the address of the unresolved named address
* @param channelInitializer the {@link ChannelInitializer} that will be used for initializing the channel pipeline
* @param eventLoop the {@link EventLoop} to use for handling the channel.
* @return a {@link Mono} of {@link Channel}
*/
public static Mono<Channel> connect(TransportConfig config, SocketAddress remoteAddress, AddressResolverGroup<?> resolverGroup, ChannelInitializer<Channel> channelInitializer, EventLoop eventLoop) {
Objects.requireNonNull(config, "config");
Objects.requireNonNull(remoteAddress, "remoteAddress");
Objects.requireNonNull(resolverGroup, "resolverGroup");
Objects.requireNonNull(channelInitializer, "channelInitializer");
Objects.requireNonNull(eventLoop, "eventLoop");
boolean isDomainAddress = remoteAddress instanceof DomainSocketAddress;
return doInitAndRegister(config, channelInitializer, isDomainAddress, eventLoop).flatMap(channel -> doResolveAndConnect(channel, config, remoteAddress, resolverGroup).onErrorResume(RetryConnectException.class, t -> {
AtomicInteger index = new AtomicInteger(1);
return Mono.defer(() -> doInitAndRegister(config, channelInitializer, isDomainAddress, eventLoop).flatMap(ch -> {
MonoChannelPromise mono = new MonoChannelPromise(ch);
doConnect(t.addresses, config.bindAddress(), mono, index.get());
return mono;
})).retryWhen(Retry.max(t.addresses.size() - 1).filter(RETRY_PREDICATE).doBeforeRetry(sig -> index.incrementAndGet()));
}));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.
the class Application method newDomainSocketAddress.
private static DomainSocketAddress newDomainSocketAddress() {
try {
File tempFile = new File("/tmp/test-server.sock");
tempFile.delete();
tempFile.deleteOnExit();
return new DomainSocketAddress(tempFile);
} catch (Exception e) {
throw new RuntimeException("Error creating a temporary file", e);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress in project reactor-netty by reactor.
the class Application method newDomainSocketAddress.
private static DomainSocketAddress newDomainSocketAddress() {
try {
File tempFile = new File("/tmp/test-client.sock");
tempFile.delete();
tempFile.deleteOnExit();
return new DomainSocketAddress(tempFile);
} catch (Exception e) {
throw new RuntimeException("Error creating a temporary file", e);
}
}
Aggregations