Search in sources :

Example 21 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project netty by netty.

the class KQueueServerDomainSocketChannel method doClose.

@Override
protected void doClose() throws Exception {
    try {
        super.doClose();
    } finally {
        DomainSocketAddress local = this.local;
        if (local != null) {
            // Delete the socket file if possible.
            File socketFile = new File(local.path());
            boolean success = socketFile.delete();
            if (!success && logger.isDebugEnabled()) {
                logger.debug("Failed to delete a domain socket file: {}", local.path());
            }
        }
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) File(java.io.File)

Example 22 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project zuul by Netflix.

the class SocketAddressPropertyTest method bindTypeWorks_uds.

@Test
public void bindTypeWorks_uds() {
    SocketAddress address = SocketAddressProperty.Decoder.INSTANCE.apply("UDS=/var/run/zuul.sock");
    assertEquals(DomainSocketAddress.class, address.getClass());
    DomainSocketAddress domainSocketAddress = (DomainSocketAddress) address;
    assertEquals("/var/run/zuul.sock", domainSocketAddress.path());
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) Test(org.junit.Test)

Example 23 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project beam by apache.

the class ManagedChannelFactory method forDescriptor.

public ManagedChannel forDescriptor(ApiServiceDescriptor apiServiceDescriptor) {
    ManagedChannelBuilder<?> channelBuilder;
    switch(type) {
        case EPOLL:
            SocketAddress address = SocketAddressFactory.createFrom(apiServiceDescriptor.getUrl());
            channelBuilder = NettyChannelBuilder.forAddress(address).channelType(address instanceof DomainSocketAddress ? EpollDomainSocketChannel.class : EpollSocketChannel.class).eventLoopGroup(new EpollEventLoopGroup());
            break;
        case DEFAULT:
            channelBuilder = ManagedChannelBuilder.forTarget(apiServiceDescriptor.getUrl());
            break;
        case IN_PROCESS:
            channelBuilder = InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl());
            break;
        default:
            throw new IllegalStateException("Unknown type " + type);
    }
    channelBuilder = channelBuilder.usePlaintext().maxInboundMessageSize(Integer.MAX_VALUE).intercept(interceptors);
    if (directExecutor) {
        channelBuilder = channelBuilder.directExecutor();
    }
    return channelBuilder.build();
}
Also used : EpollEventLoopGroup(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup) EpollDomainSocketChannel(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollDomainSocketChannel) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) EpollSocketChannel(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollSocketChannel) SocketAddress(java.net.SocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress)

Example 24 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project beam by apache.

the class SocketAddressFactory method createFrom.

/**
 * Parse a {@link SocketAddress} from the given string.
 */
public static SocketAddress createFrom(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        // Unix Domain Socket address.
        // Create the underlying file for the Unix Domain Socket.
        String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
        File file = new File(filePath);
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException("File path must be absolute: " + filePath);
        }
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        // Create the SocketAddress referencing the file.
        return new DomainSocketAddress(file);
    } else {
        // Standard TCP/IP address.
        HostAndPort hostAndPort = HostAndPort.fromString(value);
        checkArgument(hostAndPort.hasPort(), "Address must be a unix:// path or be in the form host:port. Got: %s", value);
        return new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort());
    }
}
Also used : HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) File(java.io.File)

Example 25 with DomainSocketAddress

use of io.netty.channel.unix.DomainSocketAddress in project beam by apache.

the class SocketAddressFactoryTest method testDomainSocket.

@Test
public void testDomainSocket() throws Exception {
    File tmpFile = tmpFolder.newFile();
    SocketAddress socketAddress = SocketAddressFactory.createFrom("unix://" + tmpFile.getAbsolutePath());
    assertThat(socketAddress, Matchers.instanceOf(DomainSocketAddress.class));
    assertEquals(tmpFile.getAbsolutePath(), ((DomainSocketAddress) socketAddress).path());
}
Also used : DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress) File(java.io.File) Test(org.junit.Test)

Aggregations

DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)23 File (java.io.File)11 InetSocketAddress (java.net.InetSocketAddress)9 SocketAddress (java.net.SocketAddress)8 IOException (java.io.IOException)7 Test (org.junit.Test)6 ByteString (com.google.protobuf.ByteString)5 ByteBuf (io.netty.buffer.ByteBuf)4 AddressedEnvelope (io.netty.channel.AddressedEnvelope)4 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)4 Test (org.junit.jupiter.api.Test)4 PeerCredentials (io.netty.channel.unix.PeerCredentials)3 SocketTest (io.netty.channel.unix.tests.SocketTest)3 DomainSocketAddress (org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.unix.DomainSocketAddress)3 DomainDatagramPacket (io.netty.channel.unix.DomainDatagramPacket)2 DomainDatagramSocketAddress (io.netty.channel.unix.DomainDatagramSocketAddress)2 IovArray (io.netty.channel.unix.IovArray)2 ByteBuffer (java.nio.ByteBuffer)2 GrpcServerBuilder (alluxio.grpc.GrpcServerBuilder)1 HostAndPort (com.google.common.net.HostAndPort)1