• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ServiceHealth类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getServices

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
List<ServiceHealth> getServices(String consulServiceName) {
  synchronized (consulLock) {
    checkInstance();
    try {
      ServiceCache cached = cachedServices.get(consulServiceName);
      if (cached == null || cached.when < (System.currentTimeMillis() - ConsulDiscoveryAgent.pollingInterval)) {
        HealthClient healthClient = consul.healthClient();
        List<ServiceHealth> services = healthClient.getAllServiceInstances(consulServiceName).getResponse();
        cached = new ServiceCache(System.currentTimeMillis(), services);
        cachedServices.put(consulServiceName, cached);
      }
      return cached.services;
    } catch (ConsulException e) {
      throw new ConsulDiscoveryException(e);
    }
  }
}
 
开发者ID:squark-io,项目名称:active-mq-consul-discovery,代码行数:18,代码来源:ConsulHolder.java


示例2: getNodeAddresses

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public ListenableFuture<List<ClusterNodeAddress>> getNodeAddresses() {

    final List<ClusterNodeAddress> addresses = new ArrayList<>();

    List<ServiceHealth> nodes = consul.healthClient()
            .getHealthyServiceInstances(configuration.getConsulServiceName(), getQueryOptions())
            .getResponse();

    for (ServiceHealth node : nodes) {
        addresses.add(new ClusterNodeAddress(node.getService().getAddress(), node.getService().getPort()));
    }

    log.debug(String.format("consul returned %s cluster nodes (%s)",
            addresses.size(),
            addresses.stream().map(a -> a.getHost() + ":" + a.getPort())
                    .collect(Collectors.joining(", "))));
    return Futures.immediateFuture(addresses);
}
 
开发者ID:pellepelster,项目名称:hivemq-consul-cluster-discovery,代码行数:20,代码来源:ConsulDiscoveryCallback.java


示例3: notify

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public void notify(Map<HostAndPort, ServiceHealth> newValues) {
    Set<Registration> previousEntries = topologyManager.registrationsForService(this.name);

    Set<Registration> newEntries = newValues.values().stream()
            .map(e -> new Registration("consul",
                                       this.name,
                                       e.getService().getAddress(),
                                       e.getService().getPort())
                    .addTags(e.getService().getTags())
            )
            .collect(Collectors.toSet());

    previousEntries.stream()
            .filter(e -> !newEntries.contains(e))
            .forEach(e -> {
                this.topologyManager.unregister(e);
            });

    newEntries.stream()
            .filter(e -> !previousEntries.contains(e))
            .forEach(e -> {
                this.topologyManager.register(e);
            });
}
 
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-topology-consul,代码行数:26,代码来源:ServiceCacheListener.java


示例4: connect

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
private void connect()
{
    if (connected) {
        return;
    }
    connected = true;
    // get all healthy docker services
    List<ServiceHealth> services = consulClient
        .healthClient()
        .getHealthyServiceInstances(serviceName)
        .getResponse();
    for (ServiceHealth service : services) {
        dockerMetadataCollectors.put(
            service.getNode().getNode(),
            dockerMetadataCollectorProvider.getCollector(
                URI.create("docker://" + service.getNode().getAddress() + ":" + service.getService().getPort())
            )
        );
    }
}
 
开发者ID:Marmelatze,项目名称:docker-controller,代码行数:21,代码来源:ConsulDockerMetadataCollectorProvider.java


示例5: notify

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public void notify(Map<HostAndPort, ServiceHealth> newValues) {
    Set<Registration> previousEntries = topologyManager.registrationsForService(this.name);

    Set<Registration> newEntries = newValues.values().stream()
            .map(e -> new Registration("consul",
                    this.name,
                    e.getService().getAddress(),
                    e.getService().getPort())
                    .addTags(e.getService().getTags())
            )
            .collect(Collectors.toSet());

    previousEntries.stream()
            .filter(e -> !newEntries.contains(e))
            .forEach(e -> {
                this.topologyManager.unregister(e);
            });

    newEntries.stream()
            .filter(e -> !previousEntries.contains(e))
            .forEach(e -> {
                this.topologyManager.register(e);
            });
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:26,代码来源:ServiceCacheListener.java


示例6: start

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public void start() throws Exception {
  LOG.info("Starting Consul Discovery Agent for " + basePath);
  taskRunner = new TaskRunnerFactory("Consul Discovery Agent");
  taskRunner.init();
  running.set(true);

  if (CONSUL_HOLDER == null || !CONSUL_HOLDER.hasInstance()) {
    CONSUL_HOLDER = ConsulHolder.initialize(Consul.builder().withUrl(basePath.toURL()).build(), this);
  } else {
    CONSUL_HOLDER = ConsulHolder.instance();
  }
  registerSelf();

  executorService = Executors.newSingleThreadScheduledExecutor();
  executorService.scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      if (running.get()) {
        try {
          if (CONSUL_HOLDER == null || !CONSUL_HOLDER.hasInstance()) {
            CONSUL_HOLDER =
              ConsulHolder.initialize(Consul.builder().withUrl(basePath.toURL()).build(), ConsulDiscoveryAgent.this);
          }
          checkTtl();

          List<ServiceHealth> services = CONSUL_HOLDER.getServices(consulServiceName);
          handleServices(services);
        } catch (Throwable t) {
          //We don't really want this thread to ever die as long as the agent is running, so we'll just log any
          // errors.
          LOG.warn("Failure in Consul service discovery", t);
        }
      } else {
        Thread.currentThread().interrupt();
      }
    }
  }, 0, pollingInterval, TimeUnit.MILLISECONDS);
}
 
开发者ID:squark-io,项目名称:active-mq-consul-discovery,代码行数:40,代码来源:ConsulDiscoveryAgent.java


示例7: getHealthyServiceInstances

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@GET
@Timed
@Path("/consul/{service}")
public List<ServiceHealth> getHealthyServiceInstances(
        @PathParam("service") String service) {
    return consul.healthClient().getHealthyServiceInstances(service)
            .getResponse();
}
 
开发者ID:smoketurner,项目名称:dropwizard-consul,代码行数:9,代码来源:HelloWorldResource.java


示例8: getUpdatedListOfServers

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
    List<CatalogService> services = getCatalogClient()
        .getService(name, getCatalogOptions())
        .getResponse();

    List<ServiceHealth> healths = getHealthClient()
        .getAllServiceInstances(name, getCatalogOptions())
        .getResponse();

    return services.stream()
        .filter(service -> !hasFailingChecks(service, healths))
        .map(this::newServer)
        .collect(Collectors.toList());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:ConsulServiceCallServerListStrategies.java


示例9: ServiceCache

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
ServiceCache(long when, List<ServiceHealth> services) {
  this.when = when;
  this.services = services;
}
 
开发者ID:squark-io,项目名称:active-mq-consul-discovery,代码行数:5,代码来源:ConsulHolder.java


示例10: discover

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Override
public Collection<ServiceHealth> discover(@Nonnull final Consul consul) {
    return consul.healthClient().getHealthyServiceInstances(service)
            .getResponse();
}
 
开发者ID:smoketurner,项目名称:dropwizard-consul,代码行数:6,代码来源:HealthyConsulServiceDiscoverer.java


示例11: isNotHealthy

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
protected boolean isNotHealthy(ServiceHealth health) {
    return health.getChecks().stream().anyMatch(this::isNotHealthy);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ConsulServiceCallServerListStrategy.java


示例12: isCheckOnService

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
protected boolean isCheckOnService(ServiceHealth check, CatalogService service) {
    return check.getService().getService().equalsIgnoreCase(service.getServiceName());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ConsulServiceCallServerListStrategy.java


示例13: hasFailingChecks

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
protected boolean hasFailingChecks(CatalogService service, List<ServiceHealth> healths) {
    return healths.stream().anyMatch(health -> isCheckOnService(health, service) && isNotHealthy(health));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ConsulServiceCallServerListStrategy.java


示例14: discoverNodes

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的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


示例15: findAvailableServicesTest

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
@Test
public void findAvailableServicesTest() {
    injects();
    final List<ServiceHealth> nodes = healthClient.getHealthyServiceInstances("DataService").getResponse();
    Assert.assertTrue(CollectionUtils.isEmpty(nodes));
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:7,代码来源:ConsulTests.java


示例16: buildServerList

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
/**
 * Converts a list of {@link ServiceHealth} objects into {@link Server}
 * objects
 *
 * @param services
 *            list of healthy service instances
 * @return list of server instances
 */
private List<Server> buildServerList(
        @Nonnull final Collection<ServiceHealth> services) {
    return services.stream().map(this::buildServer)
            .collect(Collectors.toList());
}
 
开发者ID:smoketurner,项目名称:dropwizard-consul,代码行数:14,代码来源:ConsulServerList.java


示例17: discover

import com.orbitz.consul.model.health.ServiceHealth; //导入依赖的package包/类
Collection<ServiceHealth> discover(Consul consul); 
开发者ID:smoketurner,项目名称:dropwizard-consul,代码行数:2,代码来源:ConsulServiceDiscoverer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OpTransferBlockProto类代码示例发布时间:2022-05-22
下一篇:
Java XListLiteral类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap