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


Java ServiceHealth类代码示例

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


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


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