Search in sources :

Example 16 with DomainSocketAddress

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

the class GrpcDataServer method createServerBuilder.

private GrpcServerBuilder createServerBuilder(String hostName, SocketAddress bindAddress, ChannelType type) {
    // Create an executor for Worker RPC server.
    mRPCExecutor = ExecutorServiceBuilder.buildExecutorService(ExecutorServiceBuilder.RpcExecutorHost.WORKER);
    MetricsSystem.registerGaugeIfAbsent(MetricKey.WORKER_RPC_QUEUE_LENGTH.getName(), mRPCExecutor::getRpcQueueLength);
    // Create underlying gRPC server.
    GrpcServerBuilder builder = GrpcServerBuilder.forAddress(GrpcServerAddress.create(hostName, bindAddress), ServerConfiguration.global(), ServerUserState.global()).executor(mRPCExecutor);
    int bossThreadCount = ServerConfiguration.getInt(PropertyKey.WORKER_NETWORK_NETTY_BOSS_THREADS);
    // If number of worker threads is 0, Netty creates (#processors * 2) threads by default.
    int workerThreadCount = ServerConfiguration.getInt(PropertyKey.WORKER_NETWORK_NETTY_WORKER_THREADS);
    String dataServerEventLoopNamePrefix = "data-server-" + ((mSocketAddress instanceof DomainSocketAddress) ? "domain-socket" : "tcp-socket");
    mBossGroup = NettyUtils.createEventLoop(type, bossThreadCount, dataServerEventLoopNamePrefix + "-boss-%d", true);
    mWorkerGroup = NettyUtils.createEventLoop(type, workerThreadCount, dataServerEventLoopNamePrefix + "-worker-%d", true);
    Class<? extends ServerChannel> socketChannelClass = NettyUtils.getServerChannelClass(mSocketAddress instanceof DomainSocketAddress, ServerConfiguration.global());
    if (type == ChannelType.EPOLL) {
        builder.withChildOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    }
    return builder.bossEventLoopGroup(mBossGroup).workerEventLoopGroup(mWorkerGroup).channelType(socketChannelClass).withChildOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).withChildOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, (int) ServerConfiguration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_HIGH)).withChildOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) ServerConfiguration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_LOW));
}
Also used : GrpcServerBuilder(alluxio.grpc.GrpcServerBuilder) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 17 with DomainSocketAddress

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

the class EpollSocketTestPermutation method newSocketAddress.

public static DomainSocketAddress newSocketAddress() {
    try {
        File file = File.createTempFile("netty", "dsocket");
        file.delete();
        return new DomainSocketAddress(file);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) File(java.io.File)

Example 18 with DomainSocketAddress

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

the class KQueueSocketTest method testPeerPID.

@Test
public void testPeerPID() throws IOException {
    BsdSocket s1 = BsdSocket.newSocketDomain();
    BsdSocket s2 = BsdSocket.newSocketDomain();
    try {
        DomainSocketAddress dsa = UnixTestUtils.newDomainSocketAddress();
        s1.bind(dsa);
        s1.listen(1);
        // PID of client socket is expected to be 0 before connection
        assertEquals(0, s2.getPeerCredentials().pid());
        assertTrue(s2.connect(dsa));
        byte[] addr = new byte[64];
        int clientFd = s1.accept(addr);
        assertNotEquals(-1, clientFd);
        PeerCredentials pc = new BsdSocket(clientFd).getPeerCredentials();
        assertNotEquals(0, pc.pid());
        assertNotEquals(0, s2.getPeerCredentials().pid());
        // Server socket FDs should not have pid field set:
        assertEquals(0, s1.getPeerCredentials().pid());
    } finally {
        s1.close();
        s2.close();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) PeerCredentials(io.netty.channel.unix.PeerCredentials) Test(org.junit.jupiter.api.Test) SocketTest(io.netty.channel.unix.tests.SocketTest)

Example 19 with DomainSocketAddress

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

the class EpollSocketTest method testPeerCreds.

@Test
public void testPeerCreds() throws IOException {
    LinuxSocket s1 = LinuxSocket.newSocketDomain();
    LinuxSocket s2 = LinuxSocket.newSocketDomain();
    try {
        DomainSocketAddress dsa = UnixTestUtils.newDomainSocketAddress();
        s1.bind(dsa);
        s1.listen(1);
        assertTrue(s2.connect(dsa));
        byte[] addr = new byte[64];
        s1.accept(addr);
        PeerCredentials pc = s1.getPeerCredentials();
        assertNotEquals(pc.uid(), -1);
    } finally {
        s1.close();
        s2.close();
    }
}
Also used : DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) PeerCredentials(io.netty.channel.unix.PeerCredentials) Test(org.junit.jupiter.api.Test) SocketTest(io.netty.channel.unix.tests.SocketTest)

Example 20 with DomainSocketAddress

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

the class EpollServerDomainSocketChannel 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)

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