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


Java ServiceDiscovery.queryForInstances方法代码示例

本文整理汇总了Java中org.apache.curator.x.discovery.ServiceDiscovery.queryForInstances方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscovery.queryForInstances方法的具体用法?Java ServiceDiscovery.queryForInstances怎么用?Java ServiceDiscovery.queryForInstances使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.curator.x.discovery.ServiceDiscovery的用法示例。


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

示例1: listInstances

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public void listInstances(ServiceDiscovery<MetaData> serviceDiscovery) throws Exception {
    // This shows how to query all the instances in service discovery
    try {
        Collection<String> serviceNames = serviceDiscovery.queryForNames();
        for (String serviceName : serviceNames) {
            Collection<ServiceInstance<MetaData>> instances = serviceDiscovery.queryForInstances(serviceName);
            log.info("serviceName: " + serviceName);
            for (ServiceInstance<MetaData> instance : instances) {
                outputInstance(instance);
            }
        }
    } catch (Exception e) {
            /*                 * Something bad did happen, but carry on
             */
        log.error(e.getMessage(), e);
    }
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:18,代码来源:CuratorManager.java

示例2: listServiceInstance

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public List<String> listServiceInstance() throws Exception {
    List<String> list = new ArrayList<String>();
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceUtil.getServiceDiscovery(curatorFramework, basePath);

    try {
        Collection<String> serviceNames = serviceDiscovery.queryForNames();
        for (String serviceName : serviceNames) {
            Collection<ServiceInstance<MetaData>> instances = serviceDiscovery.queryForInstances(serviceName);
            log.info("serviceName: " + serviceName);
            for (ServiceInstance<MetaData> instance : instances) {
                list.add(instance.getPayload().getListenAddress() + ":" + instance.getPayload().getListenPort());
                outputInstance(instance);
            }
        }

    } catch (Exception e) {
            /*                 * Something bad did happen, but carry on
             */
        log.error(e.getMessage(), e);
    }
    Collections.sort(list);
    log.debug("listsize:" + list.size());
    return list;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:25,代码来源:CuratorManager.java

示例3: listInstances

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
private static void listInstances(ServiceDiscovery<InstanceDetails> serviceDiscovery) throws Exception
{
    // This shows how to query all the instances in service discovery

    try
    {
        Collection<String>  serviceNames = serviceDiscovery.queryForNames();
        System.out.println(serviceNames.size() + " type(s)");
        for ( String serviceName : serviceNames )
        {
            Collection<ServiceInstance<InstanceDetails>> instances = serviceDiscovery.queryForInstances(serviceName);
            System.out.println(serviceName);
            for ( ServiceInstance<InstanceDetails> instance : instances )
            {
                outputInstance(instance);
            }
        }
    }
    finally
    {
        CloseableUtils.closeQuietly(serviceDiscovery);
    }
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:24,代码来源:DiscoveryExample.java

示例4: listInstances

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
private static void listInstances(ServiceDiscovery<InstanceDetails> serviceDiscovery) throws Exception {
	// This shows how to query all the instances in service discovery
	try {
		Collection<String> serviceNames = serviceDiscovery.queryForNames();
		System.out.println(serviceNames.size() + " type(s)");
		for (String serviceName : serviceNames) {
			Collection<ServiceInstance<InstanceDetails>> instances = serviceDiscovery.queryForInstances(serviceName);
			System.out.println(serviceName);
			for (ServiceInstance<InstanceDetails> instance : instances) {
				outputInstance(instance);
			}
		}
	} finally {
		CloseableUtils.closeQuietly(serviceDiscovery);
	}
}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:17,代码来源:DiscoveryExample.java

示例5: getWorkers

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public Collection<ServiceInstance<MetaData>> getWorkers(String serviceName) throws Exception {
    Collection<ServiceInstance<MetaData>> instances;
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceUtil.getServiceDiscovery(curatorFramework, basePath);
    try {
        instances = serviceDiscovery.queryForInstances(serviceName);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }

    return instances;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:13,代码来源:CuratorManager.java

示例6: registerLocalService

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
/**
 * Advertise availability.
 *
 * @return the registration client
 */
public CuratorManager registerLocalService() throws Exception {

    if (active.getAndSet(true)) {
        throw new IllegalStateException("This client instance is already available.");
    }

    try {
        if (curatorFramework.getState() != CuratorFrameworkState.STARTED) {
            curatorFramework.start();
        }

        for (Map.Entry<String, Integer> entry : services.entrySet()) {
            String serviceName = entry.getKey();
            int port = entry.getValue().intValue();

            ServiceDiscovery<MetaData> serviceDiscovery = ServiceUtil.getServiceDiscovery(curatorFramework, basePath);
            ServiceInstance<MetaData> service = ServiceUtil.configureServiceInstance(serviceName, port, listenAddress, parameters);
 
            /*                 * Having >1 instance with of the same name with same listenAddress + listPort is 
             * bad. Incur some overhead to look for duplicates and explode appropriately 
             */
            Collection<ServiceInstance<MetaData>> candidates = serviceDiscovery.queryForInstances(serviceName);

            for (ServiceInstance<MetaData> worker : candidates) {
                outputInstance(worker);
                if ((worker.getAddress().equals(service.getAddress())) && (worker.getPort() == port)) {
                    log.error("An instance of " + service + " already exists at: " +
                            service.getAddress() + ":" + port);
                    throw new IllegalStateException("Duplicate service being registered. for service: " +
                            serviceName + " at: " + basePath);
                }
            }

            log.debug("registering service: " + serviceName);
            serviceDiscovery.registerService(service);
            discoveryMap.put(serviceDiscovery, service);
            log.info("registered service: " + serviceName);
        }
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }

    return this;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:52,代码来源:CuratorManager.java

示例7: main

import org.apache.curator.x.discovery.ServiceDiscovery; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
    {
        CuratorFramework client = CuratorFrameworkFactory
                .newClient("ec2-54-211-43-119.compute-1.amazonaws.com:2181,ec2-54-198-130-168.compute-1.amazonaws.com,127.0.0.1:2181", 
                        new ExponentialBackoffRetry(1000, 3));
        client.start();
        
        ServiceDetails deployment = new ServiceDetails()
                  .setId("deployment")
                  .setName("deployment")
                  .setEndpoint("http://localhost:8080/excalibur/deployment/v1/")
                  .setVersion("v1.0")
                  .setProvider("aws")
                  .setPort(8080);
        
        ServiceDetails workflow = new ServiceDetails()
                 .setId("workflow")
                 .setName("workflow")
                 .setEndpoint("http://localhost:8080/excalibur/workflow/v1/")
                 .setVersion("1")
                 .setProvider("aws")
                 .setPort(8080);
        
        ObjectMapper mapper = new ObjectMapper();
//        String data = mapper.writeValueAsString(service);
        
//        client.create().forPath("/services");
//        client.create().withMode(CreateMode.EPHEMERAL).forPath("/services/deployment", data.getBytes());
        
//        mapper.readValue(client.getData().forPath("/services/deployment"), ServiceDetails.class);
        
        ServiceDiscovery<ServiceDetails> discovery = ServiceDiscoveryBuilder.builder(ServiceDetails.class)
                .client(client)
                .basePath("/services")
                .build();
        
        InstanceServer server = new InstanceServer(client, "/services", deployment);
        server.start();
        
        new InstanceServer(client, "/services", workflow).start();
        new InstanceServer(client, "/services", deployment).start();
        
//        ServiceInstance<ServiceDetails> instance = ServiceInstance.<ServiceDetails>builder()
//                .address(service.getEndpoint())
//                .id(service.getId())
//                .name(service.getName())
//                .payload(service)
//                .serviceType(ServiceType.DYNAMIC).build();
//        
//        discovery.registerService(instance);
        
        Collection<ServiceInstance<ServiceDetails>> services = discovery.queryForInstances("deployment");
        
//        ServiceProvider<ServiceDetails> provider = discovery.serviceProviderBuilder()
//                .serviceName("workflow")
////                .providerStrategy(new ProviderStrategy<ServiceDetails>()
////                {
////                    @Override
////                    public ServiceInstance<ServiceDetails> getInstance(InstanceProvider<ServiceDetails> instanceProvider) throws Exception
////                    {
////                        List<ServiceInstance<ServiceDetails>> instances = instanceProvider.getInstances();
////                        System.err.println(instances.size());
////                        
////                        return null;
////                    }
////                })
//                .build();
//        provider.start();
//        ServiceInstance<ServiceDetails> instance2 = provider.getInstance();
        
        for (ServiceInstance<ServiceDetails> serviceInstance : services)
        {
            System.out.println(serviceInstance);
        }
        
        server.close();
    }
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:78,代码来源:ServiceDiscoveryTest.java


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