List of usage examples for com.google.common.net HostAndPort getPort
public int getPort()
From source file:brooklyn.entity.webapp.nodejs.NodeJsWebAppServiceImpl.java
@Override protected void connectSensors() { super.connectSensors(); ConfigToAttributes.apply(this); HostAndPort accessible = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getHttpPort()); String nodeJsUrl = String.format("http://%s:%d", accessible.getHostText(), accessible.getPort()); LOG.info("Connecting to {}", nodeJsUrl); httpFeed = HttpFeed.builder().entity(this).baseUri(nodeJsUrl) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).suburl(getConfig(NodeJsWebAppService.SERVICE_UP_PATH)) .checkSuccess(Predicates.alwaysTrue()).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .setOnException(false)) .build();/*w w w . java2 s.c o m*/ WebAppServiceMethods.connectWebAppServerPolicies(this); }
From source file:org.graylog.plugins.metrics.mongodb.providers.MongoDBReporterProvider.java
private ServerAddress[] extractServerAddresses(MongoClientURI mongoClientURI) { final List<String> hosts = mongoClientURI.getHosts(); final List<ServerAddress> serverAddresses = new ArrayList<>(hosts.size()); for (String host : hosts) { final HostAndPort hostAndPort = HostAndPort.fromString(host) .withDefaultPort(ServerAddress.defaultPort()); final ServerAddress serverAddress = new ServerAddress(hostAndPort.getHostText(), hostAndPort.getPort()); serverAddresses.add(serverAddress); }/* w w w . j av a 2 s . c om*/ return serverAddresses.toArray(new ServerAddress[serverAddresses.size()]); }
From source file:org.apache.brooklyn.entity.nosql.mongodb.sharding.MongoDBConfigServerClusterImpl.java
@Override public void start(Collection<? extends Location> locs) { super.start(locs); // TODO this should be an enricher Iterable<String> memberHostNamesAndPorts = Iterables.transform(getMembers(), new Function<Entity, String>() { @Override//ww w. jav a 2 s.c o m public String apply(Entity entity) { HostAndPort hostAndPort = BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, entity.getAttribute(MongoDBConfigServer.PORT)); return hostAndPort.getHostText() + ":" + hostAndPort.getPort(); } }); sensors().set(MongoDBConfigServerCluster.CONFIG_SERVER_ADDRESSES, ImmutableList.copyOf(memberHostNamesAndPorts)); }
From source file:de.uniulm.omi.cloudiator.sword.base.BaseConnectionService.java
@Override public RemoteConnection getRemoteConnection(HostAndPort hostAndPort, RemoteType remoteType, LoginCredential loginCredential) throws RemoteException { return this.remoteConnectionFactory.createRemoteConnection(hostAndPort.getHostText(), remoteType, loginCredential, hostAndPort.getPort()); }
From source file:com.splicemachine.stream.RemoteQueryClientImpl.java
@Override public void submit() throws StandardException { Activation activation = root.getActivation(); ActivationHolder ah = new ActivationHolder(activation, root); try {/* w w w. j a va2 s . com*/ updateLimitOffset(); int streamingBatches = HConfiguration.getConfiguration().getSparkResultStreamingBatches(); int streamingBatchSize = HConfiguration.getConfiguration().getSparkResultStreamingBatchSize(); streamListener = new StreamListener(limit, offset, streamingBatches, streamingBatchSize); StreamListenerServer server = getServer(); server.register(streamListener); HostAndPort hostAndPort = server.getHostAndPort(); String host = hostAndPort.getHostText(); int port = hostAndPort.getPort(); UUID uuid = streamListener.getUuid(); String sql = activation.getPreparedStatement().getSource(); sql = sql == null ? root.toString() : sql; String userId = activation.getLanguageConnectionContext().getCurrentUserId(activation); RemoteQueryJob jobRequest = new RemoteQueryJob(ah, root.getResultSetNumber(), uuid, host, port, userId, sql, streamingBatches, streamingBatchSize); olapFuture = EngineDriver.driver().getOlapClient().submit(jobRequest); olapFuture.addListener(new Runnable() { @Override public void run() { try { OlapResult olapResult = olapFuture.get(); streamListener.completed(olapResult); } catch (ExecutionException e) { LOG.warn("Execution failed", e); streamListener.failed(e.getCause()); } catch (InterruptedException e) { // this shouldn't happen, the olapFuture already completed Thread.currentThread().interrupt(); LOG.error("Unexpected exception, shouldn't happen", e); streamListener.failed(e); } } }, MoreExecutors.sameThreadExecutor()); } catch (IOException e) { throw Exceptions.parseException(e); } }
From source file:io.bazel.rules.closure.webfiles.server.NetworkUtils.java
/** Binds server socket, incrementing port on {@link BindException} if {@code shouldRetry}. */ ServerSocket createServerSocket(HostAndPort bind, boolean tryAlternativePortsOnFailure) throws IOException { InetAddress host = InetAddress.getByName(bind.getHost()); int port = bind.getPort(); BindException bindException = null; for (int n = 0; n < MAX_BIND_ATTEMPTS; n++) { try {//from w ww . j a v a 2 s. com return serverSocketFactory.createServerSocket(port, CONNECTION_BACKLOG, host); } catch (BindException e) { if (port == 0 || !tryAlternativePortsOnFailure) { throw e; } if (bindException == null) { bindException = e; } else if (!e.equals(bindException)) { bindException.addSuppressed(e); } port++; } } throw bindException; }
From source file:org.apache.brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewayImpl.java
@Override protected void connectServiceUpIsRunning() { HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)); String managementUri = String.format("http://%s:%s", hp.getHostText(), hp.getPort()); sensors().set(MANAGEMENT_URL, managementUri); httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(managementUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();//from w ww . ja va 2 s . c om }
From source file:brooklyn.entity.nosql.couchbase.CouchbaseSyncGatewayImpl.java
@Override protected void connectServiceUpIsRunning() { HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this, getAttribute(CouchbaseSyncGateway.ADMIN_REST_API_PORT)); String managementUri = String.format("http://%s:%s", hp.getHostText(), hp.getPort()); setAttribute(MANAGEMENT_URL, managementUri); httpFeed = HttpFeed.builder().entity(this).period(200).baseUri(managementUri) .poll(new HttpPollConfig<Boolean>(SERVICE_UP).onSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant(false))) .build();/*ww w.j a v a2 s. c o m*/ }
From source file:ratpack.server.internal.InferringPublicAddress.java
@Override public URI get() { Request request = Execution.current().maybeGet(Request.class).orElseThrow(() -> new IllegalStateException( "Inferring the public address is only supported during a request execution.")); String scheme = determineScheme(request); String host;/*from www. j av a 2 s. c o m*/ int port; HostAndPort forwardedHostData = getForwardedHostData(request); if (forwardedHostData != null) { host = forwardedHostData.getHost(); port = forwardedHostData.getPortOrDefault(-1); } else { URI absoluteRequestURI = getAbsoluteRequestUri(request); if (absoluteRequestURI != null) { host = absoluteRequestURI.getHost(); port = absoluteRequestURI.getPort(); } else { HostAndPort hostData = getHostData(request); if (hostData != null) { host = hostData.getHost(); port = hostData.getPortOrDefault(-1); } else { HostAndPort localAddress = request.getLocalAddress(); host = localAddress.getHost(); port = ProtocolUtil.isDefaultPortForScheme(localAddress.getPort(), scheme) ? -1 : localAddress.getPort(); } } } try { return new URI(scheme, null, host, port, null, null, null); } catch (URISyntaxException ex) { throw Exceptions.uncheck(ex); } }
From source file:org.apache.hadoop.hbase.rsgroup.RSGroupAdminClient.java
@Override public void moveServers(Set<HostAndPort> servers, String targetGroup) throws IOException { Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet(); for (HostAndPort el : servers) { hostPorts.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostText()).setPort(el.getPort()) .build());//from ww w .j a va2s .c o m } RSGroupAdminProtos.MoveServersRequest request = RSGroupAdminProtos.MoveServersRequest.newBuilder() .setTargetGroup(targetGroup).addAllServers(hostPorts).build(); try { proxy.moveServers(null, request); } catch (ServiceException e) { throw ProtobufUtil.getRemoteException(e); } }