System.out.printf("Trying to detect '%s' on '%s' ", serviceName, m_host); final CompletableFuture<Boolean> future = locationAwareDetectorClient.detect() .withLocation(m_location) .withSystemId(m_systemId) .withServiceName(serviceName) .withAddress(InetAddress.getByName(m_host)) .withAttributes(parse(attributes)) .execute();
@Override public CompletableFuture<Boolean> detect(String serviceName, String hostName, Map<String, String> detectorAttributes) { CompletableFuture<Boolean> detected = new CompletableFuture<>(); try { return locationAwareDetectorClient.detect() .withServiceName(serviceName) .withAddress(InetAddress.getByName(hostName)) .withAttributes(detectorAttributes) .execute(); } catch (Exception e) { detected.completeExceptionally(e); return detected; } } }
/** {@inheritDoc} */ @Override public void supplyAsyncThenAccept(final Callback<Boolean> cb) { try { LOG.info("Attemping to detect service {} on address {} at location {}", m_detectorConfig.getName(), getHostAddress(), getLocationName()); // Launch the detector m_service.getLocationAwareDetectorClient().detect().withClassName(m_detectorConfig.getPluginClass()) .withAddress(m_address).withNodeId(m_nodeId).withLocation(getLocationName()) .withAttributes(m_detectorConfig.getParameters().stream() .collect(Collectors.toMap(PluginParameter::getKey, PluginParameter::getValue))) .execute() // After completion, run the callback .whenComplete((res, ex) -> { LOG.info("Completed detector execution for service {} on address {} at location {}", m_detectorConfig.getName(), getHostAddress(), getLocationName()); if (ex != null) { cb.handleException(ex); } else { cb.accept(res); } }); } catch (Throwable e) { cb.handleException(e); } }
/** {@inheritDoc} */ @Override public void supplyAsyncThenAccept(final Callback<Boolean> cb) { try { LOG.info("Attemping to detect service {} on address {} at location {}", m_detectorConfig.getName(), getHostAddress(), getLocationName()); // Launch the detector m_service.getLocationAwareDetectorClient().detect().withClassName(m_detectorConfig.getPluginClass()) .withAddress(m_address).withNodeId(m_nodeId).withLocation(getLocationName()) .withAttributes(m_detectorConfig.getParameters().stream() .collect(Collectors.toMap(PluginParameter::getKey, PluginParameter::getValue))) .execute() // After completion, run the callback .whenComplete((res, ex) -> { LOG.info("Completed detector execution for service {} on address {} at location {}", m_detectorConfig.getName(), getHostAddress(), getLocationName()); if (ex != null) { cb.handleException(ex); } else { cb.accept(res); } }); } catch (Throwable e) { cb.handleException(e); } }