Example usage for com.google.common.net HostAndPort toString

List of usage examples for com.google.common.net HostAndPort toString

Introduction

In this page you can find the example usage for com.google.common.net HostAndPort toString.

Prototype

@Override
public String toString() 

Source Link

Document

Rebuild the host:port string, including brackets if necessary.

Usage

From source file:io.mandrel.transport.thrift.MandrelCoercions.java

@ToThrift
public static String toThrift(HostAndPort value) {
    return value.toString();
}

From source file:org.apache.slider.core.zk.ZookeeperUtils.java

public static String buildQuorumEntry(HostAndPort hostAndPort, int defaultPort) {
    String s = hostAndPort.toString();
    if (hostAndPort.hasPort()) {
        return s;
    } else {//from w  w  w . j a v a  2s.  c o m
        return s + ":" + defaultPort;
    }
}

From source file:com.streamsets.pipeline.kafka.impl.KafkaValidationUtil08.java

private static String getKafkaBrokers(List<HostAndPort> kafkaBrokers) {
    StringBuilder sb = new StringBuilder();
    for (HostAndPort k : kafkaBrokers) {
        sb.append(k.toString()).append(", ");
    }/*from   w  ww.j a  v a2  s.c o m*/
    sb.setLength(sb.length() - 2);
    return sb.toString();
}

From source file:io.tsdb.opentsdb.discovery.ConsulPlugin.java

private static void register() {
    AgentClient agentClient = consul.agentClient();

    List<Registration.RegCheck> checks = new ArrayList<Registration.RegCheck>();

    HostAndPort serviceHostAndPort = HostAndPort.fromParts(visibleHost, visiblePort);

    Registration.RegCheck mainCheck = Registration.RegCheck.tcp(serviceHostAndPort.toString(), 30);

    checks.add(mainCheck);//  w ww .  j  a  va 2 s .c om

    Registration registration = ImmutableRegistration.builder().port(visiblePort).address(visibleHost)
            .checks(checks).name(serviceName).id(serviceId).addTags(tsdMode).build();

    agentClient.register(registration);

    if (agentClient.isRegistered(serviceId)) {
        LOGGER.info("Registered this instance with Consul");
    } else {
        LOGGER.warn("Consul reports that this instance is not registered");
    }
}

From source file:io.v.impl.google.naming.EndpointImpl.java

public static Endpoint fromString(String s) {
    Matcher matcher = hostPortPattern.matcher(s);
    if (matcher.matches()) {
        List<String> blessings = new ArrayList<>(1);
        // If the endpoint does not end in a @, it must be in [blessing@]host:port format.
        HostAndPort hostPort = HostAndPort.fromString(matcher.group(matcher.groupCount()));
        if (matcher.group(1) != null) {
            blessings.add(matcher.group(1));
        }//from  w  ww . ja  v a2s .c o  m

        return new EndpointImpl("", hostPort.toString(), ImmutableList.<String>of(), RoutingId.NULL_ROUTING_ID,
                blessings, true, false);
    }

    if (s.endsWith("@@")) {
        s = s.substring(0, s.length() - 2);
    }
    if (s.startsWith("@")) {
        s = s.substring(1, s.length());
    }

    List<String> parts = Splitter.on('@').splitToList(s);
    int version = Integer.parseInt(parts.get(0));
    switch (version) {
    case 6:
        return fromV6String(parts);
    default:
        return null;
    }
}

From source file:org.apache.kudu.client.ConnectToCluster.java

/**
 * Locate the leader master and retrieve the cluster information
 * (see {@link ConnectToClusterResponse}.
 *
 * @param masterTable the "placeholder" table used by AsyncKuduClient
 * @param masterAddresses the addresses of masters to fetch from
 * @param parentRpc RPC that prompted a master lookup, can be null
 * @param connCache the client's connection cache, used for creating connections
 *                  to masters/*from w w  w. j  a  v  a 2s.com*/
 * @param defaultTimeoutMs timeout to use for RPCs if the parentRpc has no timeout
 * @return a Deferred object for the cluster connection status
 */
public static Deferred<ConnectToClusterResponse> run(KuduTable masterTable, List<HostAndPort> masterAddresses,
        KuduRpc<?> parentRpc, ConnectionCache connCache, long defaultTimeoutMs) {
    ConnectToCluster connector = new ConnectToCluster(masterAddresses);

    // Try to connect to each master. The ConnectToCluster instance
    // waits until it gets a good response before firing the returned
    // deferred.
    for (HostAndPort hostAndPort : masterAddresses) {
        Deferred<ConnectToMasterResponsePB> d;
        TabletClient client = connCache.newMasterClient(hostAndPort);
        if (client == null) {
            String message = "Couldn't resolve this master's address " + hostAndPort.toString();
            LOG.warn(message);
            Status statusIOE = Status.IOError(message);
            d = Deferred.fromError(new NonRecoverableException(statusIOE));
        } else {
            d = connectToMaster(masterTable, client, parentRpc, defaultTimeoutMs);
        }
        d.addCallbacks(connector.callbackForNode(hostAndPort), connector.errbackForNode(hostAndPort));
    }
    return connector.responseD;
}

From source file:org.apache.accumulo.server.util.Admin.java

private static void stopTabletServer(final ClientContext context, List<String> servers, final boolean force)
        throws AccumuloException, AccumuloSecurityException {
    if (context.getInstance().getMasterLocations().size() == 0) {
        log.info("No masters running. Not attempting safe unload of tserver.");
        return;/*w  w  w  . j a  v a 2 s . c  o m*/
    }
    final Instance instance = context.getInstance();
    final String zTServerRoot = getTServersZkPath(instance);
    final ZooCache zc = new ZooCacheFactory().getZooCache(instance.getZooKeepers(),
            instance.getZooKeepersSessionTimeOut());
    for (String server : servers) {
        HostAndPort address = AddressUtil.parseAddress(server,
                context.getConfiguration().getPort(Property.TSERV_CLIENTPORT));
        final String finalServer = qualifyWithZooKeeperSessionId(zTServerRoot, zc, address.toString());
        log.info("Stopping server " + finalServer);
        MasterClient.execute(context, new ClientExec<MasterClientService.Client>() {
            @Override
            public void execute(MasterClientService.Client client) throws Exception {
                client.shutdownTabletServer(Tracer.traceInfo(), context.rpcCreds(), finalServer, force);
            }
        });
    }
}

From source file:io.mandrel.common.bson.HostAndPortCodec.java

@Override
public void encode(final BsonWriter writer, final HostAndPort value, final EncoderContext encoderContext) {
    writer.writeString(value.toString());
}

From source file:org.graylog.plugins.metrics.prometheus.providers.PushGatewayProvider.java

@Override
public PushGateway get() {
    final HostAndPort address = configuration.getAddress().withDefaultPort(9091);

    return new PushGateway(address.toString());
}

From source file:io.druid.server.listener.announcer.ListenerResourceAnnouncer.java

ListenerResourceAnnouncer(Announcer announcer, String announceBasePath, HostAndPort node) {
    this.announcePath = ZKPaths.makePath(announceBasePath, node.toString());
    this.announcer = announcer;
}