List of usage examples for java.util.function Supplier get
T get();
From source file:com.thoughtworks.go.server.service.EntityHashingService.java
private String getFromCache(String cacheKey, Supplier<String> fingerprintSupplier) { String cachedMD5 = getFromCache(cacheKey); if (cachedMD5 != null) { return cachedMD5; }//from w w w .j a va2 s .c om String md5 = CachedDigestUtils.md5Hex(fingerprintSupplier.get()); goCache.put(ETAG_CACHE_KEY, cacheKey, md5); return md5; }
From source file:org.trustedanalytics.cloud.cc.CcClientTest.java
@SuppressWarnings(value = "unchecked") private void verifyGetForEntity(Supplier<Collection> supplier, String apiUrl, Class verifyClass) { mockGetForEntity(verifyClass, false); supplier.get(); verify(template).getForEntity(eq(apiUrl), eq(verifyClass)); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials.java
private <T> T runAndRecordMetrics(String action, List<KubernetesKind> kinds, String namespace, Supplier<T> op) { T result = null;/*from w w w . ja v a2 s . co m*/ Throwable failure = null; KubectlException apiException = null; long startTime = clock.monotonicTime(); try { result = op.get(); } catch (KubectlException e) { apiException = e; } catch (Exception e) { failure = e; } finally { Map<String, String> tags = new HashMap<>(); tags.put("action", action); if (kinds.size() == 1) { tags.put("kind", kinds.get(0).toString()); } else { tags.put("kinds", String.join(",", kinds.stream().map(KubernetesKind::toString).collect(Collectors.toList()))); } tags.put("account", accountName); tags.put("namespace", StringUtils.isEmpty(namespace) ? "none" : namespace); if (failure == null) { tags.put("success", "true"); } else { tags.put("success", "false"); tags.put("reason", failure.getClass().getSimpleName() + ": " + failure.getMessage()); } registry.timer(registry.createId("kubernetes.api", tags)).record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); if (failure != null) { throw new KubectlJobExecutor.KubectlException( "Failure running " + action + " on " + kinds + ": " + failure.getMessage(), failure); } else if (apiException != null) { throw apiException; } else { return result; } } }
From source file:com.savoirtech.logging.slf4j.json.logger.AbstractJsonLogger.java
@Override public JsonLogger field(String key, Supplier value) { try {//from ww w .j a v a2 s . c o m // in the rare case that the value passed is null, this method will be selected as more specific than the Object // method. Have to handle it here or the value.get() will NullPointer if (value == null) { jsonObject.add(key, null); } else { jsonObject.add(key, gson.toJsonTree(value.get())); } } catch (Exception e) { jsonObject.add(key, gson.toJsonTree(formatException(e))); } return this; }
From source file:ddf.catalog.impl.operations.OperationsCrudSupport.java
/** * Validates that the {@link StorageRequest} is non-null and has a non-empty list of * {@link ContentItem}s in it./*from w w w . ja v a 2 s.c om*/ * * @param request the {@link StorageRequest} * @throws IngestException if the {@link StorageRequest} is null, or request has a null or empty list of * {@link ContentItem}s */ private void validateStorageRequest(StorageRequest request, Supplier<List<ContentItem>> getContentItems) throws IngestException { if (request == null) { throw new IngestException("StorageRequest was null."); } List<ContentItem> contentItems = getContentItems.get(); if (CollectionUtils.isEmpty(contentItems)) { throw new IngestException("Cannot perform ingest or update with null/empty entry list."); } }
From source file:hydrograph.ui.propertywindow.widgets.customwidgets.databasecomponents.LoadTypeConfigurationDialog.java
/** * The Function will call to disable the widgets * @param textbox1//ww w. java 2 s .com * @param textbox2 * @param buttonWidgets * @return Selection Adapter */ private SelectionAdapter buttonSelectionListener(Text textbox2, Widget... buttonWidgets) { Supplier<Stream<Widget>> streamSupplier = () -> Stream.of(buttonWidgets); SelectionAdapter adapter = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { newTableRadioButton.setSelection(false); textbox2.setEnabled(false); streamSupplier.get().forEach((Widget widgets) -> { ((Button) widgets).setEnabled(false); }); if (OSValidator.isMac()) { ((Button) event.getSource()).setFocus(); } propertyDialogButtonBar.enableApplyButton(true); } }; return adapter; }
From source file:org.elasticsearch.xpack.security.authc.saml.SamlRealm.java
private static IdpConfiguration getIdpConfiguration(RealmConfig config, MetadataResolver metadataResolver, Supplier<EntityDescriptor> idpDescriptor) { final MetadataCredentialResolver resolver = new MetadataCredentialResolver(); final PredicateRoleDescriptorResolver roleDescriptorResolver = new PredicateRoleDescriptorResolver( metadataResolver);/*from ww w . ja va 2 s . co m*/ resolver.setRoleDescriptorResolver(roleDescriptorResolver); final InlineX509DataProvider keyInfoProvider = new InlineX509DataProvider(); resolver.setKeyInfoCredentialResolver( new BasicProviderKeyInfoCredentialResolver(Collections.singletonList(keyInfoProvider))); try { roleDescriptorResolver.initialize(); resolver.initialize(); } catch (ComponentInitializationException e) { throw new IllegalStateException("Cannot initialise SAML IDP resolvers for realm " + config.name(), e); } final String entityID = idpDescriptor.get().getEntityID(); return new IdpConfiguration(entityID, () -> { try { final Iterable<Credential> credentials = resolver .resolve(new CriteriaSet(new EntityIdCriterion(entityID), new EntityRoleCriterion(IDPSSODescriptor.DEFAULT_ELEMENT_NAME), new UsageCriterion(UsageType.SIGNING))); return CollectionUtils.iterableAsArrayList(credentials); } catch (ResolverException e) { throw new IllegalStateException( "Cannot resolve SAML IDP credentials resolver for realm " + config.name(), e); } }); }
From source file:com.epam.ta.reportportal.core.launch.impl.UpdateLaunchHandler.java
/** * Update test-items of specified launches with new LaunchID * * @param launchId//from ww w . jav a 2s.c o m */ private List<TestItem> updateChildrenOfLaunch(String launchId, Set<String> launches, boolean extendDescription) { List<TestItem> testItems = launches.stream().map(id -> { Launch launch = launchRepository.findOne(id); return testItemRepository.findByLaunch(launch).stream().map(item -> { item.setLaunchRef(launchId); if (item.getPath().size() == 0) { // Add launch reference description for top level items Supplier<String> newDescription = Suppliers.formattedSupplier( ((null != item.getItemDescription()) ? item.getItemDescription() : "") + (extendDescription ? "\r\n@launch '{} #{}'" : ""), launch.getName(), launch.getNumber()); item.setItemDescription(newDescription.get()); } return item; }).collect(toList()); }).flatMap(List::stream).collect(toList()); testItemRepository.save(testItems); return testItems.stream().filter(item -> item.getPath().size() == 0).collect(toList()); }
From source file:com.netflix.spinnaker.clouddriver.cloudfoundry.client.ServiceInstances.java
@Nullable public CloudFoundryServiceInstance getServiceInstance(String region, String serviceInstanceName) { CloudFoundrySpace space = orgs.findSpaceByRegion(region) .orElseThrow(() -> new CloudFoundryApiException("Cannot find region '" + region + "'")); Supplier<CloudFoundryServiceInstance> si = () -> Optional .ofNullable(getOsbServiceInstance(space, serviceInstanceName)).orElse(null); Supplier<CloudFoundryServiceInstance> up = () -> Optional .ofNullable(getUserProvidedServiceInstance(space, serviceInstanceName)).orElse(null); return Optional.ofNullable(si.get()).orElseGet(up); }