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


Java DiscoveryNode类代码示例

本文整理汇总了Java中com.hazelcast.spi.discovery.DiscoveryNode的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryNode类的具体用法?Java DiscoveryNode怎么用?Java DiscoveryNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: determineMyLocalAddress

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
@SneakyThrows
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {

    Address myLocalAddress = localDiscoveryNode.getPrivateAddress();

    Object usePublicAddress = registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
    if (usePublicAddress instanceof Boolean && Boolean.class.cast(usePublicAddress)) {
        log.info("Registrator config property: {}:{} attempting to use it...",
                 CONFIG_PROP_PREFER_PUBLIC_ADDRESS,
                 usePublicAddress);
        Address publicAddress = localDiscoveryNode.getPublicAddress();
        myLocalAddress = (publicAddress != null) ? publicAddress : myLocalAddress;
    }

    return new Address(INET_UTILS_INSTANCE.findFirstNonLoopbackHostInfo().getIpAddress(), myLocalAddress.getPort());
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:18,代码来源:CustomDiscoveryNodeRegistrator.java

示例2: determineMyLocalAddress

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
@SneakyThrows
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
	
	Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
	 
	Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
	if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) {
		logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it...");
		Address publicAddress = localDiscoveryNode.getPublicAddress();
		if (publicAddress != null) {
			myLocalAddress = publicAddress;
		}
	}

	return new Address(InetUtils.getFirstNonLoopbackHostInfo().getIpAddress(), myLocalAddress.getPort());
}
 
开发者ID:xm-online,项目名称:xm-ms-config,代码行数:18,代码来源:CustomDiscoveryNodeRegistrator.java

示例3: discoveryStrategyFactory

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Bean
public DiscoveryStrategyFactory discoveryStrategyFactory () {
    return new DiscoveryStrategyFactory() {

        @Override
        public Class<? extends DiscoveryStrategy> getDiscoveryStrategyType () {
            return EurekaDiscoveryStrategy.class;
        }

        @Override
        public DiscoveryStrategy newDiscoveryStrategy (DiscoveryNode discoveryNode,
                                                       ILogger logger,
                                                       Map<String, Comparable> properties
        ) {
            val eurekaDiscoveryStrategy = new EurekaDiscoveryStrategy(logger, emptyMap());
            eurekaDiscoveryStrategy.setDiscoveryClient(discoveryClient);
            eurekaDiscoveryStrategy.setHaselcastNodeServiceId(applicationName);
            return eurekaDiscoveryStrategy;
        }

        @Override
        public Collection<PropertyDefinition> getConfigurationProperties () {
            return null;
        }
    };
}
 
开发者ID:xxlabaza,项目名称:hazelcast_eureka,代码行数:27,代码来源:HazelcastMemberConfiguration.java

示例4: shouldOnlyDiscoverInstancesWithUpStatus

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithUpStatus(){
    Application application = new Application();
    List<InstanceInfo> infoList = InstanceInfoGenerator
            .newBuilder(5, 1)
            .build()
            .toInstanceList();
    for (InstanceInfo info : infoList) {
        info.setStatus(InstanceInfo.InstanceStatus.DOWN);
        application.addInstance(info);
    }

    when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);

    Iterable<DiscoveryNode> nodes = strategy.discoverNodes();
    assertThat(nodes.iterator().hasNext(), is(false));
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:18,代码来源:EurekaOneDiscoveryStrategyTest.java

示例5: shouldOnlyDiscoverInstancesWithValidAddress

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Test
public void shouldOnlyDiscoverInstancesWithValidAddress(){
    Application application = new Application();
    InstanceInfo mockInfo = mock(InstanceInfo.class);
    when(mockInfo.getId()).thenReturn(RandomStringUtils.random(42));
    when(mockInfo.getStatus()).thenReturn(InstanceInfo.InstanceStatus.UP);
    when(mockInfo.getIPAddr()).thenReturn("local");

    application.addInstance(mockInfo);

    when(eurekaClient.getApplication(APPLICATION_NAME)).thenReturn(application);

    Iterable<DiscoveryNode> nodes = strategy.discoverNodes();

    verify(eurekaClient).getApplication(APPLICATION_NAME);
    verify(mockInfo).getStatus();
    verify(mockInfo).getIPAddr();

    assertThat(nodes.iterator().hasNext(), is(false));
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:21,代码来源:EurekaOneDiscoveryStrategyTest.java

示例6: discoveryProviderTest

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Test
public void discoveryProviderTest() throws Exception {
  environmentVariables.set("HEROKU_DNS_FORMATION_NAME", "localhost");

  DiscoveryNode local = new SimpleDiscoveryNode(new Address("127.0.0.1", 1010));
  DiscoveryStrategyFactory factory = new HerokuDiscoveryStrategyFactory();
  DiscoveryStrategy provider = factory.newDiscoveryStrategy(local, null, new HashMap<>());

  provider.start();

  Iterable<DiscoveryNode> nodes = provider.discoverNodes();
  Assert.assertNotNull(nodes);
  Assert.assertTrue("Empty DiscoveryNode list", nodes.iterator().hasNext());

  for (DiscoveryNode node : nodes) {
    LOGGER.info("Node -> {}", node.getPublicAddress());
  }
}
 
开发者ID:jkutner,项目名称:hazelcast-heroku-discovery,代码行数:19,代码来源:HerokuDiscoveryTest.java

示例7: discoverNodes

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes() {
    List<DiscoveryNode> discoveryNodes = new ArrayList<DiscoveryNode>();
    try {
        Iterable<? extends NodeMetadata> nodes = computeServiceBuilder.getFilteredNodes();
        for (NodeMetadata metadata : nodes) {
            if (metadata.getStatus() != NodeMetadata.Status.RUNNING) {
                continue;
            }
            discoveryNodes.add(buildDiscoveredNode(metadata));
        }
        if (discoveryNodes.isEmpty()) {
            LOGGER.warning("No running nodes discovered in configured cloud provider.");
        } else {
            StringBuilder sb = new StringBuilder("Discovered the following nodes with public IPS:\n");
            for (DiscoveryNode node : discoveryNodes) {
                sb.append("    ").append(node.getPublicAddress().toString()).append("\n");
            }
            LOGGER.finest(sb.toString());
        }
    } catch (Exception e) {
        throw new HazelcastException("Failed to get registered addresses", e);
    }
    return discoveryNodes;
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:26,代码来源:JCloudsDiscoveryStrategy.java

示例8: testShouldFetchHostMetadata

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Test
public void testShouldFetchHostMetadata() {
    ComputeServiceBuilder mockComputeServiceBuilder = mock(ComputeServiceBuilder.class);
    JCloudsDiscoveryStrategy jCloudsDiscoveryStrategy = new JCloudsDiscoveryStrategy(mockComputeServiceBuilder);
    Set<NodeMetadata> nodes = new HashSet<NodeMetadata>();
    HashSet<String> privateAddresses = new HashSet<String>();
    privateAddresses.add(jCloudsDiscoveryStrategy.getLocalHostAddress());
    nodes.add(new NodeMetadataImpl("", "", "dummy",
            null,
            null,
            new HashMap<String, String>(),
            new HashSet<String>(),
            null, null, null, null,
            NodeMetadata.Status.RUNNING, "",
            99999, privateAddresses, privateAddresses, null, "dummyHostName"));
    doReturn(nodes).when(mockComputeServiceBuilder).getFilteredNodes();

    Iterable<DiscoveryNode> runningNodes = jCloudsDiscoveryStrategy.discoverNodes();
    Map<String, Object> localMetadata = jCloudsDiscoveryStrategy.discoverLocalMetadata();

    for (DiscoveryNode ignored : runningNodes) {
        assertTrue(localMetadata.get(PARTITION_GROUP_HOST).toString().startsWith("dummyHostName"));
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-jclouds,代码行数:25,代码来源:JCloudsDiscoveryStrategyTest.java

示例9: determineMyLocalAddress

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override 
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
	
	Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
	 
	Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
	if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) {
		logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it...");
		Address publicAddress = localDiscoveryNode.getPublicAddress();
		if (publicAddress != null) {
			myLocalAddress = publicAddress;
		}
	}
	
	return myLocalAddress;
}
 
开发者ID:bitsofinfo,项目名称:hazelcast-consul-discovery-spi,代码行数:17,代码来源:LocalDiscoveryNodeRegistrator.java

示例10: init

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
public void init(
		String consulHost, 
		Integer consulPort, 
		String consulServiceName, 
		String[] consulServiceTags, 
		String consulAclToken,  
		boolean consulSslEnabled,
		String	consulSslServerCertFilePath,
		String consulSslServerCertBase64,
		boolean consulServerHostnameVerify,
		DiscoveryNode localDiscoveryNode,
		Map<String, Object> registratorConfig, 
		ILogger logger) {

}
 
开发者ID:bitsofinfo,项目名称:hazelcast-consul-discovery-spi,代码行数:17,代码来源:DoNothingRegistrator.java

示例11: setupHz

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
protected void setupHz(Map<Long, HaMembership> activeSet, ClusterConfig selfConfig) {
    Map<String, DiscoveryNode> newNodes = new TreeMap<>();
    for (HaMembership member : activeSet.values()) {
        try {
            ClusterConfig config = jsonMapper.readValue(member.getConfig(), ClusterConfig.class);
            String address = getAddress(config.getAdvertiseAddress());
            String[] parts = address.split(":");

            newNodes.put(address, new SimpleDiscoveryNode(new Address(parts[0], Integer.parseInt(parts[1]))));
        } catch (Exception e) {
            log.error("Failed to register cluster member {} {}", member.getUuid(), member.getConfig());
        }
    }

    if (selfNode != null) {
        newNodes.put(selfConfig.getAdvertiseAddress(), selfNode);
    }

    if (!this.hzNodes.keySet().equals(newNodes.keySet())) {
        log.info("Cluster membership changed {}", newNodes.keySet());
    }

    this.hzNodes = newNodes;
}
 
开发者ID:rancher,项目名称:cattle,代码行数:25,代码来源:DBDiscovery.java

示例12: discoverNodes

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes() {

	List<DiscoveryNode> toReturn = new ArrayList<DiscoveryNode>();

	try {

		Set<DiscoveredContainer> discoveredContainers = this.swarmDiscoveryUtil.discoverContainers();
		
		/**
		 * We have all the containers, convert to DiscoveryNodes and return...
		 */
		getLogger().info("discoverNodes() DiscoveredContainers["+discoveredContainers.size()+"]: " + 
				Arrays.toString(discoveredContainers.toArray(new DiscoveredContainer[]{})));
		
		for (DiscoveredContainer container : discoveredContainers) {
			toReturn.add(new SimpleDiscoveryNode(
					new Address(container.getIp(),
								swarmDiscoveryUtil.getHazelcastPeerPort())));
		}

		return toReturn;

	} catch(Exception e) {
		getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(),e);
	}

	return toReturn;
}
 
开发者ID:bitsofinfo,项目名称:hazelcast-docker-swarm-discovery-spi,代码行数:30,代码来源:DockerSwarmDiscoveryStrategy.java

示例13: SomeRestServiceDiscoveryStrategy

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
public SomeRestServiceDiscoveryStrategy(DiscoveryNode discoveryNode, ILogger logger, //
                                        Map<String, Comparable> properties) {
    super(logger, properties);
    this.discoveryNode = discoveryNode;

    this.baseUrl = getOrDefault("discovery.rest", DISCOVERY_URL, "http://localhost:12345/");
    this.applicationScope = getOrDefault("discovery.rest", APPLICATION_SCOPE, "hazelcast-cluster");

    logger.info("SomeRestService discovery strategy started {url=" //
            + baseUrl + ", scope=" + applicationScope + "}");

    GsonConverterFactory converterFactory = GsonConverterFactory.create();
    Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl).addConverterFactory(converterFactory).build();
    this.someRestService = retrofit.create(SomeRestService.class);
}
 
开发者ID:noctarius,项目名称:hazelcast-discovery-spi-demonstration,代码行数:16,代码来源:SomeRestServiceDiscoveryStrategy.java

示例14: mapEndpoints

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
private Iterable<DiscoveryNode> mapEndpoints(List<Endpoint> endpoints) {
    List<DiscoveryNode> discoveryNodes = new ArrayList<>();
    for (Endpoint endpoint : endpoints) {
        discoveryNodes.add(new SimpleDiscoveryNode(mapEndpoint(endpoint)));
    }
    return discoveryNodes;
}
 
开发者ID:noctarius,项目名称:hazelcast-discovery-spi-demonstration,代码行数:8,代码来源:SomeRestServiceDiscoveryStrategy.java

示例15: discoverNodes

import com.hazelcast.spi.discovery.DiscoveryNode; //导入依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes () {
    return tryToFindInstances()
            .map(instances -> instances.stream()
                    .map(it -> (EurekaDiscoveryClient.EurekaServiceInstance) it)
                    .map(it -> it.getInstanceInfo())
                    .filter(it -> it.getStatus() == UP)
                    .map(this::createDiscoveryNode)
                    .collect(toList())
            )
            .orElse(emptyList());
}
 
开发者ID:xxlabaza,项目名称:hazelcast_eureka,代码行数:13,代码来源:EurekaDiscoveryStrategy.java


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