當前位置: 首頁>>代碼示例>>Java>>正文


Java HostAndPort.fromString方法代碼示例

本文整理匯總了Java中com.google.common.net.HostAndPort.fromString方法的典型用法代碼示例。如果您正苦於以下問題:Java HostAndPort.fromString方法的具體用法?Java HostAndPort.fromString怎麽用?Java HostAndPort.fromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.net.HostAndPort的用法示例。


在下文中一共展示了HostAndPort.fromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: launch

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Override
public final SafariBrowser launch(DesiredCapabilities caps) throws BrowserException {
  String udid = (String) caps.getCapability("uuid");
  SafariBrowser browser = udid == null ? launch() : launch(udid);
  @SuppressWarnings("unchecked")
  Map<String, String> proxyDict = (Map<String, String>) caps.getCapability("proxy");
  if (proxyDict != null) {
    HostAndPort proxy = HostAndPort.fromString(proxyDict.get("httpProxy"));
    browser.setHttpProxy(proxy);
  }
  @SuppressWarnings("unchecked")
  Map<String, String> cert = (Map<String, String>) caps.getCapability("httpsCert");
  if (cert != null) {
    browser.installHttpsCert(cert.get("certName"), cert.get("certContentBase64"));
  }
  return browser;
}
 
開發者ID:google,項目名稱:devtools-driver,代碼行數:18,代碼來源:SafariBrowserLauncher.java

示例2: getGelfConfiguration

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
private GelfConfiguration getGelfConfiguration(Configuration config) {
    final Integer queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
    final Long reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
    final Long connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
    final Boolean isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
    final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
    final String protocol = config.getString("graylog2.appender.protocol", "udp");

    final HostAndPort hostAndPort = HostAndPort.fromString(hostString);

    GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());

    final Integer sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used

    return new GelfConfiguration(hostAndPort.getHost(), hostAndPort.getPort())
            .transport(gelfTransport)
            .reconnectDelay(reconnectInterval.intValue())
            .queueSize(queueCapacity)
            .connectTimeout(connectTimeout.intValue())
            .tcpNoDelay(isTcpNoDelay)
            .sendBufferSize(sendBufferSize);
}
 
開發者ID:tochkak,項目名稱:play-graylog2,代碼行數:23,代碼來源:Graylog2Component.java

示例3: getChannel

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public synchronized ManagedChannel getChannel(String addressStr) {
  ManagedChannel channel = connPool.get(addressStr);
  if (channel == null) {
    HostAndPort address;
    try {
      address = HostAndPort.fromString(addressStr);
    } catch (Exception e) {
      throw new IllegalArgumentException("failed to form address");
    }

    // Channel should be lazy without actual connection until first call
    // So a coarse grain lock is ok here
    channel = ManagedChannelBuilder.forAddress(address.getHostText(), address.getPort())
        .maxInboundMessageSize(conf.getMaxFrameSize())
        .usePlaintext(true)
        .idleTimeout(60, TimeUnit.SECONDS)
        .build();
    connPool.put(addressStr, channel);
  }
  return channel;
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:22,代碼來源:TiSession.java

示例4: startOstrichService

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public static void startOstrichService(String tsdbHostPort, int ostrichPort) {
  final int TSDB_METRICS_PUSH_INTERVAL_IN_MILLISECONDS = 10 * 1000;
  OstrichAdminService ostrichService = new OstrichAdminService(ostrichPort);
  ostrichService.startAdminHttpService();
  if (tsdbHostPort != null) {
    LOG.info("Starting the OpenTsdb metrics pusher");
    try {
      HostAndPort pushHostPort = HostAndPort.fromString(tsdbHostPort);
      MetricsPusher metricsPusher = new MetricsPusher(
          pushHostPort.getHostText(),
          pushHostPort.getPort(),
          new OpenTsdbMetricConverter("KafkaOperator", HostName),
          TSDB_METRICS_PUSH_INTERVAL_IN_MILLISECONDS);
      metricsPusher.start();
      LOG.info("OpenTsdb metrics pusher started!");
    } catch (Throwable t) {
      // pusher fail is OK, do
      LOG.error("Exception when starting stats pusher: ", t);
    }
  }
}
 
開發者ID:pinterest,項目名稱:doctorkafka,代碼行數:22,代碼來源:OperatorUtil.java

示例5: validate

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
void validate(final String setting, final String input) {
  HostAndPort hostAndPort = HostAndPort.fromString(input);
  if (this.requireBracketsForIPv6) {
    hostAndPort = hostAndPort.requireBracketsForIPv6();
  }
  if (null != this.defaultPort) {
    hostAndPort.withDefaultPort(this.defaultPort);
  }

  if (Strings.isNullOrEmpty(hostAndPort.getHostText())) {
    throw new ConfigException(String.format("'%s'(%s) host cannot be blank or null.", setting, input));
  }

  if (this.portRequired && !hostAndPort.hasPort()) {
    throw new ConfigException(String.format("'%s'(%s) must specify a port.", setting, input));
  }

}
 
開發者ID:jcustenborder,項目名稱:connect-utils,代碼行數:19,代碼來源:ValidHostAndPort.java

示例6: main

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public static void main(String[] args) {
    if (args.length != 1) {
        usage();
        throw new RuntimeException("Incorrect arguments");
    }

    HillviewLogger.initialize("worker", "hillview.log");
    try {
        final IDataSet<Empty> dataSet = new LocalDataSet<Empty>(Empty.getInstance());
        final String hostnameAndPort = args[0];
        final HillviewServer server = new HillviewServer(HostAndPort.fromString(hostnameAndPort), dataSet);
        HillviewLogger.instance.info("Created HillviewServer");
        Thread.currentThread().join();
    } catch (Exception ex) {
        HillviewLogger.instance.error("Caught exception", ex);
    }
}
 
開發者ID:vmware,項目名稱:hillview,代碼行數:18,代碼來源:HillviewServerRunner.java

示例7: nodeChanged

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Override
public void nodeChanged() throws Exception {

    String tsoInfo = getCurrentTSOInfoFoundInZK(zkCurrentTsoPath);
    // TSO info includes the new TSO host:port address and epoch
    String[] currentTSOAndEpochArray = tsoInfo.split("#");
    HostAndPort hp = HostAndPort.fromString(currentTSOAndEpochArray[0]);
    setTSOAddress(hp.getHostText(), hp.getPort());
    epoch = Long.parseLong(currentTSOAndEpochArray[1]);
    LOG.info("CurrentTSO ZNode changed. New TSO Host & Port {}/Epoch {}", hp, getEpoch());
    if (currentChannel != null && currentChannel.isConnected()) {
        LOG.info("\tClosing channel with previous TSO {}", currentChannel);
        currentChannel.close();
    }

}
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:17,代碼來源:TSOClient.java

示例8: getRandomReplicaAddress

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
public HostAndPort getRandomReplicaAddress(byte partition) throws ReplicaManagerException {
       try {
           String path = BASEPATH + "/" + Byte.toString(partition);
           List<String> replicas = this.zk.getChildren(path, false);
           if (replicas.size() < 1) {
               return null;
           } else {
               String rep = replicas.get(this.random.nextInt(replicas.size()));
               path += "/" + rep;
               byte[] data = zk.getData(path, false, null);
               return HostAndPort.fromString(new String(data));
           }
       } catch (KeeperException | InterruptedException e) {
           throw new ReplicaManagerException(e);
       }
}
 
開發者ID:pacheco,項目名稱:GlobalFS,代碼行數:17,代碼來源:ZookeeperReplicaManager.java

示例9: setup

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@BeforeClass
public static void setup() throws Exception {
  // start the zk server
  startZKServer();

  HostAndPort hostAndPort1 = HostAndPort.fromString("localhost:" + PORT);
  ArrayList<HostAndPort> list = new ArrayList<HostAndPort>();
  list.add(hostAndPort1);
  identifier = new ServerIdentifier(rootZnode, list);
  serviceRegistry =
      ServiceRegistryProvider.provider().getRegistryFactory().getServiceRegistry(identifier);
  serviceRegistry.start();

  client =
      CuratorFrameworkFactory.newClient(identifier.getConnectionString(), new RetryNTimes(10,
          5000));
  client.start();

  entry = new RegisterEntry();
  HostMetadata metadata = new HostMetadata("localhost", 4442, zone, true);
  entry.setServiceName(targetService.getAuthority());
  entry.setDescription(targetService.getAuthority());
  entry.setLastUpdated(Calendar.getInstance().getTime());
  entry.setHostMetadata(metadata);

}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:27,代碼來源:ServiceRegistryTest.java

示例10: parseHostHeader

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/**
 * Retrieves the host and, optionally, the port from the specified request's Host header.
 *
 * @param httpRequest HTTP request
 * @param includePort when true, include the port
 * @return the host and, optionally, the port specified in the request's Host header
 */
private static String parseHostHeader(HttpRequest httpRequest, boolean includePort) {
    // this header parsing logic is adapted from ClientToProxyConnection#identifyHostAndPort.
    List<String> hosts = httpRequest.headers().getAll(HttpHeaders.Names.HOST);
    if (!hosts.isEmpty()) {
        String hostAndPort = hosts.get(0);

        if (includePort) {
            return hostAndPort;
        } else {
            HostAndPort parsedHostAndPort = HostAndPort.fromString(hostAndPort);
            return parsedHostAndPort.getHostText();
        }
    } else {
        return null;
    }
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:24,代碼來源:HttpUtil.java

示例11: fromString

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
@Nonnull
public static Replica fromString(@Nonnull String info) {
    try {
        checkNotNull(info);
        HostAndPort hostAndPort = HostAndPort.fromString(info);
        InetAddress addr = InetAddress.getByName(hostAndPort.getHostText());
        InetSocketAddress saddr = new InetSocketAddress(addr, hostAndPort.getPort());
        return new Replica(saddr);
    } catch (UnknownHostException e) {
        throw Throwables.propagate(e);
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:13,代碼來源:Replica.java

示例12: parseHosts

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
static String parseHosts(String contactPoints) {
  List<String> result = new LinkedList<>();
  for (String contactPoint : contactPoints.split(",")) {
    HostAndPort parsed = HostAndPort.fromString(contactPoint);
    result.add(parsed.getHostText());
  }
  return Joiner.on(',').join(result);
}
 
開發者ID:jaegertracing,項目名稱:spark-dependencies,代碼行數:9,代碼來源:CassandraDependenciesJob.java

示例13: parsePort

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
/** Returns the consistent port across all contact points or 9042 */
static String parsePort(String contactPoints) {
  Set<Integer> ports = new HashSet<>();
  for (String contactPoint: contactPoints.split(",")) {
    HostAndPort parsed = HostAndPort.fromString(contactPoint);
    ports.add(parsed.getPortOrDefault(9042));
  }
  return ports.size() == 1 ? String.valueOf(ports.iterator().next()) : "9042";
}
 
開發者ID:jaegertracing,項目名稱:spark-dependencies,代碼行數:10,代碼來源:CassandraDependenciesJob.java

示例14: hostAndPort

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
static HostAndPort hostAndPort(String input, Integer defaultPort) {
  final HostAndPort result = HostAndPort.fromString(input);

  if (null != defaultPort) {
    result.withDefaultPort(defaultPort);
  }

  return result;
}
 
開發者ID:jcustenborder,項目名稱:connect-utils,代碼行數:10,代碼來源:ConfigUtils.java

示例15: parseContactPoints

import com.google.common.net.HostAndPort; //導入方法依賴的package包/類
static List<InetSocketAddress> parseContactPoints(Cassandra3Storage cassandra) {
  List<InetSocketAddress> result = new LinkedList<>();
  for (String contactPoint : cassandra.contactPoints.split(",")) {
    HostAndPort parsed = HostAndPort.fromString(contactPoint);
    result.add(
        new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042)));
  }
  return result;
}
 
開發者ID:liaominghua,項目名稱:zipkin,代碼行數:10,代碼來源:DefaultSessionFactory.java


注:本文中的com.google.common.net.HostAndPort.fromString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。