List of usage examples for com.google.common.net HostAndPort getPort
public int getPort()
From source file:org.jclouds.predicates.InetSocketAddressConnect.java
@Override public boolean apply(HostAndPort socketA) { InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA.getPort()); Socket socket = null;//from ww w . java 2 s.c o m try { logger.trace("testing socket %s", socketAddress); socket = new Socket( proxyForURI.apply(URI.create("socket://" + socketA.getHostText() + ":" + socketA.getPort()))); socket.setReuseAddress(false); socket.setSoLinger(false, 1); socket.setSoTimeout(timeout); socket.connect(socketAddress, timeout); } catch (IOException e) { return false; } finally { if (socket != null) { try { socket.close(); } catch (IOException ioe) { // no work to do } } } return true; }
From source file:com.facebook.presto.hive.StaticHiveCluster.java
/** * Create a metastore client connected to the Hive metastore. * <p>/*www .j a v a 2 s . c o m*/ * As per Hive HA metastore behavior, return the first metastore in the list * list of available metastores (i.e. the default metastore) if a connection * can be made, else try another of the metastores at random, until either a * connection succeeds or there are no more fallback metastores. */ @Override public HiveMetastoreClient createMetastoreClient() { List<HostAndPort> metastores = new ArrayList<>(addresses); Collections.shuffle(metastores.subList(1, metastores.size())); TTransportException lastException = null; for (HostAndPort metastore : metastores) { try { return clientFactory.create(metastore.getHostText(), metastore.getPort()); } catch (TTransportException e) { lastException = e; } } throw new PrestoException(HIVE_METASTORE_ERROR, "Failed connecting to Hive metastore: " + addresses, lastException); }
From source file:com.google.devtools.kythe.platform.shared.RemoteFileData.java
public RemoteFileData(String addr) { HostAndPort hp = HostAndPort.fromString(addr); ChannelImpl channel = NettyChannelBuilder.forAddress(new InetSocketAddress(hp.getHostText(), hp.getPort())) .build();//from ww w .j a v a 2 s. c o m stub = FileDataServiceGrpc.newStub(channel); }
From source file:com.streamsets.pipeline.lib.kafka.BaseKafkaValidationUtil.java
@Override public List<HostAndPort> validateKafkaBrokerConnectionString(List<Stage.ConfigIssue> issues, String connectionString, String configGroupName, String configName, Stage.Context context) { List<HostAndPort> kafkaBrokers = new ArrayList<>(); if (connectionString == null || connectionString.isEmpty()) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_06, configName)); } else {/*from w w w . j a v a 2 s.co m*/ String[] brokers = connectionString.split(","); for (String broker : brokers) { try { HostAndPort hostAndPort = HostAndPort.fromString(broker); if (!hostAndPort.hasPort() || hostAndPort.getPort() < 0) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_07, connectionString)); } else { kafkaBrokers.add(hostAndPort); } } catch (IllegalArgumentException e) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_07, connectionString)); } } } return kafkaBrokers; }
From source file:brooklyn.entity.nosql.solr.SolrServerImpl.java
@Override protected void connectSensors() { super.connectSensors(); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getSolrPort()); String solrUri = String.format("http://%s:%d/solr", hp.getHostText(), hp.getPort()); setAttribute(Attributes.MAIN_URI, URI.create(solrUri)); httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS).baseUri(solrUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();// ww w .j a va 2 s . c om }
From source file:org.apache.brooklyn.entity.nosql.solr.SolrServerImpl.java
@Override protected void connectSensors() { super.connectSensors(); HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getSolrPort()); String solrUri = String.format("http://%s:%d/solr", hp.getHostText(), hp.getPort()); sensors().set(Attributes.MAIN_URI, URI.create(solrUri)); httpFeed = HttpFeed.builder().entity(this).period(500, TimeUnit.MILLISECONDS).baseUri(solrUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();// w w w.ja va 2s .com }
From source file:com.streamsets.pipeline.lib.kafka.BaseKafkaValidationUtil.java
@Override public List<HostAndPort> validateZkConnectionString(List<Stage.ConfigIssue> issues, String connectString, String configGroupName, String configName, Stage.Context context) { List<HostAndPort> kafkaBrokers = new ArrayList<>(); if (connectString == null || connectString.isEmpty()) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_06, configName)); return kafkaBrokers; }/*from www . j av a 2 s. c om*/ String chrootPath; int off = connectString.indexOf('/'); if (off >= 0) { chrootPath = connectString.substring(off); // ignore a single "/". Same as null. Anything longer must be validated if (chrootPath.length() > 1) { try { PathUtils.validatePath(chrootPath); } catch (IllegalArgumentException e) { LOG.error(Utils.format(KafkaErrors.KAFKA_09.getMessage(), connectString, e.toString())); issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, e.toString())); } } connectString = connectString.substring(0, off); } String brokers[] = connectString.split(","); for (String broker : brokers) { try { HostAndPort hostAndPort = HostAndPort.fromString(broker); if (!hostAndPort.hasPort() || hostAndPort.getPort() < 0) { issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, "Valid port must be specified")); } else { kafkaBrokers.add(hostAndPort); } } catch (IllegalArgumentException e) { LOG.error(Utils.format(KafkaErrors.KAFKA_09.getMessage(), connectString, e.toString())); issues.add(context.createConfigIssue(configGroupName, configName, KafkaErrors.KAFKA_09, connectString, e.toString())); } } return kafkaBrokers; }
From source file:brooklyn.networking.portforwarding.subnet.JcloudsPortforwardingSubnetMachineLocation.java
@Override public HostAndPort getSocketEndpointFor(Cidr accessor, int privatePort) { PortForwardManager pfw = getRequiredConfig(PORT_FORWARDING_MANAGER); PortForwarder portForwarder = getRequiredConfig(PORT_FORWARDER); synchronized (pfw) { HostAndPort hp = pfw.lookup(this, privatePort); if (hp != null) return hp; // TODO What to use for associate's publicIpId? HostAndPort result = portForwarder.openPortForwarding(this, privatePort, Optional.<Integer>absent(), Protocol.TCP, accessor); pfw.associate(getJcloudsId(), result.getPort(), this, privatePort); return result; }/*from w ww . ja v a2 s.com*/ }
From source file:org.mayocat.shop.application.MayocatShopService.java
@Override public void run(MayocatShopSettings configuration, Environment environment) throws Exception { super.run(configuration, environment); if (configuration.getDevelopmentEnvironment().isEnabled()) { HostAndPort hp = HostAndPort.fromString(configuration.getSiteSettings().getDomainName()); swaggerDropwizard.onRun(configuration, environment, hp.getHostText(), hp.getPort()); }//from w ww . j a v a 2 s . c o m }
From source file:com.facebook.presto.hive.DiscoveryLocatedHiveCluster.java
@Override public HiveMetastoreClient createMetastoreClient() { List<ServiceDescriptor> descriptors = selector.selectAllServices().stream() .filter(input -> input.getState() != ServiceState.STOPPED).collect(toList()); if (descriptors.isEmpty()) { throw new DiscoveryException("No metastore servers available for pool: " + selector.getPool()); }/*w w w .j a v a 2s .c om*/ Collections.shuffle(descriptors); TTransportException lastException = null; for (ServiceDescriptor descriptor : descriptors) { String thrift = descriptor.getProperties().get("thrift"); if (thrift != null) { try { HostAndPort metastore = HostAndPort.fromString(thrift); checkArgument(metastore.hasPort()); return clientFactory.create(metastore.getHostText(), metastore.getPort()); } catch (IllegalArgumentException ignored) { // Ignore entries with parse issues } catch (TTransportException e) { lastException = e; } } } throw new DiscoveryException("Unable to connect to any metastore servers in pool: " + selector.getPool(), lastException); }