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


Java CatalogService.getAddress方法代码示例

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


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

示例1: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的package包/类
@Override
public Collection<DiscoveredNode> discoverNodes() {

    Collection<DiscoveredNode> list = new LinkedList<>();
    Properties empty = new Properties();

    if (this.agentClient != null) {
        try {

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

            LOG.log(Level.WARNING, "Resolving service: {0}", 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 SimpleDiscoveredNode(address, empty));
            }

            if (list.isEmpty()) {
                LOG.warning("No consul instances found!");
            }
            return list;
        } catch (Exception e) {
            LOG.severe(e.getMessage());
            throw ExceptionUtil.rethrow(e);
        }
    }
    return list;
}
 
开发者ID:decoomanj,项目名称:hazelcast-consul-spi,代码行数:33,代码来源:ConsulDiscovery.java

示例2: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的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

示例3: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的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.orbitz.consul.model.catalog.CatalogService.getAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。