public int getPortOrDefault(int defaultPort) { return hostAndPort.getPortOrDefault(defaultPort); }
private static int extractPort(@Nullable final String hostAndPort) { if (hostAndPort == null) { return -1; } return HostAndPort.fromString(hostAndPort).getPortOrDefault(-1); }
public static URI parseServer(String server) { server = server.toLowerCase(ENGLISH); if (server.startsWith("http://") || server.startsWith("https://")) { return URI.create(server); } HostAndPort host = HostAndPort.fromString(server); try { return new URI("http", null, host.getHost(), host.getPortOrDefault(80), null, null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
public static int getFirstPort(String quorum, int defVal) throws Exception { List<HostAndPort> hostAndPorts = splitToHostsAndPortsStrictly(quorum); int port = hostAndPorts.get(0).getPortOrDefault(defVal); return port; } }
private static URI parseServer(String server) { server = server.toLowerCase(ENGLISH); if (server.startsWith("http://") || server.startsWith("https://")) { return URI.create(server); } HostAndPort host = HostAndPort.fromString(server); try { return new URI("http", null, host.getHost(), host.getPortOrDefault(80), null, null, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
public MinimalTransportClient(Settings settings, Set<HostAndPort> hostAndPorts) { super(settings, unmodifiableList(singletonList(Netty4Plugin.class))); boolean connectedToOneHost = false; for (HostAndPort hostAndPort : hostAndPorts) { try { addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndPort.getHostText()), hostAndPort.getPortOrDefault(9001))); connectedToOneHost = true; } catch (UnknownHostException e) { LOG.debug("Can not resolve host [" + hostAndPort.getHostText() + "]", e); } } if (!connectedToOneHost) { throw new IllegalStateException(format("Can not connect to one node from [%s]", hostAndPorts.stream() .map(h -> format("%s:%d", h.getHostText(), h.getPortOrDefault(9001))) .collect(Collectors.joining(",")))); } }
private static void addHostToClient(HostAndPort host, TransportClient client) { try { client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()), host.getPortOrDefault(9001))); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); } }
private DockerHost(final String endpoint, final String certPath) { if (endpoint.startsWith("unix://")) { this.port = 0; this.address = DEFAULT_ADDRESS; this.host = endpoint; this.uri = URI.create(endpoint); this.bindUri = URI.create(endpoint); } else { final String stripped = endpoint.replaceAll(".*://", ""); final HostAndPort hostAndPort = HostAndPort.fromString(stripped); final String hostText = hostAndPort.getHost(); final String scheme = isNullOrEmpty(certPath) ? "http" : "https"; this.port = hostAndPort.getPortOrDefault(defaultPort()); this.address = isNullOrEmpty(hostText) ? DEFAULT_ADDRESS : hostText; this.host = address + ":" + port; this.uri = URI.create(scheme + "://" + address + ":" + port); this.bindUri = URI.create("tcp://" + address + ":" + port); } this.certPath = certPath; }
public void testGetPortOrDefault() { assertEquals(80, HostAndPort.fromString("host:80").getPortOrDefault(123)); assertEquals(123, HostAndPort.fromString("host").getPortOrDefault(123)); }
final String scheme = certs.isPresent() ? "https" : "http"; final int port = hostAndPort.getPortOrDefault(DockerHost.defaultPort()); final String address = isNullOrEmpty(hostText) ? DockerHost.defaultAddress() : hostText;
/** * Converts wire type to proto type. * * @param fileBlockInfo the wire representation to convert * @return converted proto representation */ public static alluxio.grpc.FileBlockInfo toProto(FileBlockInfo fileBlockInfo) { List<alluxio.grpc.WorkerNetAddress> ufsLocations = new ArrayList<>(); for (String ufsLocation : fileBlockInfo.getUfsLocations()) { HostAndPort address = HostAndPort.fromString(ufsLocation); ufsLocations.add(alluxio.grpc.WorkerNetAddress.newBuilder().setHost(address.getHost()) .setDataPort(address.getPortOrDefault(-1)).build()); } return alluxio.grpc.FileBlockInfo.newBuilder() .setBlockInfo(toProto(fileBlockInfo.getBlockInfo())).setOffset(fileBlockInfo.getOffset()) .addAllUfsLocations(ufsLocations).addAllUfsStringLocations(fileBlockInfo.getUfsLocations()) .build(); }
public SimpleAddressSelector(Iterable<HostAndPort> addresses, boolean retrySameAddress) { for (HostAndPort address : addresses) { checkArgument(address.getPortOrDefault(0) > 0, "address port must be set"); } this.addresses = ImmutableSet.copyOf(addresses); this.retrySameAddress = retrySameAddress; }
/** Returns the consistent port across all contact points or 9042 */ static String parsePort(String contactPoints) { Set<Integer> ports = Sets.newLinkedHashSet(); for (String contactPoint : contactPoints.split(",")) { HostAndPort parsed = HostAndPort.fromString(contactPoint); ports.add(parsed.getPortOrDefault(9042)); } return ports.size() == 1 ? String.valueOf(ports.iterator().next()) : "9042"; }
public static int getFirstPort(String quorum, int defVal) throws BadConfigException { List<HostAndPort> hostAndPorts = splitToHostsAndPortsStrictly(quorum); int port = hostAndPorts.get(0).getPortOrDefault(defVal); return port; } }
static List<InetSocketAddress> parseContactPoints(CassandraStorage cassandra) { List<InetSocketAddress> result = new ArrayList<>(); for (String contactPoint : cassandra.contactPoints.split(",")) { HostAndPort parsed = HostAndPort.fromString(contactPoint); result.add(new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042))); } return result; }
static List<InetSocketAddress> parseContactPoints(CassandraStorage cassandra) { List<InetSocketAddress> result = new ArrayList<>(); for (String contactPoint : cassandra.contactPoints.split(",")) { HostAndPort parsed = HostAndPort.fromString(contactPoint); result.add( new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042))); } return result; }
private static void addHostToClient(HostAndPort host, TransportClient client) { try { client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()), host.getPortOrDefault(9001))); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); } }
public HttpClientConnector(String hostNameAndPort, String servicePath, TDuplexProtocolFactory protocolFactory) throws URISyntaxException { super(new InetSocketAddress(HostAndPort.fromString(hostNameAndPort).getHostText(), HostAndPort.fromString(hostNameAndPort).getPortOrDefault(80)), protocolFactory); this.endpointUri = new URI("http", hostNameAndPort, servicePath, null, null); }
private static void addHostToClient(HostAndPort host, TransportClient client) { try { client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHostText()), host.getPortOrDefault(9001))); } catch (UnknownHostException e) { throw new IllegalStateException("Can not resolve host [" + host + "]", e); } }
public void resetHostConfig(String hostPort) { HostAndPort hostAndPort = HostAndPort.fromString(hostPort); int portOrDefault = hostAndPort.getPortOrDefault(Constants.DEFAULT_DIAMOND_SERVER_PORT); HostConfiguration hostConfiguration = httpClient.getHostConfiguration(); String hostText = hostAndPort.getHost(); hostConfiguration.setHost(hostText, portOrDefault); log.debug("use host {}:{}", hostText, portOrDefault); setBasicAuth(hostText, portOrDefault); }