Search in sources :

Example 1 with ServiceDescriptors

use of io.airlift.discovery.client.ServiceDescriptors in project airlift by airlift.

the class InMemoryDiscoveryClient method getServices.

@Override
public CheckedFuture<ServiceDescriptors, DiscoveryException> getServices(String type, String pool) {
    requireNonNull(type, "type is null");
    requireNonNull(pool, "pool is null");
    ImmutableList.Builder<ServiceDescriptor> builder = ImmutableList.builder();
    for (ServiceDescriptor serviceDescriptor : this.announcements.get()) {
        if (serviceDescriptor.getType().equals(type) && serviceDescriptor.getPool().equals(pool)) {
            builder.add(serviceDescriptor);
        }
    }
    for (ServiceDescriptor serviceDescriptor : this.discovered.values()) {
        if (serviceDescriptor.getType().equals(type) && serviceDescriptor.getPool().equals(pool)) {
            builder.add(serviceDescriptor);
        }
    }
    return Futures.immediateCheckedFuture(new ServiceDescriptors(type, pool, builder.build(), maxAge, UUID.randomUUID().toString()));
}
Also used : ServiceDescriptor(io.airlift.discovery.client.ServiceDescriptor) ImmutableList(com.google.common.collect.ImmutableList) ServiceDescriptors(io.airlift.discovery.client.ServiceDescriptors)

Example 2 with ServiceDescriptors

use of io.airlift.discovery.client.ServiceDescriptors in project airlift by airlift.

the class SimpleServiceSelector method selectAllServices.

@Override
public List<ServiceDescriptor> selectAllServices() {
    try {
        ListenableFuture<ServiceDescriptors> future = lookupClient.getServices(type, pool);
        ServiceDescriptors serviceDescriptors = getFutureValue(future, DiscoveryException.class);
        return serviceDescriptors.getServiceDescriptors();
    } catch (DiscoveryException e) {
        log.error(e);
        return ImmutableList.of();
    }
}
Also used : DiscoveryException(io.airlift.discovery.client.DiscoveryException) ServiceDescriptors(io.airlift.discovery.client.ServiceDescriptors)

Aggregations

ServiceDescriptors (io.airlift.discovery.client.ServiceDescriptors)2 ImmutableList (com.google.common.collect.ImmutableList)1 DiscoveryException (io.airlift.discovery.client.DiscoveryException)1 ServiceDescriptor (io.airlift.discovery.client.ServiceDescriptor)1