Guava HostAndPort - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava HostAndPort class.

This code example shows how to use the following methods:getHostText, getPort
    public boolean bootstrap(HostAndPort seed, 
                             Node localNode) throws SyncException { 
        this.localNode = localNode;
        succeeded = false;
        SocketAddress sa =
                new InetSocketAddress(seed.getHostText(), seed.getPort());
        ChannelFuture future = bootstrap.connect(sa);
        future.awaitUninterruptibly();
        if (!future.isSuccess()) {
            logger.debug("Could not connect to " + seed, future.getCause());
            return false; 
        } 
        Channel channel = future.getChannel();
        logger.debug("[{}] Connected to {}",  
                     localNode != null ? localNode.getNodeId() : null, 
                     seed);
         
        try { 
            channel.getCloseFuture().await();
        } catch (InterruptedException e) {
7
CodeRank
This code example shows how to use the following methods:getHostText, getPort
      this.proxyForURI = checkNotNull(proxyForURI, "proxyForURI");
   } 
    
   @Override 
   public boolean apply(HostAndPort socketA) {
      InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA
               .getPort());
      Socket socket = null;
      try { 
         logger.trace("testing socket %s", socketAddress);
         socket = new Socket(
               proxyForURI.apply(URI.create("socket://" + socketA.getHostText() + ":" + socketA.getPort())));
         socket.setReuseAddress(false);
         socket.setSoLinger(false, 1);
         socket.setSoTimeout(timeout);
         socket.connect(socketAddress, timeout);
      } catch (IOException e) {
         return false; 
      } finally { 
         if (socket != null) {
6
CodeRank
This code example shows how to use the following methods:getHostText, getPort
        return protocolFactory;
    } 
 
    protected static SocketAddress toSocketAddress(HostAndPort address)
    { 
        return new InetSocketAddress(address.getHostText(), address.getPort());
    } 
 
    protected static TDuplexProtocolFactory defaultProtocolFactory() 
    { 
        return TDuplexProtocolFactory.fromSingleFactory(new TBinaryProtocol.Factory()); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getHostText, getPort, hasPort, toString
 
    public HttpUriBuilder hostAndPort(HostAndPort hostAndPort)
    { 
        Preconditions.checkNotNull(hostAndPort, "hostAndPort is null");
        this.host = bracketedHostString(hostAndPort);
        this.port = hostAndPort.hasPort() ? hostAndPort.getPort() : -1;
        return this;
    } 
 
    /** 
     * Replace the current path with the given unencoded path 
     */ 
    public HttpUriBuilder replacePath(String path)
    { 
        Preconditions.checkNotNull(path, "path is null");
 
        if (!path.equals("") && !path.startsWith("/")) {
            path = "/" + path;
        } 
 

6
CodeRank
This code example shows how to use the following methods:getHostText, getPort
      throw new RuntimeException(e);
    } 
  } 
   
  public static TTransport create(HostAndPort addr, long timeoutMillis) throws IOException {
    return create(new InetSocketAddress(addr.getHostText(), addr.getPort()), timeoutMillis);
  } 
 
  public static TTransport create(SocketAddress addr, long timeoutMillis) throws IOException {
    Socket socket = SelectorProvider.provider().openSocketChannel().socket();
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);
    socket.connect(addr);
    InputStream input = new BufferedInputStream(getInputStream(socket, timeoutMillis), 1024 * 10);
    OutputStream output = new BufferedOutputStream(NetUtils.getOutputStream(socket, timeoutMillis), 1024 * 10);
    return new TIOStreamTransport(input, output);
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getHostText, getPort, hasPort, toString
 
    public HttpUriBuilder hostAndPort(HostAndPort hostAndPort)
    { 
        Preconditions.checkNotNull(hostAndPort, "hostAndPort is null");
        this.host = bracketedHostString(hostAndPort);
        this.port = hostAndPort.hasPort() ? hostAndPort.getPort() : -1;
        return this;
    } 
 
    /** 
     * Replace the current path with the given unencoded path 
     */ 
    public HttpUriBuilder replacePath(String path)
    { 
        Preconditions.checkNotNull(path, "path is null");
 
        if (!path.equals("") && !path.startsWith("/")) {
            path = "/" + path;
        } 
 

6
CodeRank
This code example shows how to use the following methods:getHostText, getPort
    return invoke(handler, launchConfig, registry);
  } 
 
  private HandlingResult invoke(Handler handler, LaunchConfig launchConfig, Registry registry) throws HandlerTimeoutException {
    Request request = new DefaultRequest(requestHeaders, HttpMethod.valueOf(method.toUpperCase()), uri,
      new InetSocketAddress(remoteHostAndPort.getHostText(), remoteHostAndPort.getPort()),
      new InetSocketAddress(localHostAndPort.getHostText(), localHostAndPort.getPort()),
      requestBody);
 
    try { 
      return new DefaultHandlingResult( 
        request, 
        responseHeaders,
        registry,
        timeout,
        launchConfig,
        handler 
      ); 
    } finally { 
      launchConfig.getExecController().close();
6
CodeRank
This code example shows how to use the following methods:getHostText, getPort, hasPort
        return hostAndPort;
    } 
     
    @Override 
    public String toString() {
        return user + "@" + hostAndPort.getHostText() + (hostAndPort.hasPort() ? ":" + hostAndPort.getPort() : "");
    } 
     
    @Override 
    public boolean equals(Object obj) { 
        if (!(obj instanceof UserAndHostAndPort)) return false; 
        UserAndHostAndPort o = (UserAndHostAndPort) obj;
        return Objects.equal(user, o.user) && Objects.equal(hostAndPort, o.hostAndPort);
    } 
     
    @Override 
    public int hashCode() { 
        return Objects.hashCode(user, hostAndPort);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getHostText, getPort
        } 
    } 
 
    private static Socket createSocksSocket(HostAndPort proxy)
    { 
        SocketAddress address = InetSocketAddress.createUnresolved(proxy.getHostText(), proxy.getPort());
        return new Socket(new Proxy(Proxy.Type.SOCKS, address));
    } 
 
    private static TTransportException rewriteException(TTransportException e, String host)
    { 
        return new TTransportException(e.getType(), String.format("%s: %s", host, e.getMessage()), e.getCause());
    } 
 
    private static class TTransportWrapper 
            extends TTransport 
    { 
        private final TTransport transport;
        private final String host;
 
5
CodeRank
This code example shows how to use the following methods:getHostText
    return determineHost(address);
  } 
 
  public static String determineHost(HostAndPort hostAndPort) {
    try { 
      InetAddress address = InetAddress.getByName(hostAndPort.getHostText());
      return determineHost(address);
    } catch (UnknownHostException e) {
      return hostAndPort.getHostText();
    } 
  } 
 
  private static String determineHost(InetAddress address) {
    if (address.isLoopbackAddress() || address.isAnyLocalAddress()) {
      return "localhost"; 
    } else { 
      return address.getHostAddress();
    } 
  } 
} 
5
CodeRank
See Code Examples for Guava HostAndPort Methods: