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:com.lambdaworks.redis.cluster.models.slots.ClusterSlotRange.java

private HostAndPort toHostAndPort(RedisClusterNode redisClusterNode) {
    RedisURI uri = redisClusterNode.getUri();
    return HostAndPort.fromParts(uri.getHost(), uri.getPort());
}

From source file:com.bennavetta.aeneas.zookeeper.ZkServer.java

/**
 * Returns the host/port combination used by clients to connect to this particular server. The host is the server
 * address, and the port is the client connection port.
 * @return the client connection information
 *///from  w  w  w  .  j  a v a 2s  .  c o m
public HostAndPort toClientConnection() {
    return HostAndPort.fromParts(address.toString(), clientPort);
}

From source file:com.proofpoint.jmx.JmxAgent8.java

@Inject
public JmxAgent8(JmxConfig config) throws IOException {
    // first, see if the jmx agent is already started (e.g., via command line properties passed to the jvm)
    HostAndPort address = getRunningAgentAddress(config.getRmiRegistryPort(), config.getRmiServerPort());
    if (address != null) {
        log.info("JMX agent already running and listening on %s", address);
    } else if (config.isEnabled()) {
        // otherwise, start it manually
        int registryPort;
        if (config.getRmiRegistryPort() == null) {
            registryPort = NetUtils.findUnusedPort();
        } else {//from ww w . j a  v a2s.com
            registryPort = config.getRmiRegistryPort();
        }

        int serverPort = 0;
        if (config.getRmiServerPort() != null) {
            serverPort = config.getRmiServerPort();
        }

        // This is somewhat of a hack, but the jmx agent in Oracle/OpenJDK doesn't
        // have a programmatic API for starting it and controlling its parameters
        System.setProperty("com.sun.management.jmxremote", "true");
        System.setProperty("com.sun.management.jmxremote.port", Integer.toString(registryPort));
        System.setProperty("com.sun.management.jmxremote.rmi.port", Integer.toString(serverPort));
        System.setProperty("com.sun.management.jmxremote.authenticate", "false");
        System.setProperty("com.sun.management.jmxremote.ssl", "false");

        try {
            Agent.startAgent();
        } catch (Exception e) {
            throwIfUnchecked(e);
            throw new RuntimeException(e);
        }

        try {
            // This is how the jdk jmx agent constructs its url
            JMXServiceURL url = new JMXServiceURL("rmi", null, registryPort);
            address = HostAndPort.fromParts(url.getHost(), url.getPort());
        } catch (MalformedURLException e) {
            // should not happen...
            throw new AssertionError(e);
        }

        log.info("JMX agent started and listening on %s", address);
    }

    if (config.isEnabled()) {
        this.url = new JMXServiceURL(String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi",
                address.getHost(), address.getPort()));
    } else {
        this.url = null;
    }
}

From source file:org.apache.aurora.scheduler.http.LeaderRedirect.java

private Optional<HostAndPort> getLocalHttp() {
    HostAndPort localHttp = httpService.getAddress();
    return (localHttp == null) ? Optional.absent()
            : Optional.of(HostAndPort.fromParts(localHttp.getHost(), localHttp.getPort()));
}

From source file:com.splicemachine.stream.StreamListenerServer.java

public void start() throws StandardException {
    ThreadFactory tf = new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("StreamerListenerServer-boss-%s").build();
    this.bossGroup = new NioEventLoopGroup(4, tf);
    tf = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("StreamerListenerServer-worker-%s").build();
    this.workerGroup = new NioEventLoopGroup(4, tf);
    try {//from  ww  w .  ja  v a  2s .c  om
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new OpenHandler(this))
                .option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);

        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(port).sync();

        this.serverChannel = f.channel();
        InetSocketAddress socketAddress = (InetSocketAddress) this.serverChannel.localAddress();
        String host = InetAddress.getLocalHost().getHostName();
        int port = socketAddress.getPort();

        this.hostAndPort = HostAndPort.fromParts(host, port);
        LOG.info("StreamListenerServer listening on " + hostAndPort);

    } catch (IOException e) {
        throw Exceptions.parseException(e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jclouds.smartos.SmartOSHostController.java

protected SshClient getConnection() {
    if (_connection == null) {
        Credentials currentCreds = checkNotNull(creds.get(), "credential supplier returned null");

        LoginCredentials credentials = new LoginCredentials.Builder().user(currentCreds.identity)
                .password(currentCreds.credential).build();

        _connection = getSshClientFactory().create(HostAndPort.fromParts(hostname, 22), credentials);

        _connection.connect();/*w  w  w  .j a v  a2  s .  com*/

    }
    return _connection;
}

From source file:com.facebook.presto.jdbc.PrestoDriverUri.java

private PrestoDriverUri(URI uri, Properties driverProperties) throws SQLException {
    this.uri = requireNonNull(uri, "uri is null");
    address = HostAndPort.fromParts(uri.getHost(), uri.getPort());
    properties = mergeConnectionProperties(uri, driverProperties);

    validateConnectionProperties(properties);

    useSecureConnection = SSL.getRequiredValue(properties);

    initCatalogAndSchema();//from  ww  w . j a v a  2 s .  c  o  m
}

From source file:com.facebook.presto.jdbc.ext.PrestoConnection.java

PrestoConnection(URI uri, String user, QueryExecutor queryExecutor) throws SQLException {
    this.uri = requireNonNull(uri, "uri is null");
    this.address = HostAndPort.fromParts(uri.getHost(), uri.getPort());
    this.user = requireNonNull(user, "user is null");
    this.queryExecutor = requireNonNull(queryExecutor, "queryExecutor is null");
    timeZoneId.set(TimeZone.getDefault().getID());
    locale.set(Locale.getDefault());

    if (!isNullOrEmpty(uri.getPath())) {
        setCatalogAndSchema();/*from   ww w . j a v a2s .  c  om*/
    }
}

From source file:org.sonar.server.es.EsClientProvider.java

public EsClient provide(Configuration config) {
    if (cache == null) {
        Settings.Builder esSettings = Settings.builder();

        // mandatory property defined by bootstrap process
        esSettings.put("cluster.name", config.get(CLUSTER_NAME).get());

        boolean clusterEnabled = config.getBoolean(CLUSTER_ENABLED).orElse(false);
        boolean searchNode = !clusterEnabled
                || SEARCH.equals(NodeType.parse(config.get(CLUSTER_NODE_TYPE).orElse(null)));
        final TransportClient nativeClient = new MinimalTransportClient(esSettings.build());
        if (clusterEnabled && !searchNode) {
            esSettings.put("client.transport.sniff", true);
            Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS)).map(HostAndPort::fromString)
                    .forEach(h -> addHostToClient(h, nativeClient));
            LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
        } else {//w ww .j av  a  2s  .  c  o m
            HostAndPort host = HostAndPort.fromParts(config.get(ProcessProperties.SEARCH_HOST).get(),
                    config.getInt(ProcessProperties.SEARCH_PORT).get());
            addHostToClient(host, nativeClient);
            LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
        }

        cache = new EsClient(nativeClient);
    }
    return cache;
}

From source file:io.druid.server.DruidNode.java

private void init(String serviceName, String host, Integer port) {
    Preconditions.checkNotNull(serviceName);
    this.serviceName = serviceName;

    if (host == null && port == null) {
        host = getDefaultHost();//from  w  ww  . jav a2s.  c o  m
        port = -1;
    } else {
        final HostAndPort hostAndPort;
        if (host != null) {
            hostAndPort = HostAndPort.fromString(host);
            if (port != null && hostAndPort.hasPort() && port != hostAndPort.getPort()) {
                throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, port);
            }
        } else {
            hostAndPort = HostAndPort.fromParts(getDefaultHost(), port);
        }

        host = hostAndPort.getHostText();

        if (hostAndPort.hasPort()) {
            port = hostAndPort.getPort();
        }

        if (port == null) {
            port = SocketUtil.findOpenPort(8080);
        }
    }

    this.port = port;
    this.host = host;
}