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


Java SimpleDiscoveryNode类代码示例

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


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

示例1: discoveryProviderTest

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的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

示例2: setupHz

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的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

示例3: discoverNodes

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的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

示例4: mapEndpoints

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的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

示例5: createDiscoveryNode

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
@SneakyThrows
private DiscoveryNode createDiscoveryNode (InstanceInfo instanceInfo) {
    Map<String, Object> metadata = (Map) instanceInfo.getMetadata();
    String port = metadata.getOrDefault("hazelcast-port", "5701").toString();
    Address address = new Address(InetAddress.getByName(instanceInfo.getIPAddr()), parseInt(port));
    return new SimpleDiscoveryNode(address, metadata);
}
 
开发者ID:xxlabaza,项目名称:hazelcast_eureka,代码行数:8,代码来源:EurekaDiscoveryStrategy.java

示例6: discoverNodes

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
public Iterable<DiscoveryNode> discoverNodes() {
    List<DiscoveryNode> nodes = new ArrayList<DiscoveryNode>();
    String applicationName = applicationInfoManager.getEurekaInstanceConfig().getAppname();

    Application application = null;
    for (int i = 0; i < NUM_RETRIES; i++) {
        application = eurekaClient.getApplication(applicationName);
        if (application != null) {
            break;
        }
        try {
            TimeUnit.SECONDS.sleep(DISCOVERY_RETRY_TIMEOUT);
        } catch (InterruptedException almostIgnore) {
            Thread.currentThread().interrupt();
        }
    }
    if (application != null) {
        List<InstanceInfo> instances = application.getInstances();
        for (InstanceInfo instance : instances) {
            // Only recognize up and running instances
            if (instance.getStatus() != InstanceInfo.InstanceStatus.UP) {
                continue;
            }

            InetAddress address = mapAddress(instance);
            if (null == address) {
                continue;
            }

            int port = instance.getPort();
            Map<String, Object> metadata = (Map) instance.getMetadata();
            nodes.add(new SimpleDiscoveryNode(new Address(address, port), metadata));
        }
    }
    return nodes;
}
 
开发者ID:hazelcast,项目名称:hazelcast-eureka,代码行数:37,代码来源:EurekaOneDiscoveryStrategy.java

示例7: discoverNodes

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

  for (String serviceName : this.serviceNames) {
    try {
      InetAddress[] hosts = InetAddress.getAllByName(serviceName);

      for (InetAddress host : hosts) {
        Address address = ipToAddress(host.getHostAddress());
        if (LOGGER.isFinestEnabled()) {
          LOGGER.finest("Found node ip-address is: " + address);
        }

        servers.add(new SimpleDiscoveryNode(address));
      }

      if (servers.isEmpty()) {
        LOGGER.warning("Could not find any service for service '" + serviceName + "'");
      }
    } catch (Exception e) {
      if (LOGGER.isFinestEnabled()) {
        LOGGER.warning(e);
      }

      LOGGER.warning("DNS lookup for service '" + serviceName + "' failed");
    }
  }

  return servers;
}
 
开发者ID:jkutner,项目名称:hazelcast-heroku-discovery,代码行数:32,代码来源:HerokuDiscoveryStrategy.java

示例8: discoverNodes

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
/**
 * Look in consul for nodes with a given name. Exceptions are not rethrown
 * to prevent HazelCast of shutting down. This method returns an empty
 * list in case of error. When for example, consul returns to a normal state
 * a list of nodes is returned. HazelCast will try to connect to this
 * nodes.
 * 
 * @return A Collection of Nodes.
 */
@Override
public Collection<DiscoveryNode> discoverNodes() {

    Collection<DiscoveryNode> list = new LinkedList<>();
    try {

        ConsulResponse<List<CatalogService>> service
                = this.getClient().getService(serviceName);

        for (CatalogService s : service.getResponse()) {
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.log(Level.FINEST, "Found service at: {0}", s.getAddress());
            }
            Address address = new Address(s.getAddress(), s.getServicePort());
            list.add(new SimpleDiscoveryNode(address));
        }

        LOG.log(Level.INFO, "Hazelcast found ''{0}'' instance(s) of ''{1}'' ", new Object[]{list.size(), serviceName});

        return list;
        
    } catch (Exception e) {
        // The exception is no longer rethrown. When the exception
        // arrives in Hazelcast-core, it will stop working totally.
        // An empty list is delivered as default. This method will be
        // invoked again after a certain time. When consul is available,
        // it will answer, otherwise we just retry.
        LOG.severe(e.getMessage());
    }

    return list;
}
 
开发者ID:Neofonie,项目名称:hazelcast-consul-discovery,代码行数:42,代码来源:ConsulDiscovery.java

示例9: asDiscoveredNodes

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
private List<DiscoveryNode> asDiscoveredNodes(Set<Address> addresses) {
    List<DiscoveryNode> discoveryNodes = new ArrayList<DiscoveryNode>();
    for (Address address : addresses) {
        discoveryNodes.add(new SimpleDiscoveryNode(address));
    }
    return discoveryNodes;
}
 
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:8,代码来源:DnsEndpointResolver.java

示例10: addAddress

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
private void addAddress(List<DiscoveryNode> discoveredNodes, EndpointAddress endpointAddress) {
    Map<String, Object> properties = endpointAddress.getAdditionalProperties();
    String ip = endpointAddress.getIp();
    InetAddress inetAddress = mapAddress(ip);
    int port = (this.port > 0) ? this.port : getServicePort(properties);
    Address address = new Address(inetAddress, port);
    discoveredNodes.add(new SimpleDiscoveryNode(address, properties));
    if (logger.isFinestEnabled()) {
        logger.finest("Found node service with address: " + address);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:12,代码来源:ServiceEndpointResolver.java

示例11: discoverNodes

import com.hazelcast.spi.discovery.SimpleDiscoveryNode; //导入依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes() {
	
	List<DiscoveryNode> toReturn = new ArrayList<DiscoveryNode>();
	
	try {
		// discover healthy nodes only? (and its NOT the first invocation...)
		if (this.consulHealthyOnly && discoverNodesInvoked) {
			
			List<ServiceHealth> nodes = consulHealthClient.getHealthyServiceInstances(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken)).getResponse();
			
			for (ServiceHealth node : nodes) {
				toReturn.add(new SimpleDiscoveryNode(
								new Address(node.getService().getAddress(),node.getService().getPort())));
				getLogger().info("Discovered healthy node: " + node.getService().getAddress()+":"+node.getService().getPort());
			}
			
		// discover all services, regardless of health or this is the first invocation
		} else {
			
			ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken));
			
			for (CatalogService service : response.getResponse()) {
				
				String discoveredAddress = null;
				String rawServiceAddress = service.getServiceAddress();
				String rawAddress = service.getAddress();
				
				if (rawServiceAddress != null && !rawServiceAddress.trim().isEmpty()) {
				    discoveredAddress = rawServiceAddress;
					
				} else if (rawAddress != null && !rawAddress.trim().isEmpty()) {
				    getLogger().warning("discoverNodes() ServiceAddress was null/blank! " +
						     "for service: " + service.getServiceName() + 
						     " falling back to Address value");
				    discoveredAddress = rawAddress;
					
				} else {
				    getLogger().warning("discoverNodes() could not discover an address, " +
						     "both ServiceAddress and Address were null/blank! " +
						     "for service: " + service.getServiceName());
				}
				
				toReturn.add(new SimpleDiscoveryNode(
						new Address(discoveredAddress, service.getServicePort())));
				getLogger().info("Discovered healthy node: " + discoveredAddress+":"+service.getServicePort());
			}
		}
		
	} catch(Exception e) {
		getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(),e);
	}

	// flag we were invoked
	discoverNodesInvoked = true;
	
	return toReturn;
}
 
开发者ID:bitsofinfo,项目名称:hazelcast-consul-discovery-spi,代码行数:59,代码来源:ConsulDiscoveryStrategy.java


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