当前位置: 首页>>代码示例>>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;未经允许,请勿转载。