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

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

Introduction

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

Prototype

public static HostAndPort fromParts(String host, int port) 

Source Link

Document

Build a HostAndPort instance from separate host and port values.

Usage

From source file:ezbake.thriftrunner.starters.SimpleStarter.java

@Override
public HostAndPort getPublicHostInfo() {
    return HostAndPort.fromParts(hostName, portNumber);
}

From source file:org.grycap.gpf4med.cloud.util.CloudUtils.java

/**
 * Gets the first public address where a node listen for incoming requests in the
 * specified network port./*w  w  w .  ja  v  a 2 s .  com*/
 * @param port the network port where the node listens for connections.
 * @return the first public address found for the specified port.
 */
public static Function<NodeMetadata, HostAndPort> firstPublicAddressToHostAndPort(final int port) {
    return new Function<NodeMetadata, HostAndPort>() {
        @Override
        public HostAndPort apply(final NodeMetadata input) {
            return HostAndPort.fromParts(get(input.getPublicAddresses(), 0), port);
        }

        @Override
        public String toString() {
            return "firstPublicAddressToHostAndPort(" + port + ")";
        }
    };
}

From source file:com.torodb.mongodb.repl.oplogreplier.fetcher.StaticOplogReader.java

public StaticOplogReader(Collection<OplogOperation> oplog) {
    this(HostAndPort.fromParts("localhost", 27017), oplog);
}

From source file:org.apache.phoenix.queryserver.register.ZookeeperRegistry.java

@Override
public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString,
        String pqsHost) throws Exception {

    this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString,
            new ExponentialBackoffRetry(1000, 10));
    this.client.start();
    HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort);
    String path = configuration.getFullPathToNode(hostAndPort);
    String node = hostAndPort.toString();
    this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path,
            node.getBytes(StandardCharsets.UTF_8));
    Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path);
    if (stat != null) {
        LOG.info(" node created with right ACL");
    } else {/*from  w ww. ja  v a  2  s .  c o m*/
        LOG.error("could not create node with right ACL. So, system would exit now.");
        throw new RuntimeException(" Unable to connect to Zookeeper");
    }

}

From source file:ezbake.thriftrunner.starters.OpenShiftStarter.java

@Override
public HostAndPort getPublicHostInfo() {
    return HostAndPort.fromParts(publicHostName, publicPort);
}

From source file:com.facebook.hive.metastore.client.HiveMetastoreClientConfig.java

public HostAndPort getHostAndPort() {
    return HostAndPort.fromParts(host, port);
}

From source file:alluxio.wire.FileBlockInfo.java

/**
 * Creates a new instance of {@link FileBlockInfo} from a thrift representation.
 *
 * @param fileBlockInfo the thrift representation of a file block information
 *///  w ww  .ja  va  2s  . c o  m
protected FileBlockInfo(alluxio.thrift.FileBlockInfo fileBlockInfo) {
    mBlockInfo = new BlockInfo(fileBlockInfo.getBlockInfo());
    mOffset = fileBlockInfo.getOffset();
    if (fileBlockInfo.getUfsStringLocationsSize() != 0) {
        mUfsLocations = new ArrayList<>(fileBlockInfo.getUfsStringLocations());
    } else if (fileBlockInfo.getUfsLocationsSize() != 0) {
        for (alluxio.thrift.WorkerNetAddress address : fileBlockInfo.getUfsLocations()) {
            mUfsLocations.add(HostAndPort.fromParts(address.getHost(), address.getDataPort()).toString());
        }
    }
}

From source file:ezbake.thriftrunner.starters.SimpleStarter.java

@Override
public HostAndPort getPrivateHostInfo() {
    return HostAndPort.fromParts(hostName, portNumber);
}

From source file:com.facebook.swift.service.async.AsyncTestBase.java

protected <T> ListenableFuture<T> createClient(Class<T> clientClass, int serverPort)
        throws TTransportException, InterruptedException, ExecutionException {
    HostAndPort address = HostAndPort.fromParts("localhost", serverPort);
    ThriftClientConfig config = new ThriftClientConfig().setConnectTimeout(new Duration(1, TimeUnit.SECONDS))
            .setReadTimeout(new Duration(1, TimeUnit.SECONDS))
            .setWriteTimeout(new Duration(1, TimeUnit.SECONDS));
    FramedClientConnector connector = new FramedClientConnector(address);
    return new ThriftClient<>(clientManager, clientClass, config, "asyncTestClient").open(connector);
}

From source file:org.hillview.targets.InitialObjectTarget.java

public InitialObjectTarget() {
    // Get the base naming context
    final String clusterFile = System.getenv(ENV_VARIABLE);
    final ClusterDescription desc;
    if (clusterFile == null) {
        HillviewLogger.instance.info("No cluster description file specified; creating singleton");
        desc = new ClusterDescription(
                Collections.singletonList(HostAndPort.fromParts(LOCALHOST, HillviewServer.DEFAULT_PORT)));
        this.initialize(desc);
    } else {/*from w w  w  .j a va  2  s  .  c o  m*/
        try {
            HillviewLogger.instance.info("Initializing cluster descriptor from file", "{0}", clusterFile);
            final List<String> lines = Files.readAllLines(Paths.get(clusterFile), Charset.defaultCharset());
            final List<HostAndPort> hostAndPorts = lines.stream().map(HostAndPort::fromString)
                    .collect(Collectors.toList());
            desc = new ClusterDescription(hostAndPorts);
            HillviewLogger.instance.info("Backend servers", "{0}", lines);
            this.initialize(desc);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    RpcObjectManager.instance.addObject(this);
}