List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:org.apache.gobblin.util.request_allocation.ConcurrentBoundedPriorityIterable.java
/** * Log statistics about this {@link ConcurrentBoundedPriorityIterable}. */// w w w. ja v a 2s .co m public synchronized void logStatistics(Optional<Logger> logger) { Logger actualLogger = logger.or(log); StringBuilder messageBuilder = new StringBuilder("Statistics for ") .append(ConcurrentBoundedPriorityIterable.class.getSimpleName()).append(": {"); messageBuilder.append(this.resourcePool).append(", "); messageBuilder.append("totalResourcesUsed: ") .append(this.resourcePool.stringifyRequirement(this.currentRequirement)).append(", "); messageBuilder.append("maxRequirementPerDimension: ") .append(this.resourcePool.stringifyRequirement(this.maxResourceRequirement)).append(", "); messageBuilder.append("requestsOffered: ").append(this.requestsOffered).append(", "); messageBuilder.append("requestsAccepted: ") .append(this.requestsOffered - this.requestsEvicted - this.requestsRefused).append(", "); messageBuilder.append("requestsRefused: ").append(this.requestsRefused).append(", "); messageBuilder.append("requestsEvicted: ").append(this.requestsEvicted); messageBuilder.append("}"); actualLogger.info(messageBuilder.toString()); }
From source file:com.addthis.hydra.job.spawn.resources.TaskResource.java
@GET @Path("/start") @Produces(MediaType.APPLICATION_JSON)/*from w ww. j a va 2s .c o m*/ public Response startTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> task) { // emitLogLineForAction(kv, "start task " + job + "/" + task); try { spawn.startTask(jobId.or(""), task.or(-1), true, true, false); return Response.ok().build(); } catch (Exception ex) { return Response.serverError().entity(ex.getMessage()).build(); } }
From source file:com.opentable.logging.jetty.JsonRequestLog.java
@Inject public JsonRequestLog(final Clock clock, final JsonRequestLogConfig config, final Optional<JsonRequestEventFactory> eventFactory) { this.clock = clock; this.startsWithBlackList = config.getStartsWithBlacklist(); this.equalityBlackList = config.getEqualityBlacklist(); this.eventFactory = eventFactory.or(RequestLogEvent::new); }
From source file:org.apache.rya.indexing.pcj.fluo.api.InsertTriples.java
/** * Insert a batch of RyaStatements into Fluo. * * @param fluo - A connection to the Fluo table that will be updated. (not null) * @param triples - The triples to insert. (not null) *///from www . j av a2 s .c o m public void insert(final FluoClient fluo, final Collection<RyaStatement> triples) { checkNotNull(fluo); checkNotNull(triples); try (Transaction tx = fluo.newTransaction()) { for (final RyaStatement triple : triples) { Optional<byte[]> visibility = Optional.fromNullable(triple.getColumnVisibility()); try { tx.set(spoFormat(triple), FluoQueryColumns.TRIPLES, Bytes.of(visibility.or(new byte[0]))); } catch (final TripleRowResolverException e) { log.error("Could not convert a Triple into the SPO format: " + triple); } } tx.commit(); } }
From source file:org.jage.platform.config.xml.readers.ArrayDefinitionReader.java
@Override public ArrayDefinition read(Element element) throws ConfigurationException { String nameAttribute = getRequiredAttribute(element, NAME); String typeAttribute = getRequiredAttribute(element, TYPE); Optional<String> isSingletonAttribute = getOptionalAttribute(element, IS_SINGLETON); ArrayDefinition definition = new ArrayDefinition(nameAttribute, toArrayClass(toClass(typeAttribute)), toBoolean(isSingletonAttribute.or(getDefaultIsSingleton()))); for (Element child : getChildrenIncluding(element, REFERENCE, VALUE)) { IArgumentDefinition value = argumentReader.read(child); definition.addItem(value);//from w ww . j a v a 2 s .c o m } // FIXME: Backward compatibility. Remove in future ticket for (Element child : getChildrenExcluding(element, REFERENCE, VALUE)) { IComponentDefinition innerDefinition = instanceReader.read(child); definition.addInnerComponentDefinition(innerDefinition); } return definition; }
From source file:org.seedstack.i18n.internal.infrastructure.service.TranslationServiceImpl.java
@Override public Map<String, String> getTranslationsForLocale(String locale) { Map<String, String> translations = new HashMap<String, String>(); for (Key key : keyRepository.loadAll()) { Optional<String> translation = getTranslationWithFallback(locale, key); if (translation.isPresent() || !allowMissingTranslation) { translations.put(key.getEntityId(), translation.or("[" + key.getEntityId() + "]")); }/*from ww w. ja v a2s . c o m*/ } return translations; }
From source file:org.sonar.server.computation.queue.ReportSubmitter.java
/** * @throws NotFoundException if the organization with the specified key does not exist * @throws IllegalArgumentException if the organization with the specified key is not the organization of the specified project (when it already exists in DB) *///from ww w . j a va 2s . c om public CeTask submit(String organizationKey, String projectKey, @Nullable String projectBranch, @Nullable String projectName, InputStream reportInput) { try (DbSession dbSession = dbClient.openSession(false)) { String effectiveProjectKey = ComponentKeys.createKey(projectKey, projectBranch); OrganizationDto organizationDto = getOrganizationDtoOrFail(dbSession, organizationKey); Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, effectiveProjectKey); ensureOrganizationIsConsistent(opt, organizationDto); ComponentDto project = opt .or(() -> createProject(dbSession, organizationDto, projectKey, projectBranch, projectName)); checkScanPermission(project); return submitReport(dbSession, reportInput, project); } }
From source file:net.wouterdanes.docker.maven.TagImageMojo.java
private void applyTagsToImage(ImageTagConfiguration config) throws MojoFailureException { String imageId = config.getId(); boolean push = config.isPush(); Optional<String> registry = Optional.fromNullable(config.getRegistry()); Optional<BuiltImageInfo> builtInfo = getBuiltImageForStartId(imageId); if (builtInfo.isPresent()) { imageId = builtInfo.get().getImageId(); registry = registry.or(builtInfo.get().getRegistry()); }//from ww w. ja v a2s. co m for (String nameAndTag : config.getTags()) { attachTag(imageId, nameAndTag); if (push) { enqueueForPushing(imageId, Optional.fromNullable(nameAndTag), registry); } } }
From source file:org.apache.nifi.reporting.datadog.DataDogReportingTask.java
private String buildMetricName(Optional<String> processorName, String metricName) { return metricsPrefix + "." + processorName.or("flow") + "." + metricName; }
From source file:com.pinterest.teletraan.resource.Builds.java
@GET @Path("/names") public List<String> getBuildNames(@QueryParam("filter") Optional<String> nameFilter, @QueryParam("start") Optional<Integer> start, @QueryParam("size") Optional<Integer> size) throws Exception { return buildDAO.getBuildNames(nameFilter.orNull(), start.or(1), size.or(DEFAULT_SIZE)); }