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

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

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Get the current port number, failing if no port is defined.

Usage

From source file:com.facebook.presto.hive.HiveMetastoreClientFactory.java

private static Socket createSocksSocket(HostAndPort proxy) {
    SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHostText(), proxy.getPort());
    return new Socket(new Proxy(Proxy.Type.SOCKS, address));
}

From source file:org.apache.brooklyn.entity.nosql.mongodb.MongoDBTestHelper.java

private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {//w w  w  .java  2 s  .  co  m
        HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(server,
                server.getAttribute(MongoDBServer.PORT));
        return new MongoClient(hap.getHostText(), hap.getPort());
    } catch (Exception e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}

From source file:brooklyn.entity.nosql.mongodb.MongoDBTestHelper.java

private static MongoClient clientForServer(AbstractMongoDBServer server) {
    try {//from w ww.  j a v a 2  s . c  o  m
        HostAndPort hap = BrooklynAccessUtils.getBrooklynAccessibleAddress(server,
                server.getAttribute(MongoDBServer.PORT));
        return new MongoClient(hap.getHostText(), hap.getPort());
    } catch (UnknownHostException e) {
        // Fail whatever test called this method.
        throw Throwables.propagate(e);
    }
}

From source file:com.netflix.metacat.connector.hive.client.thrift.HiveMetastoreClientFactory.java

private static Socket createSocksSocket(final HostAndPort proxy) {
    final SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHostText(), proxy.getPort());
    return new Socket(new Proxy(Proxy.Type.SOCKS, address));
}

From source file:org.kududb.client.ProtobufHelper.java

/**
 * Convert a {@link com.google.common.net.HostAndPort} to {@link org.kududb.Common.HostPortPB}
 * protobuf message for serialization./* www .j a  va 2s.c o m*/
 * @param hostAndPort The host and port object. Both host and port must be specified.
 * @return An initialized HostPortPB object.
 */
public static Common.HostPortPB hostAndPortToPB(HostAndPort hostAndPort) {
    return Common.HostPortPB.newBuilder().setHost(hostAndPort.getHostText()).setPort(hostAndPort.getPort())
            .build();
}

From source file:com.pingcap.tikv.RegionStoreClient.java

public static RegionStoreClient create(Region region, Store store, TiSession session) {
    RegionStoreClient client = null;//from   w w  w  .j  ava 2  s  . co  m
    try {
        HostAndPort address = HostAndPort.fromString(store.getAddress());
        ManagedChannel channel = ManagedChannelBuilder.forAddress(address.getHostText(), address.getPort())
                .usePlaintext(true).build();
        TiKVBlockingStub blockingStub = TiKVGrpc.newBlockingStub(channel);
        TiKVStub asyncStub = TiKVGrpc.newStub(channel);
        client = new RegionStoreClient(region, session, channel, blockingStub, asyncStub);
    } catch (Exception e) {
        if (client != null) {
            try {
                client.close();
            } catch (Exception ignore) {
            }
        }
    }
    return client;
}

From source file:org.apache.beam.runners.dataflow.worker.fn.SocketAddressFactory.java

/** Parse a {@link SocketAddress} from the given string. */
public static SocketAddress createFrom(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        // Unix Domain Socket address.
        // Create the underlying file for the Unix Domain Socket.
        String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
        File file = new File(filePath);
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException("File path must be absolute: " + filePath);
        }//w w  w.ja  v  a  2s .c o m
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        // Create the SocketAddress referencing the file.
        return new DomainSocketAddress(file);
    } else {
        // Standard TCP/IP address.
        HostAndPort hostAndPort = HostAndPort.fromString(value);
        checkArgument(hostAndPort.hasPort(),
                "Address must be a unix:// path or be in the form host:port. Got: %s", value);
        return new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort());
    }
}

From source file:org.apache.beam.harness.channel.SocketAddressFactory.java

/**
 * Parse a {@link SocketAddress} from the given string.
 *//*from  w w  w .  java 2s  .co m*/
public static SocketAddress createFrom(String value) {
    if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
        // Unix Domain Socket address.
        // Create the underlying file for the Unix Domain Socket.
        String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
        File file = new File(filePath);
        if (!file.isAbsolute()) {
            throw new IllegalArgumentException("File path must be absolute: " + filePath);
        }
        try {
            if (file.createNewFile()) {
                // If this application created the file, delete it when the application exits.
                file.deleteOnExit();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        // Create the SocketAddress referencing the file.
        return new DomainSocketAddress(file);
    } else {
        // Standard TCP/IP address.
        HostAndPort hostAndPort = HostAndPort.fromString(value);
        checkArgument(hostAndPort.hasPort(),
                "Address must be a unix:// path or be in the form host:port. Got: %s", value);
        return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
    }
}

From source file:org.opendaylight.protocol.util.InetSocketAddressUtil.java

public static InetSocketAddress getInetSocketAddress(final String hostPortString, final Integer defaultPort) {
    final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString);
    if (defaultPort != null) {
        return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(defaultPort));
    }//from w w w.j av  a2 s  .c  o m
    return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}

From source file:io.mandrel.transport.thrift.nifty.NiftyClient.java

private static InetSocketAddress toInetAddress(HostAndPort hostAndPort) {
    return (hostAndPort == null) ? null
            : new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}