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