@Override public ListenableFuture<ServiceDescriptors> getServices(String type) { requireNonNull(type, "type is null"); ImmutableList.Builder<ServiceDescriptor> builder = ImmutableList.builder(); for (ServiceDescriptor serviceDescriptor : this.announcements.get()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } for (ServiceDescriptor serviceDescriptor : this.discovered.values()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } return immediateFuture(new ServiceDescriptors(type, null, builder.build(), maxAge, UUID.randomUUID().toString())); }
@Override public CheckedFuture<ServiceDescriptors, DiscoveryException> getServices(String type) { Preconditions.checkNotNull(type, "type is null"); ImmutableList.Builder<ServiceDescriptor> builder = ImmutableList.builder(); for (ServiceDescriptor serviceDescriptor : this.announcements.get()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } for (ServiceDescriptor serviceDescriptor : this.discovered.values()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } return Futures.immediateCheckedFuture(new ServiceDescriptors(type, null, builder.build(), maxAge, UUID.randomUUID().toString())); }
@Override public CheckedFuture<ServiceDescriptors, DiscoveryException> getServices(String type) { Preconditions.checkNotNull(type, "type is null"); ImmutableList.Builder<ServiceDescriptor> builder = ImmutableList.builder(); for (ServiceDescriptor serviceDescriptor : this.announcements.get()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } for (ServiceDescriptor serviceDescriptor : this.discovered.values()) { if (serviceDescriptor.getType().equals(type)) { builder.add(serviceDescriptor); } } return Futures.immediateCheckedFuture(new ServiceDescriptors(type, null, builder.build(), maxAge, UUID.randomUUID().toString())); }
@Override public ListenableFuture<ServiceDescriptors> 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 immediateFuture(new ServiceDescriptors(type, pool, builder.build(), maxAge, UUID.randomUUID().toString())); }
@Override public CheckedFuture<ServiceDescriptors, DiscoveryException> getServices(String type, String pool) { Preconditions.checkNotNull(type, "type is null"); Preconditions.checkNotNull(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())); }
@Override public CheckedFuture<ServiceDescriptors, DiscoveryException> getServices(String type, String pool) { Preconditions.checkNotNull(type, "type is null"); Preconditions.checkNotNull(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())); }
@Override public ServiceDescriptors handle(Request request, Response response) { Duration maxAge = extractMaxAge(response); String eTag = response.getHeader(HttpHeaders.ETAG); if (NOT_MODIFIED.code() == response.getStatusCode() && serviceDescriptors != null) { return new ServiceDescriptors(serviceDescriptors, maxAge, eTag); } if (OK.code() != response.getStatusCode()) { throw new DiscoveryException(format("Lookup of %s failed with status code %s", type, response.getStatusCode())); } String json; try { json = CharStreams.toString(new InputStreamReader(response.getInputStream(), Charsets.UTF_8)); } catch (IOException e) { throw new DiscoveryException(format("Lookup of %s failed", type), e); } ServiceDescriptorsRepresentation serviceDescriptorsRepresentation = serviceDescriptorsCodec.fromJson(json); if (!environment.equals(serviceDescriptorsRepresentation.getEnvironment())) { throw new DiscoveryException(format("Expected environment to be %s, but was %s", environment, serviceDescriptorsRepresentation.getEnvironment())); } return new ServiceDescriptors( type, pool, serviceDescriptorsRepresentation.getServiceDescriptors(), maxAge, eTag); } });
@Override public ServiceDescriptors handle(Request request, Response response) { Duration maxAge = extractMaxAge(response); String eTag = response.getHeader(HttpHeaders.ETAG); if (NOT_MODIFIED.code() == response.getStatusCode() && serviceDescriptors != null) { return new ServiceDescriptors(serviceDescriptors, maxAge, eTag); } if (OK.code() != response.getStatusCode()) { throw new DiscoveryException(format("Lookup of %s failed with status code %s", type, response.getStatusCode())); } byte[] json; try { json = ByteStreams.toByteArray(response.getInputStream()); } catch (IOException e) { throw new DiscoveryException(format("Lookup of %s failed", type), e); } ServiceDescriptorsRepresentation serviceDescriptorsRepresentation = serviceDescriptorsCodec.fromJson(json); if (!environment.equals(serviceDescriptorsRepresentation.getEnvironment())) { throw new DiscoveryException(format("Expected environment to be %s, but was %s", environment, serviceDescriptorsRepresentation.getEnvironment())); } return new ServiceDescriptors( type, pool, serviceDescriptorsRepresentation.getServiceDescriptors(), maxAge, eTag); } });
@Override public ServiceDescriptors handle(Request request, Response response) { Duration maxAge = extractMaxAge(response); String eTag = response.getHeader(HttpHeaders.ETAG); if (NOT_MODIFIED.code() == response.getStatusCode() && serviceDescriptors != null) { return new ServiceDescriptors(serviceDescriptors, maxAge, eTag); } if (OK.code() != response.getStatusCode()) { throw new DiscoveryException(format("Lookup of %s failed with status code %s", type, response.getStatusCode())); } byte[] json; try { json = ByteStreams.toByteArray(response.getInputStream()); } catch (IOException e) { throw new DiscoveryException(format("Lookup of %s failed", type), e); } ServiceDescriptorsRepresentation serviceDescriptorsRepresentation = serviceDescriptorsCodec.fromJson(json); if (!environment.equals(serviceDescriptorsRepresentation.getEnvironment())) { throw new DiscoveryException(format("Expected environment to be %s, but was %s", environment, serviceDescriptorsRepresentation.getEnvironment())); } return new ServiceDescriptors( type, pool, serviceDescriptorsRepresentation.getServiceDescriptors(), maxAge, eTag); } });