List of usage examples for com.google.common.collect ImmutableList isEmpty
boolean isEmpty();
From source file:org.apache.hadoop.hbase.regionserver.Store.java
long getNextMajorCompactTime() { // default = 24hrs long ret = conf.getLong(HConstants.MAJOR_COMPACTION_PERIOD, 1000 * 60 * 60 * 24); if (family.getValue(HConstants.MAJOR_COMPACTION_PERIOD) != null) { String strCompactionTime = family.getValue(HConstants.MAJOR_COMPACTION_PERIOD); ret = (new Long(strCompactionTime)).longValue(); }/*w w w .j av a2 s.c om*/ if (ret > 0) { // default = 20% = +/- 4.8 hrs double jitterPct = conf.getFloat("hbase.hregion.majorcompaction.jitter", 0.20F); if (jitterPct > 0) { long jitter = Math.round(ret * jitterPct); // deterministic jitter avoids a major compaction storm on restart ImmutableList<StoreFile> snapshot = storefiles; if (snapshot != null && !snapshot.isEmpty()) { String seed = snapshot.get(0).getPath().getName(); double curRand = new Random(seed.hashCode()).nextDouble(); ret += jitter - Math.round(2L * jitter * curRand); } else { ret = 0; // no storefiles == no major compaction } } } return ret; }
From source file:org.apache.hadoop.hbase.regionserver.Store.java
/** * Close all the readers/*from www . j a va 2 s. co m*/ * * We don't need to worry about subsequent requests because the HRegion holds * a write lock that will prevent any more reads or writes. * * @throws IOException */ ImmutableList<StoreFile> close() throws IOException { this.lock.writeLock().lock(); try { ImmutableList<StoreFile> result = storefiles; // Clear so metrics doesn't find them. storefiles = ImmutableList.of(); if (!result.isEmpty()) { // initialize the thread pool for closing store files in parallel. ThreadPoolExecutor storeFileCloserThreadPool = this.region.getStoreFileOpenAndCloseThreadPool( "StoreFileCloserThread-" + this.family.getNameAsString()); // close each store file in parallel CompletionService<Void> completionService = new ExecutorCompletionService<Void>( storeFileCloserThreadPool); for (final StoreFile f : result) { completionService.submit(new Callable<Void>() { public Void call() throws IOException { f.closeReader(true); return null; } }); } try { for (int i = 0; i < result.size(); i++) { Future<Void> future = completionService.take(); future.get(); } } catch (InterruptedException e) { throw new IOException(e); } catch (ExecutionException e) { throw new IOException(e.getCause()); } finally { storeFileCloserThreadPool.shutdownNow(); } } LOG.info("Closed " + this); return result; } finally { this.lock.writeLock().unlock(); } }
From source file:com.facebook.buck.parser.PythonDslProjectBuildFileParser.java
@VisibleForTesting protected BuildFileManifest getAllRulesInternal(Path buildFile) throws IOException, BuildFileParseException { ensureNotClosed();//www .j a v a 2 s. c o m initIfNeeded(); // Check isInitialized implications (to avoid Eradicate warnings). Objects.requireNonNull(buckPyProcess); Objects.requireNonNull(buckPyProcessInput); long alreadyReadBytes = buckPyProcessInput.getCount(); ParseBuckFileEvent.Started parseBuckFileStarted = ParseBuckFileEvent.started(buildFile, this.getClass()); buckEventBus.post(parseBuckFileStarted); ImmutableList<Map<String, Object>> values = ImmutableList.of(); Optional<String> profile = Optional.empty(); try (AssertScopeExclusiveAccess.Scope scope = assertSingleThreadedParsing.scope()) { Path cellPath = options.getProjectRoot().toAbsolutePath(); String watchRoot = cellPath.toString(); String projectPrefix = ""; if (options.getWatchman().getProjectWatches().containsKey(cellPath)) { ProjectWatch projectWatch = options.getWatchman().getProjectWatches().get(cellPath); watchRoot = projectWatch.getWatchRoot(); if (projectWatch.getProjectPrefix().isPresent()) { projectPrefix = projectWatch.getProjectPrefix().get(); } } currentBuildFile.set(buildFile); BuildFilePythonResult resultObject = performJsonRequest( ImmutableMap.of("buildFile", buildFile.toString(), "watchRoot", watchRoot, "projectPrefix", projectPrefix, "packageImplicitLoad", packageImplicitIncludeFinder.findIncludeForBuildFile(getBasePath(buildFile)))); Path buckPyPath = getPathToBuckPy(options.getDescriptions()); handleDiagnostics(buildFile, buckPyPath.getParent(), resultObject.getDiagnostics(), buckEventBus); values = resultObject.getValues(); LOG.verbose("Got rules: %s", values); LOG.verbose("Parsed %d rules from %s", values.size(), buildFile); profile = resultObject.getProfile(); if (profile.isPresent()) { LOG.debug("Profile result:\n%s", profile.get()); } if (values.isEmpty()) { // in case Python process cannot send values due to serialization issues, it will send an // empty list return BuildFileManifest.of(ImmutableMap.of(), ImmutableSortedSet.of(), ImmutableMap.of(), Optional.empty(), ImmutableList.of()); } return toBuildFileManifest(values); } finally { long parsedBytes = buckPyProcessInput.getCount() - alreadyReadBytes; processedBytes.ifPresent(processedBytes -> processedBytes.addAndGet(parsedBytes)); buckEventBus .post(ParseBuckFileEvent.finished(parseBuckFileStarted, values.size(), parsedBytes, profile)); } }
From source file:msi.gaml.factories.ModelAssembler.java
public ModelDescription assemble(final String projectPath, final String modelPath, final Iterable<ISyntacticElement> allModels, final ValidationContext collector, final boolean document, final Map<String, ModelDescription> mm) { final ImmutableList<ISyntacticElement> models = ImmutableList.copyOf(allModels); final TOrderedHashMap<String, ISyntacticElement> speciesNodes = new TOrderedHashMap(); final TOrderedHashMap<String, TOrderedHashMap<String, ISyntacticElement>>[] experimentNodes = new TOrderedHashMap[1]; final ISyntacticElement globalNodes = SyntacticFactory.create(GLOBAL, (EObject) null, true); final ISyntacticElement source = models.get(0); Facets globalFacets = null;/* w w w . j av a 2 s . co m*/ if (source.hasFacet(IKeyword.PRAGMA)) { final Facets facets = source.copyFacets(null); final List<String> pragmas = (List<String>) facets.get(IKeyword.PRAGMA).getExpression().getConstValue(); collector.resetInfoAndWarning(); if (pragmas != null) { if (pragmas.contains(IKeyword.NO_INFO)) { collector.setNoInfo(); } if (pragmas.contains(IKeyword.NO_WARNING)) { collector.setNoWarning(); } if (pragmas.contains(IKeyword.NO_EXPERIMENT)) { collector.setNoExperiment(); } } } final Map<String, SpeciesDescription> tempSpeciesCache = new THashMap<>(); for (final ISyntacticElement cm : models.reverse()) { final SyntacticModelElement currentModel = (SyntacticModelElement) cm; if (currentModel != null) { if (currentModel.hasFacets()) { if (globalFacets == null) { globalFacets = new Facets(currentModel.copyFacets(null)); } else { globalFacets.putAll(currentModel.copyFacets(null)); } } currentModel.visitChildren(element -> globalNodes.addChild(element)); SyntacticVisitor visitor = element -> addSpeciesNode(element, speciesNodes, collector); currentModel.visitSpecies(visitor); // We input the species so that grids are always the last ones // (see DiffusionStatement) currentModel.visitGrids(visitor); visitor = element -> { if (experimentNodes[0] == null) { experimentNodes[0] = new TOrderedHashMap(); } addExperimentNode(element, currentModel.getName(), experimentNodes[0], collector); }; currentModel.visitExperiments(visitor); } } final String modelName = buildModelName(source.getName()); // We build a list of working paths from which the composite model will // be able to look for resources. These working paths come from the // imported models Set<String> absoluteAlternatePathAsStrings = models.isEmpty() ? null : ImmutableSet.copyOf( Iterables.transform(models.reverse(), each -> ((SyntacticModelElement) each).getPath())); if (mm != null) { for (final ModelDescription m1 : mm.values()) { for (final String im : m1.getAlternatePaths()) { absoluteAlternatePathAsStrings = Sets.union(absoluteAlternatePathAsStrings, Collections.singleton(im)); } } } final ModelDescription model = new ModelDescription(modelName, null, projectPath, modelPath, source.getElement(), null, ModelDescription.ROOT, null, globalFacets, collector, absoluteAlternatePathAsStrings); final Collection<String> allModelNames = models.size() == 1 ? null : ImmutableSet.copyOf( Iterables.transform(Iterables.skip(models, 1), each -> buildModelName(each.getName()))); model.setImportedModelNames(allModelNames); model.isDocumenting(document); // hqnghi add micro-models if (mm != null) { // model.setMicroModels(mm); model.addChildren(mm.values()); } // end-hqnghi // recursively add user-defined species to world and down on to the // hierarchy speciesNodes.forEachValue(speciesNode -> { addMicroSpecies(model, speciesNode, tempSpeciesCache); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { addExperiment(s, model, experimentNode, tempSpeciesCache); return true; }); return true; }); } // Parent the species and the experiments of the model (all are now // known). speciesNodes.forEachValue(speciesNode -> { parentSpecies(model, speciesNode, model, tempSpeciesCache); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { parentExperiment(model, experimentNode); return true; }); return true; }); } // Initialize the hierarchy of types model.buildTypes(); // hqnghi build micro-models as types if (mm != null) { for (final Entry<String, ModelDescription> entry : mm.entrySet()) { model.getTypesManager().alias(entry.getValue().getName(), entry.getKey()); } // end-hqnghi } // Make species and experiments recursively create their attributes, // actions.... complementSpecies(model, globalNodes); speciesNodes.forEachValue(speciesNode -> { complementSpecies(model.getMicroSpecies(speciesNode.getName()), speciesNode); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { complementSpecies(model.getExperiment(experimentNode.getName()), experimentNode); return true; }); return true; }); } // Complement recursively the different species (incl. the world). The // recursion is hierarchical model.inheritFromParent(); for (final SpeciesDescription sd : getSpeciesInHierarchicalOrder(model)) { sd.inheritFromParent(); if (sd.isExperiment()) { if (!sd.finalizeDescription()) { return null; } } } // Issue #1708 (put before the finalization) if (model.hasFacet(SCHEDULES) || model.hasFacet(FREQUENCY)) { createSchedulerSpecies(model); } if (!model.finalizeDescription()) { return null; } if (document) { collector.document(model); } return model; }
From source file:com.google.devtools.build.lib.rules.cpp.CompileBuildVariables.java
public static CcToolchainVariables setupVariablesOrThrowEvalException(FeatureConfiguration featureConfiguration, CcToolchainProvider ccToolchainProvider, String sourceFile, // TODO(b/76195763): Remove once blaze with cl/189769259 is released and crosstools are // updated. String outputFile, String gcnoFile, String dwoFile, String ltoIndexingFile, ImmutableList<String> includes, Iterable<String> userCompileFlags, CppModuleMap cppModuleMap, boolean usePic, String fakeOutputFile, String fdoStamp, String dotdFileExecPath, ImmutableList<VariablesExtension> variablesExtensions, ImmutableMap<String, String> additionalBuildVariables, Iterable<Artifact> directModuleMaps, Iterable<String> includeDirs, Iterable<String> quoteIncludeDirs, Iterable<String> systemIncludeDirs, Iterable<String> defines, boolean addLegacyCxxOptions) throws EvalException { Preconditions.checkNotNull(directModuleMaps); Preconditions.checkNotNull(includeDirs); Preconditions.checkNotNull(quoteIncludeDirs); Preconditions.checkNotNull(systemIncludeDirs); Preconditions.checkNotNull(defines); CcToolchainVariables.Builder buildVariables = new CcToolchainVariables.Builder( ccToolchainProvider.getBuildVariables()); buildVariables.addStringSequenceVariable(USER_COMPILE_FLAGS.getVariableName(), userCompileFlags); buildVariables.addLazyStringSequenceVariable(LEGACY_COMPILE_FLAGS.getVariableName(), getLegacyCompileFlagsSupplier(ccToolchainProvider, addLegacyCxxOptions)); if (sourceFile != null) { buildVariables.addStringVariable(SOURCE_FILE.getVariableName(), sourceFile); }// w w w. j ava 2s .c o m if (sourceFile == null || (!CppFileTypes.OBJC_SOURCE.matches(sourceFile) && !CppFileTypes.OBJCPP_SOURCE.matches(sourceFile))) { buildVariables.addLazyStringSequenceVariable(UNFILTERED_COMPILE_FLAGS.getVariableName(), getUnfilteredCompileFlagsSupplier(ccToolchainProvider)); } String fakeOutputFileOrRealOutputFile = fakeOutputFile != null ? fakeOutputFile : outputFile; if (outputFile != null) { // TODO(b/76195763): Remove once blaze with cl/189769259 is released and crosstools are // updated. if (!FileType.contains(PathFragment.create(outputFile), CppFileTypes.ASSEMBLER, CppFileTypes.PIC_ASSEMBLER, CppFileTypes.PREPROCESSED_C, CppFileTypes.PREPROCESSED_CPP, CppFileTypes.PIC_PREPROCESSED_C, CppFileTypes.PIC_PREPROCESSED_CPP)) { buildVariables.addStringVariable(OUTPUT_OBJECT_FILE.getVariableName(), fakeOutputFileOrRealOutputFile); } buildVariables.addStringVariable(OUTPUT_FILE.getVariableName(), fakeOutputFileOrRealOutputFile); } // Set dependency_file to enable <object>.d file generation. if (dotdFileExecPath != null) { buildVariables.addStringVariable(DEPENDENCY_FILE.getVariableName(), dotdFileExecPath); } if (featureConfiguration.isEnabled(CppRuleClasses.MODULE_MAPS) && cppModuleMap != null) { // If the feature is enabled and cppModuleMap is null, we are about to fail during analysis // in any case, but don't crash. buildVariables.addStringVariable(MODULE_NAME.getVariableName(), cppModuleMap.getName()); buildVariables.addStringVariable(MODULE_MAP_FILE.getVariableName(), cppModuleMap.getArtifact().getExecPathString()); StringSequenceBuilder sequence = new StringSequenceBuilder(); for (Artifact artifact : directModuleMaps) { sequence.addValue(artifact.getExecPathString()); } buildVariables.addCustomBuiltVariable(DEPENDENT_MODULE_MAP_FILES.getVariableName(), sequence); } if (featureConfiguration.isEnabled(CppRuleClasses.USE_HEADER_MODULES)) { // Module inputs will be set later when the action is executed. buildVariables.addStringSequenceVariable(MODULE_FILES.getVariableName(), ImmutableSet.of()); } if (featureConfiguration.isEnabled(CppRuleClasses.INCLUDE_PATHS)) { buildVariables.addStringSequenceVariable(INCLUDE_PATHS.getVariableName(), includeDirs); buildVariables.addStringSequenceVariable(QUOTE_INCLUDE_PATHS.getVariableName(), quoteIncludeDirs); buildVariables.addStringSequenceVariable(SYSTEM_INCLUDE_PATHS.getVariableName(), systemIncludeDirs); } if (!includes.isEmpty()) { buildVariables.addStringSequenceVariable(INCLUDES.getVariableName(), includes); } if (featureConfiguration.isEnabled(CppRuleClasses.PREPROCESSOR_DEFINES)) { Iterable<String> allDefines; if (fdoStamp != null) { // Stamp FDO builds with FDO subtype string allDefines = ImmutableList.<String>builder().addAll(defines) .add(CppConfiguration.FDO_STAMP_MACRO + "=\"" + fdoStamp + "\"").build(); } else { allDefines = defines; } buildVariables.addStringSequenceVariable(PREPROCESSOR_DEFINES.getVariableName(), allDefines); } if (usePic) { if (!featureConfiguration.isEnabled(CppRuleClasses.PIC)) { throw new EvalException(Location.BUILTIN, CcCommon.PIC_CONFIGURATION_ERROR); } buildVariables.addStringVariable(PIC.getVariableName(), ""); } if (gcnoFile != null) { buildVariables.addStringVariable(GCOV_GCNO_FILE.getVariableName(), gcnoFile); } if (dwoFile != null) { buildVariables.addStringVariable(PER_OBJECT_DEBUG_INFO_FILE.getVariableName(), dwoFile); } if (ltoIndexingFile != null) { buildVariables.addStringVariable(LTO_INDEXING_BITCODE_FILE.getVariableName(), ltoIndexingFile); } buildVariables.addAllStringVariables(additionalBuildVariables); for (VariablesExtension extension : variablesExtensions) { extension.addVariables(buildVariables); } return buildVariables.build(); }