Search in sources :

Example 36 with DomainSocketAddress

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");
}
Also used : StepVerifier(reactor.test.StepVerifier) Http11SslContextSpec(reactor.netty.http.Http11SslContextSpec) SocketUtils(reactor.netty.SocketUtils) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) HttpProtocol(reactor.netty.http.HttpProtocol) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2SslContextSpec(reactor.netty.http.Http2SslContextSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BaseHttpTest(reactor.netty.BaseHttpTest) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) InsecureTrustManagerFactory(io.netty.handler.ssl.util.InsecureTrustManagerFactory) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Connection(reactor.netty.Connection) LoopResources(reactor.netty.resources.LoopResources) HttpContent(io.netty.handler.codec.http.HttpContent) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) HttpMethod(io.netty.handler.codec.http.HttpMethod) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) BlockingQueue(java.util.concurrent.BlockingQueue) Mono(reactor.core.publisher.Mono) CertificateException(java.security.cert.CertificateException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) HttpServer(reactor.netty.http.server.HttpServer) SslHandler(io.netty.handler.ssl.SslHandler) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DisposableServer(reactor.netty.DisposableServer) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 37 with DomainSocketAddress

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;
}
Also used : AttributeKey(io.netty.util.AttributeKey) SocketAddress(java.net.SocketAddress) ChannelOption(io.netty.channel.ChannelOption) AbortedException(reactor.netty.channel.AbortedException) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) ReactorNetty.format(reactor.netty.ReactorNetty.format) MonoSink(reactor.core.publisher.MonoSink) Nullable(reactor.util.annotation.Nullable) ArrayList(java.util.ArrayList) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ConnectionObserver(reactor.netty.ConnectionObserver) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Duration(java.time.Duration) Map(java.util.Map) ChannelFutureListener(io.netty.channel.ChannelFutureListener) Logger(reactor.util.Logger) Connection(reactor.netty.Connection) LoopResources(reactor.netty.resources.LoopResources) DecoderException(io.netty.handler.codec.DecoderException) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) Operators(reactor.core.publisher.Operators) ChannelOperations(reactor.netty.channel.ChannelOperations) Context(reactor.util.context.Context) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) InetSocketAddress(java.net.InetSocketAddress) ChannelBindException(reactor.netty.ChannelBindException) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Channel(io.netty.channel.Channel) List(java.util.List) ChannelConfig(io.netty.channel.ChannelConfig) Subscription(org.reactivestreams.Subscription) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelHandler(io.netty.channel.ChannelHandler) ConnectionProvider(reactor.netty.resources.ConnectionProvider) DisposableServer(reactor.netty.DisposableServer) InetSocketAddress(java.net.InetSocketAddress) ConnectionObserver(reactor.netty.ConnectionObserver) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 38 with DomainSocketAddress

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()));
    }));
}
Also used : AttributeKey(io.netty.util.AttributeKey) ChannelOption(io.netty.channel.ChannelOption) Retry(reactor.util.retry.Retry) SocketAddress(java.net.SocketAddress) ReactorNetty.format(reactor.netty.ReactorNetty.format) Nullable(reactor.util.annotation.Nullable) Supplier(java.util.function.Supplier) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) ChannelPromise(io.netty.channel.ChannelPromise) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Logger(reactor.util.Logger) Map(java.util.Map) ChannelFactory(io.netty.channel.ChannelFactory) Connection(reactor.netty.Connection) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) AddressResolver(io.netty.resolver.AddressResolver) ChannelInitializer(io.netty.channel.ChannelInitializer) FutureListener(io.netty.util.concurrent.FutureListener) AtomicReferenceFieldUpdater(java.util.concurrent.atomic.AtomicReferenceFieldUpdater) Predicate(java.util.function.Predicate) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) Mono(reactor.core.publisher.Mono) EventLoop(io.netty.channel.EventLoop) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) List(java.util.List) Subscription(org.reactivestreams.Subscription) Future(io.netty.util.concurrent.Future) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 39 with DomainSocketAddress

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);
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) File(java.io.File)

Example 40 with DomainSocketAddress

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);
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) File(java.io.File)

Aggregations

DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)42 File (java.io.File)15 InetSocketAddress (java.net.InetSocketAddress)15 SocketAddress (java.net.SocketAddress)14 IOException (java.io.IOException)9 Test (org.junit.jupiter.api.Test)8 Connection (reactor.netty.Connection)7 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)6 Mono (reactor.core.publisher.Mono)5 DisposableServer (reactor.netty.DisposableServer)5 ByteString (com.google.protobuf.ByteString)4 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)4 Duration (java.time.Duration)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 LoopResources (reactor.netty.resources.LoopResources)4 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3