use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort 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 org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort in project beam by apache.
the class GrpcWindmillServer method initializeWindmillService.
private synchronized void initializeWindmillService(Set<HostAndPort> endpoints) throws IOException {
LOG.info("Initializing Streaming Engine GRPC client for endpoints: {}", endpoints);
this.stubList.clear();
this.syncStubList.clear();
this.endpoints = ImmutableSet.<HostAndPort>copyOf(endpoints);
for (HostAndPort endpoint : this.endpoints) {
if ("localhost".equals(endpoint.getHost())) {
initializeLocalHost(endpoint.getPort());
} else {
CallCredentials creds = MoreCallCredentials.from(new VendoredCredentialsAdapter(options.getGcpCredential()));
this.stubList.add(CloudWindmillServiceV1Alpha1Grpc.newStub(remoteChannel(endpoint)).withCallCredentials(creds));
this.syncStubList.add(CloudWindmillServiceV1Alpha1Grpc.newBlockingStub(remoteChannel(endpoint)).withCallCredentials(creds));
}
}
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort in project beam by apache.
the class ServerFactoryTest method defaultServerWithPortSupplier.
@Test
public void defaultServerWithPortSupplier() throws Exception {
Endpoints.ApiServiceDescriptor apiServiceDescriptor = runTestUsing(ServerFactory.createWithPortSupplier(() -> 65535), ManagedChannelFactory.createDefault());
HostAndPort hostAndPort = HostAndPort.fromString(apiServiceDescriptor.getUrl());
assertThat(hostAndPort.getHost(), anyOf(equalTo(InetAddress.getLoopbackAddress().getHostName()), equalTo(InetAddress.getLoopbackAddress().getHostAddress())));
assertThat(hostAndPort.getPort(), is(65535));
}
Aggregations