本文整理汇总了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;
}
示例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) { }
}
}
示例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());
}
示例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();
}
}
示例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);
}
示例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);
}
}
示例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) { }
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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)));
}
示例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());
}
示例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;
}
}
示例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));
}
示例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));
}
示例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");
}
}