List of usage examples for com.google.common.net HostAndPort getPort
public int getPort()
From source file:org.apache.phoenix.end2end.LoadBalancerEnd2EndIT.java
private static void createNodeForTesting(List<HostAndPort> pqsNodes) throws Exception { for (HostAndPort pqs : pqsNodes) { registry.registerServer(LOAD_BALANCER_CONFIGURATION, pqs.getPort(), zkConnectString, pqs.getHostText()); }/*from w w w . j ava 2s . com*/ curatorFramework.getChildren().forPath(LOAD_BALANCER_CONFIGURATION.getParentPath()).size(); }
From source file:io.airlift.drift.integration.LegacyApacheThriftTesterUtil.java
private static TSocket createClientSocket(boolean secure, HostAndPort address) throws TTransportException { if (!secure) { return new TSocket(address.getHost(), address.getPort()); }//from w w w . j ava 2s.c o m try { SSLContext serverSslContext = ClientTestUtils.getClientSslContext(); SSLSocket clientSocket = (SSLSocket) serverSslContext.getSocketFactory().createSocket(address.getHost(), address.getPort()); // clientSocket.setSoTimeout(timeout); return new TSocket(clientSocket); } catch (Exception e) { throw new TTransportException("Error initializing secure socket", e); } }
From source file:com.facebook.presto.client.OkHttpUtil.java
private static InetSocketAddress toUnresolvedAddress(HostAndPort address) { return InetSocketAddress.createUnresolved(address.getHost(), address.getPort()); }
From source file:brooklyn.entity.webapp.WebAppServiceMethods.java
public static String inferBrooklynAccessibleRootUrl(Entity entity) { if (isProtocolEnabled(entity, "https")) { Integer rawPort = entity.getAttribute(HTTPS_PORT); checkNotNull(rawPort, "HTTPS_PORT sensors not set for %s; is an acceptable port available?", entity); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, rawPort); return String.format("https://%s:%s/", hp.getHostText(), hp.getPort()); } else if (isProtocolEnabled(entity, "http")) { Integer rawPort = entity.getAttribute(HTTP_PORT); checkNotNull(rawPort, "HTTP_PORT sensors not set for %s; is an acceptable port available?", entity); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, rawPort); return String.format("http://%s:%s/", hp.getHostText(), hp.getPort()); } else {//from w w w.j a v a 2 s .c o m throw new IllegalStateException("HTTP and HTTPS protocols not enabled for " + entity + "; enabled protocols are " + getEnabledProtocols(entity)); } }
From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java
private static Iterable<InetSocketAddress> getZkAddresses(URI uri) { String zkServers = getZKServersFromDLUri(uri); String[] zkServerList = StringUtils.split(zkServers, ','); ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder(); for (String zkServer : zkServerList) { HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181); builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort())); }// w w w . j a v a 2 s . c o m return builder.build(); }
From source file:org.dcache.utils.net.InetSocketAddresses.java
/** * Convert a {@link String} in a form <code>host:port</code> * into corresponding {@link InetSocketAddress}. * @param address//from w w w. ja v a2s .c o m * @return socketAddress */ public static InetSocketAddress inetAddressOf(String address) { HostAndPort hostAndPort = HostAndPort.fromString(address); return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort()); }
From source file:org.apache.accumulo.core.client.impl.MasterClient.java
public static MasterClientService.Client getConnection(ClientContext context) { checkArgument(context != null, "context is null"); List<String> locations = context.getInstance().getMasterLocations(); if (locations.size() == 0) { log.debug("No masters..."); return null; }/*w w w. j a v a 2 s. c om*/ HostAndPort master = HostAndPort.fromString(locations.get(0)); if (0 == master.getPort()) return null; try { // Master requests can take a long time: don't ever time out MasterClientService.Client client = ThriftUtil .getClientNoTimeout(new MasterClientService.Client.Factory(), master, context); return client; } catch (TTransportException tte) { Throwable cause = tte.getCause(); if (null != cause && cause instanceof UnknownHostException) { // do not expect to recover from this throw new RuntimeException(tte); } log.debug("Failed to connect to master=" + master + ", will retry... ", tte); return null; } }
From source file:com.facebook.presto.hive.thrift.Transport.java
private static Socket createSocksSocket(HostAndPort proxy) { SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHost(), proxy.getPort()); return new Socket(new Proxy(Proxy.Type.SOCKS, address)); }
From source file:org.robotninjas.barge.Replica.java
@Nonnull public static Replica fromString(@Nonnull String info) { try {/* w ww. jav a 2 s .c o m*/ checkNotNull(info); HostAndPort hostAndPort = HostAndPort.fromString(info); InetAddress addr = InetAddress.getByName(hostAndPort.getHostText()); InetSocketAddress saddr = new InetSocketAddress(addr, hostAndPort.getPort()); return new Replica(saddr); } catch (UnknownHostException e) { throw Throwables.propagate(e); } }
From source file:org.robotninjas.barge.NettyReplica.java
@Nonnull public static NettyReplica fromString(@Nonnull String info) { try {// w ww .j a v a2 s .c om checkNotNull(info); HostAndPort hostAndPort = HostAndPort.fromString(info); InetAddress addr = InetAddress.getByName(hostAndPort.getHostText()); InetSocketAddress saddr = new InetSocketAddress(addr, hostAndPort.getPort()); return new NettyReplica(saddr); } catch (UnknownHostException e) { throw Throwables.propagate(e); } }