当前位置: 首页>>代码示例>>Java>>正文


Java HostAndPort.fromParts方法代码示例

本文整理汇总了Java中com.google.common.net.HostAndPort.fromParts方法的典型用法代码示例。如果您正苦于以下问题:Java HostAndPort.fromParts方法的具体用法?Java HostAndPort.fromParts怎么用?Java HostAndPort.fromParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.net.HostAndPort的用法示例。


在下文中一共展示了HostAndPort.fromParts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLeaderWrapper

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private boolean createLeaderWrapper(String leaderUrlStr) {
  try {
    URL tURL = new URL(leaderUrlStr);
    HostAndPort newLeader = HostAndPort.fromParts(tURL.getHost(), tURL.getPort());
    leaderUrlStr = newLeader.toString();
    if (leaderWrapper != null && leaderUrlStr.equals(leaderWrapper.getLeaderInfo())) {
      return true;
    }

    // create new Leader
    ManagedChannel clientChannel = session.getChannel(leaderUrlStr);
    leaderWrapper =
      new LeaderWrapper(
          leaderUrlStr,
          PDGrpc.newBlockingStub(clientChannel),
          PDGrpc.newStub(clientChannel),
          System.nanoTime());
  } catch (MalformedURLException e) {
    logger.error("Error updating leader.", e);
    return false;
  }
  logger.info(String.format("Switched to new leader: %s", leaderWrapper));
  return true;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:25,代码来源:PDClient.java

示例2: updateSeeds

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private void updateSeeds(ClusterConfig config) throws SyncException {
    List<String> hosts = new ArrayList<String>();
    for (Node n : config.getNodes()) {
        if (!config.getNode().equals(n)) {
            HostAndPort h = 
                    HostAndPort.fromParts(n.getHostname(), n.getPort());
            hosts.add(h.toString());
        }
    }
    Collections.sort(hosts);
    String seeds = Joiner.on(',').join(hosts);
    while (true) {
        try {
            Versioned<String> sv = unsyncStoreClient.get(SEEDS);
            if (sv.getValue() == null || !sv.getValue().equals(seeds)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("[{}] Updating seeds to \"{}\" from \"{}\"", 
                                 new Object[]{config.getNode().getNodeId(),
                                              seeds, sv.getValue()});
                }
                unsyncStoreClient.put(SEEDS, seeds);
            }
            break;
        } catch (ObsoleteVersionException e) { }
    }
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:27,代码来源:SyncStoreCCProvider.java

示例3: getReturnsPushGatewayProvider

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Test
public void getReturnsPushGatewayProvider() throws Exception {
    final MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_ACCEPTED));
    server.start();

    final MetricsPrometheusReporterConfiguration configuration = new MetricsPrometheusReporterConfiguration() {
        @Override
        public HostAndPort getAddress() {
            return HostAndPort.fromParts(server.getHostName(), server.getPort());
        }
    };
    final PushGatewayProvider provider = new PushGatewayProvider(configuration);
    final PushGateway pushGateway = provider.get();
    pushGateway.push(CollectorRegistry.defaultRegistry, "test");

    final RecordedRequest request = server.takeRequest();
    assertEquals("PUT", request.getMethod());
    assertEquals("/metrics/job/test", request.getPath());
    assertEquals("text/plain; version=0.0.4; charset=utf-8", request.getHeader("Content-Type"));
    assertEquals(0L, request.getBodySize());
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:23,代码来源:PushGatewayProviderTest.java

示例4: remoteDataSetTest

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Test
public void remoteDataSetTest() throws IOException {
    final int numCols = 3;
    final int size = 1000, resolution = 20;
    final SmallTable randTable = TestTables.getIntTable(size, numCols);
    RecordOrder cso = new RecordOrder();
    for (String colName : randTable.getSchema().getColumnNames()) {
        cso.append(new ColumnSortOrientation(randTable.getSchema().getDescription(colName), true));
    }
    final SampleQuantileSketch sqSketch = new SampleQuantileSketch(cso, resolution, size, 0);
    final HostAndPort h1 = HostAndPort.fromParts("127.0.0.1", 1234);
    final HillviewServer server1 = new HillviewServer(h1, new LocalDataSet<ITable>(randTable));
    try {
        final RemoteDataSet<ITable> rds1 = new RemoteDataSet<>(h1);
        final SampleList sl = rds1.blockingSketch(sqSketch);
        IndexComparator comp = cso.getComparator(sl.table);
        for (int i = 0; i < (sl.table.getNumOfRows() - 1); i++)
            assertTrue(comp.compare(i, i + 1) <= 0);
    } finally {
        server1.shutdown();
    }
}
 
开发者ID:vmware,项目名称:hillview,代码行数:23,代码来源:TableDataSetTest.java

示例5: setupResourceTestRule

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private ResourceTestRule setupResourceTestRule() {
    _authIdentityManager = new InMemoryAuthIdentityManager<>();
    _authIdentityManager.createIdentity(UAC_ALL_API_KEY, new ApiKeyModification().addRoles("uac-all"));

    final EmoPermissionResolver permissionResolver = new EmoPermissionResolver(mock(DataStore.class), mock(BlobStore.class));
    final InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    _roleManager = new InMemoryRoleManager(permissionManager);

    LocalSubjectUserAccessControl uac = new LocalSubjectUserAccessControl(_roleManager, permissionResolver,
            _authIdentityManager, HostAndPort.fromParts("localhost", 8080), new MetricRegistry());
    
    createRole(_roleManager, null, "uac-all", ImmutableSet.of("role|*", "apikey|*"));
    createRole(_roleManager, null, "uac-none", ImmutableSet.of());

    return setupResourceTestRule(
            ImmutableList.of(
                    new UserAccessControlResource1(
                            new RoleResource1(uac),
                            new ApiKeyResource1(uac)),
                    new UserAccessControlRequestMessageBodyReader()),
            _authIdentityManager,
            permissionManager);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:24,代码来源:UserAccessControlJerseyTest.java

示例6: getHostAndPortFromConnectorFactories

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private HostAndPort getHostAndPortFromConnectorFactories(List<ConnectorFactory> connectors) {
    // find the first connector that matches and return it host/port information (in practice there should
    // be one, and just one, match)
    try {
        HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) Iterables.find(connectors, Predicates.instanceOf(HttpConnectorFactory.class));

        String host = httpConnectorFactory.getBindHost();
        if (host == null) {
            host = getLocalHost().getHostAddress();
        }
        int port = httpConnectorFactory.getPort();
        return HostAndPort.fromParts(host, port);
    } catch (NoSuchElementException ex) {
        throw new IllegalStateException("Did not find a valid HttpConnector for the server", ex);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:17,代码来源:SelfHostAndPortModule.java

示例7: updateSeeds

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private void updateSeeds(ClusterConfig config) throws SyncException {
    List<String> hosts = new ArrayList<String>();
    for (Node n : config.getNodes()) {
        if (!config.getNode().equals(n)) {
            HostAndPort h =
                    HostAndPort.fromParts(n.getHostname(), n.getPort());
            hosts.add(h.toString());
        }
    }
    Collections.sort(hosts);
    String seeds = Joiner.on(',').join(hosts);
    while (true) {
        try {
            Versioned<String> sv = unsyncStoreClient.get(SEEDS);
            if (sv.getValue() == null || !sv.getValue().equals(seeds)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("[{}] Updating seeds to \"{}\" from \"{}\"",
                                 new Object[]{config.getNode().getNodeId(),
                                              seeds, sv.getValue()});
                }
                unsyncStoreClient.put(SEEDS, seeds);
            }
            break;
        } catch (ObsoleteVersionException e) { }
    }
}
 
开发者ID:zhenshengcai,项目名称:floodlight-hardware,代码行数:27,代码来源:SyncStoreCCProvider.java

示例8: testProcessor

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestApacheThriftMethodInvoker.java

示例9: testProcessor

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:31,代码来源:TestDriftNettyMethodInvoker.java

示例10: testSingleDefault

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Test
public void testSingleDefault()
        throws Exception
{
    HostAndPort address = HostAndPort.fromParts("example.com", 1);
    testAddressSelector(simpleAddressSelector(address), ImmutableMap.of(), ImmutableList.of(address));

    testAddressSelector(
            simpleAddressSelector(address),
            ImmutableMap.of("testService" + ".thrift.client.addresses", "example.com:11,example.com:22"),
            ImmutableList.of(HostAndPort.fromParts("example.com", 11), HostAndPort.fromParts("example.com", 22)));
}
 
开发者ID:airlift,项目名称:drift,代码行数:13,代码来源:TestSimpleAddressSelectorBinder.java

示例11: getAddress

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Override
public HostAndPort getAddress() {
  Preconditions.checkState(state() == State.RUNNING);
  return HostAndPort.fromParts(
      advertisedHostOverride.or(serverAddress.getHostText()),
      serverAddress.getPort());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:8,代码来源:JettyServerModule.java

示例12: createUrlAddress

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
/** Turns {@code address} into a more human readable form. */
static HostAndPort createUrlAddress(HostAndPort address) {
  if (address.getHost().equals("::") || address.getHost().equals("0.0.0.0")) {
    return address.getPortOrDefault(80) == 80
        ? HostAndPort.fromHost(getCanonicalHostName())
        : HostAndPort.fromParts(getCanonicalHostName(), address.getPort());
  } else {
    return address.getPortOrDefault(80) == 80 ? HostAndPort.fromHost(address.getHost()) : address;
  }
}
 
开发者ID:bazelbuild,项目名称:rules_closure,代码行数:11,代码来源:NetworkUtils.java

示例13: testRedirectTargetNoAttribute

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Test
public void testRedirectTargetNoAttribute() throws Exception {
  HttpServletRequest mockRequest = mockRequest(null, null);

  replayAndMonitor(1);

  HostAndPort remote = HostAndPort.fromParts("foobar", HTTP_PORT);
  publishSchedulers(remote);

  assertEquals(
      Optional.of("http://foobar:500/some/path"),
      leaderRedirector.getRedirectTarget(mockRequest));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:14,代码来源:LeaderRedirectTest.java

示例14: testRedirectTargetWithAttribute

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
@Test
public void testRedirectTargetWithAttribute() throws Exception {
  HttpServletRequest mockRequest = mockRequest("/the/original/path", null);

  replayAndMonitor(1);

  HostAndPort remote = HostAndPort.fromParts("foobar", HTTP_PORT);
  publishSchedulers(remote);

  assertEquals(
      Optional.of("http://foobar:500/the/original/path"),
      leaderRedirector.getRedirectTarget(mockRequest));
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:14,代码来源:LeaderRedirectTest.java

示例15: register

import com.google.common.net.HostAndPort; //导入方法依赖的package包/类
private static void register() {
    AgentClient agentClient = consul.agentClient();

    List<Registration.RegCheck> checks = new ArrayList<Registration.RegCheck>();

    HostAndPort serviceHostAndPort = HostAndPort.fromParts(visibleHost, visiblePort);

    Registration.RegCheck mainCheck = Registration.RegCheck.tcp(serviceHostAndPort.toString(), 30);

    checks.add(mainCheck);

    Registration registration = ImmutableRegistration
            .builder()
            .port(visiblePort)
            .address(visibleHost)
            .checks(checks)
            .name(serviceName)
            .id(serviceId)
            .addTags(tsdMode)
            .build();

    agentClient.register(registration);

    if (agentClient.isRegistered(serviceId)) {
        LOGGER.info("Registered this instance with Consul");
    } else {
        LOGGER.warn("Consul reports that this instance is not registered");
    }
}
 
开发者ID:inst-tech,项目名称:opentsdb-plugins,代码行数:30,代码来源:ConsulPlugin.java


注:本文中的com.google.common.net.HostAndPort.fromParts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。