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));
}
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);
}
}
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();
}
}
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();
}
}
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());
}
}
}
}
Aggregations