List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:com.metamx.druid.merger.coordinator.TaskStorageQueryAdapter.java
/** * Returns all recursive task statuses for a particular task, staying within the same task group. Includes that * task, plus any tasks it spawned, and so on. Does not include spawned tasks that ended up in a different task * group. Does not include this task's parents or siblings. *//*from w ww . j a v a2 s .c o m*/ public Map<String, Optional<TaskStatus>> getSameGroupChildStatuses(final String taskid) { final Optional<Task> taskOptional = storage.getTask(taskid); final Optional<TaskStatus> statusOptional = storage.getStatus(taskid); final ImmutableMap.Builder<String, Optional<TaskStatus>> resultBuilder = ImmutableMap.builder(); resultBuilder.put(taskid, statusOptional); final Iterable<Task> nextTasks = FunctionalIterable.create(storage.getAuditLogs(taskid)) .filter(new Predicate<TaskAction>() { @Override public boolean apply(TaskAction taskAction) { return taskAction instanceof SpawnTasksAction; } }).transformCat(new Function<TaskAction, Iterable<Task>>() { @Override public Iterable<Task> apply(TaskAction taskAction) { return ((SpawnTasksAction) taskAction).getNewTasks(); } }); if (taskOptional.isPresent() && statusOptional.isPresent()) { for (final Task nextTask : nextTasks) { if (nextTask.getGroupId().equals(taskOptional.get().getGroupId())) { resultBuilder.putAll(getSameGroupChildStatuses(nextTask.getId())); } } } return resultBuilder.build(); }
From source file:org.apache.aurora.scheduler.updater.OneWayJobUpdater.java
private Map<K, SideEffect> startNextInstanceGroup(InstanceStateProvider<K, T> stateProvider) { Set<K> idle = filterByStatus(instances, IDLE); if (idle.isEmpty()) { return ImmutableMap.of(); } else {//from w w w .j ava 2 s .com ImmutableMap.Builder<K, SideEffect> builder = ImmutableMap.builder(); Set<K> working = filterByStatus(instances, WORKING); Set<K> nextGroup = strategy.getNextGroup(idle, working); if (!nextGroup.isEmpty()) { for (K instance : nextGroup) { builder.put(instance, instances.get(instance).evaluate(stateProvider.getState(instance))); } LOG.info("Changed working set for update to " + filterByStatus(instances, WORKING)); } Map<K, SideEffect> sideEffects = builder.build(); if (!idle.isEmpty() && working.isEmpty() && !SideEffect.hasActions(sideEffects.values())) { // There's no in-flight instances, and no actions - so there's nothing left to initiate more // work on this job. Try to find more work, or converge. return builder.putAll(startNextInstanceGroup(stateProvider)).build(); } else { return sideEffects; } } }
From source file:com.android.build.gradle.tasks.PackageAndroidArtifact.java
/** * Packages the application incrementally. In case of instant run packaging, this is not a * perfectly incremental task as some files are always rewritten even if no change has * occurred.// w w w .j a v a 2 s. c om * * @param changedDex incremental dex packaging data * @param changedJavaResources incremental java resources * @param changedAssets incremental assets * @param changedAndroidResources incremental Android resource * @param changedNLibs incremental native libraries changed * @throws IOException failed to package the APK */ private void doTask(@NonNull ImmutableMap<RelativeFile, FileStatus> changedDex, @NonNull ImmutableMap<RelativeFile, FileStatus> changedJavaResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAssets, @NonNull ImmutableMap<RelativeFile, FileStatus> changedAndroidResources, @NonNull ImmutableMap<RelativeFile, FileStatus> changedNLibs) throws IOException { ImmutableMap.Builder<RelativeFile, FileStatus> javaResourcesForApk = ImmutableMap.builder(); javaResourcesForApk.putAll(changedJavaResources); Collection<File> instantRunDexBaseFiles; switch (dexPackagingPolicy) { case INSTANT_RUN_SHARDS_IN_SINGLE_APK: /* * If we're doing instant run, then we don't want to treat all dex archives * as dex archives for packaging. We will package some of the dex files as * resources. * * All dex files in directories whose name contains INSTANT_RUN_PACKAGES_PREFIX * are kept in the apk as dex files. All other dex files are placed as * resources as defined by makeInstantRunResourcesFromDex. */ instantRunDexBaseFiles = getDexFolders().stream() .filter(input -> input.getName().contains(INSTANT_RUN_PACKAGES_PREFIX)) .collect(Collectors.toSet()); Iterable<File> nonInstantRunDexBaseFiles = getDexFolders().stream() .filter(f -> !instantRunDexBaseFiles.contains(f)).collect(Collectors.toSet()); ImmutableMap<RelativeFile, FileStatus> newInstantRunResources = makeInstantRunResourcesFromDex( nonInstantRunDexBaseFiles); @SuppressWarnings("unchecked") ImmutableMap<RelativeFile, FileStatus> updatedChangedResources = IncrementalRelativeFileSets .union(Sets.newHashSet(changedJavaResources, newInstantRunResources)); changedJavaResources = updatedChangedResources; changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(instantRunDexBaseFiles), RelativeFile.EXTRACT_BASE))); break; case INSTANT_RUN_MULTI_APK: instantRunDexBaseFiles = getDexFolders().stream() .filter(input -> input.getName().contains(InstantRunSlicer.MAIN_SLICE_NAME)) .collect(Collectors.toSet()); changedDex = ImmutableMap.copyOf(Maps.filterKeys(changedDex, Predicates.compose(Predicates.in(instantRunDexBaseFiles), RelativeFile.EXTRACT_BASE))); case STANDARD: break; default: throw new RuntimeException("Unhandled DexPackagingPolicy : " + getDexPackagingPolicy()); } PrivateKey key; X509Certificate certificate; boolean v1SigningEnabled; boolean v2SigningEnabled; try { if (signingConfig != null && signingConfig.isSigningReady()) { CertificateInfo certificateInfo = KeystoreHelper.getCertificateInfo(signingConfig.getStoreType(), checkNotNull(signingConfig.getStoreFile()), checkNotNull(signingConfig.getStorePassword()), checkNotNull(signingConfig.getKeyPassword()), checkNotNull(signingConfig.getKeyAlias())); key = certificateInfo.getKey(); certificate = certificateInfo.getCertificate(); v1SigningEnabled = signingConfig.isV1SigningEnabled(); v2SigningEnabled = signingConfig.isV2SigningEnabled(); } else { key = null; certificate = null; v1SigningEnabled = false; v2SigningEnabled = false; } ApkCreatorFactory.CreationData creationData = new ApkCreatorFactory.CreationData(getOutputFile(), key, certificate, v1SigningEnabled, v2SigningEnabled, null, // BuiltBy getBuilder().getCreatedBy(), getMinSdkVersion(), PackagingUtils.getNativeLibrariesLibrariesPackagingMode(manifest), getNoCompressPredicate()::apply); try (IncrementalPackager packager = createPackager(creationData)) { packager.updateDex(changedDex); packager.updateJavaResources(changedJavaResources); packager.updateAssets(changedAssets); packager.updateAndroidResources(changedAndroidResources); packager.updateNativeLibraries(changedNLibs); } } catch (PackagerException | KeytoolException e) { throw new RuntimeException(e); } /* * Save all used zips in the cache. */ Stream.concat(changedDex.keySet().stream(), Stream.concat(changedJavaResources.keySet().stream(), Stream.concat(changedAndroidResources.keySet().stream(), changedNLibs.keySet().stream()))) .map(RelativeFile::getBase).filter(File::isFile).distinct().forEach((File f) -> { try { cacheByPath.add(f); } catch (IOException e) { throw new IOExceptionWrapper(e); } }); // Mark this APK production, this will eventually be saved when instant-run is enabled. // this might get overridden if the apk is signed/aligned. try { instantRunContext.addChangedFile(instantRunFileType, getOutputFile()); } catch (IOException e) { throw new BuildException(e.getMessage(), e); } }
From source file:com.facebook.buck.json.PythonDslProjectBuildFileParser.java
/** Initialize the parser, starting buck.py. */ private void init() throws IOException { try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("ParserInit"))) { ImmutableMap.Builder<String, String> pythonEnvironmentBuilder = ImmutableMap.builder(); // Strip out PYTHONPATH. buck.py manually sets this to include only nailgun. We don't want // to inject nailgun into the parser's PYTHONPATH, so strip that value out. // If we wanted to pass on some environmental PYTHONPATH, we would have to do some actual // merging of this and the BuckConfig's python module search path. pythonEnvironmentBuilder.putAll(Maps.filterKeys(environment, k -> !PYTHONPATH_ENV_VAR_NAME.equals(k))); if (options.getPythonModuleSearchPath().isPresent()) { pythonEnvironmentBuilder.put(PYTHONPATH_ENV_VAR_NAME, options.getPythonModuleSearchPath().get()); }/* w w w . j a va 2s. c om*/ ImmutableMap<String, String> pythonEnvironment = pythonEnvironmentBuilder.build(); ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(buildArgs()) .setEnvironment(pythonEnvironment).build(); LOG.debug("Starting buck.py command: %s environment: %s", params.getCommand(), params.getEnvironment()); buckPyProcess = processExecutor.launchProcess(params); LOG.debug("Started process %s successfully", buckPyProcess); buckPyProcessInput = new CountingInputStream(buckPyProcess.getInputStream()); buckPyProcessJsonGenerator = ObjectMappers.createGenerator(buckPyProcess.getOutputStream()); // We have to wait to create the JsonParser until after we write our // first request, because Jackson "helpfully" synchronously reads // from the InputStream trying to detect whether the encoding is // UTF-8 or UTF-16 as soon as you create a JsonParser: // // https://git.io/vSgnA // // Since buck.py doesn't write any data until after it receives // a query, creating the JsonParser here would hang indefinitely. InputStream stderr = buckPyProcess.getErrorStream(); AtomicInteger numberOfLines = new AtomicInteger(0); AtomicReference<Path> lastPath = new AtomicReference<Path>(); InputStreamConsumer stderrConsumer = new InputStreamConsumer(stderr, (InputStreamConsumer.Handler) line -> { Path path = currentBuildFile.get(); if (!Objects.equals(path, lastPath.get())) { numberOfLines.set(0); lastPath.set(path); } int count = numberOfLines.getAndIncrement(); if (count == 0) { buckEventBus.post(ConsoleEvent.warning("WARNING: Output when parsing %s:", path)); } buckEventBus.post(ConsoleEvent.warning("| %s", line)); }); stderrConsumerTerminationFuture = new FutureTask<>(stderrConsumer); stderrConsumerThread = Threads.namedThread(PythonDslProjectBuildFileParser.class.getSimpleName(), stderrConsumerTerminationFuture); stderrConsumerThread.start(); } }
From source file:org.attribyte.api.pubsub.HubEndpoint.java
@Override public Map<String, Metric> getMetrics() { ImmutableMap.Builder<String, Metric> builder = ImmutableMap.builder(); builder.putAll(notifierFactory.getMetrics()); builder.put("message-size", globalNotificationMetrics.notificationSize); builder.putAll(globalCallbackMetrics.getMetrics()); //Note: Subscription and host-specific metrics are not included by design! builder.putAll(verifierFactory.getMetrics()); MetricSet datastoreMetrics = datastore.getMetrics(); if (datastoreMetrics != null) { builder.putAll(datastoreMetrics.getMetrics()); }/*from ww w. j a v a 2 s . c o m*/ if (notifierServiceQueueSize != null) { builder.put("notifier-service-queue-size", notifierServiceQueueSize); } if (callbackServiceQueueSize != null) { builder.put("callback-service-queue-size", callbackServiceQueueSize); } builder.put("auto-disabled-subscriptions", autoDisabledSubscriptions); builder.put("rejected-callbacks", rejectedCallbacks); builder.put("rejected-notifications", rejectedNotifications); builder.put("rejected-verifications", rejectedVerifications); return builder.build(); }
From source file:org.sonatype.nexus.repository.storage.StorageTxImpl.java
@Override @Guarded(by = ACTIVE)//www . j a va 2 s . co m public AssetBlob createBlob(final String blobName, final Supplier<InputStream> streamSupplier, final Iterable<HashAlgorithm> hashAlgorithms, @Nullable final Map<String, String> headers, @Nullable final String declaredContentType, final boolean skipContentVerification) throws IOException { checkNotNull(blobName); checkNotNull(streamSupplier); checkNotNull(hashAlgorithms); checkArgument(!skipContentVerification || !Strings2.isBlank(declaredContentType), "skipContentVerification set true but no declaredContentType provided"); if (!writePolicy.checkCreateAllowed()) { throw new IllegalOperationException("Repository is read only: " + bucket.getRepositoryName()); } ImmutableMap.Builder<String, String> storageHeaders = ImmutableMap.builder(); storageHeaders.put(Bucket.REPO_NAME_HEADER, bucket.getRepositoryName()); storageHeaders.put(BlobStore.BLOB_NAME_HEADER, blobName); storageHeaders.put(BlobStore.CREATED_BY_HEADER, createdBy); if (!skipContentVerification) { storageHeaders.put(BlobStore.CONTENT_TYPE_HEADER, determineContentType(streamSupplier, blobName, declaredContentType)); } else { storageHeaders.put(BlobStore.CONTENT_TYPE_HEADER, declaredContentType); } if (headers != null) { storageHeaders.putAll(headers); } Map<String, String> storageHeadersMap = storageHeaders.build(); return blobTx.create(streamSupplier.get(), storageHeadersMap, hashAlgorithms, storageHeadersMap.get(BlobStore.CONTENT_TYPE_HEADER)); }
From source file:io.crate.metadata.doc.DocIndexMetaData.java
private ImmutableMap<ColumnIdent, String> getAnalyzers(ColumnIdent columnIdent, Map<String, Object> propertiesMap) { ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder(); for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) { Map<String, Object> columnProperties = (Map) columnEntry.getValue(); DataType columnDataType = getColumnDataType(columnProperties); ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey()); columnProperties = furtherColumnProperties(columnProperties); if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) { if (columnProperties.get("properties") != null) { builder.putAll( getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties"))); }/*ww w . j a v a 2 s . c o m*/ } String analyzer = (String) columnProperties.get("analyzer"); if (analyzer != null) { builder.put(newIdent, analyzer); } } return builder.build(); }
From source file:com.spectralogic.dsbrowser.gui.services.tasks.RecoverInterruptedJob.java
@Override public void executeJob() throws Exception { final FilesAndFolderMap filesAndFolderMap = FilesAndFolderMap.buildFromEndpoint(endpointInfo, uuid); final JobRequestType jobRequestType = JobRequestType.valueOf(filesAndFolderMap.getType()); this.job = getJob(ds3Client, uuid, jobRequestType, loggingService); if (job == null) { loggingService.logMessage("Could not get job " + uuid, LogType.ERROR); LOG.error("Could not get job " + uuid); return;// w w w .j av a2s.com } final UUID jobId = job.getJobId(); final String bucketName = job.getBucketName(); final String date = dateTimeUtils.nowAsString(); final Instant jobStartInstant = Instant.now(); final String targetLocation = filesAndFolderMap.getTargetLocation(); final String jobDate = filesAndFolderMap.getDate(); final String endpointName = endpointInfo.getEndpoint(); final String message = buildMessage(jobRequestType, bucketName); final String titleMessage = buildTitle(date, jobRequestType, endpointName); final String logMessage = buildLogMessage(jobRequestType, jobDate); final Map<String, Path> filesMap = filesAndFolderMap.getFiles(); final Map<String, Path> foldersMap = filesAndFolderMap.getFolders(); final long totalJobSize = filesAndFolderMap.getTotalJobSize(); final AtomicLong totalSent = addDataTransferListener(totalJobSize); final boolean isFilePropertiesEnabled = settingsStore.getFilePropertiesSettings().isFilePropertiesEnabled(); final boolean isCacheJobEnable = settingsStore.getShowCachedJobSettings().getShowCachedJob(); final String buildGetRecoveringMessage = buildGetRecoveringMessage(targetLocation, totalJobSize, resourceBundle, dateTimeUtils); final String buildPutRecoveringMessage = buildPutRecoveringMessage(targetLocation, totalJobSize, isCacheJobEnable, resourceBundle, dateTimeUtils); final String buildFinalMessage = buildFinalMessage(targetLocation, totalJobSize, resourceBundle); updateTitle(titleMessage); loggingService.logMessage(logMessage, INFO); updateMessage(message); job.attachObjectCompletedListener( s -> onCompleteListener(jobStartInstant, targetLocation, totalJobSize, totalSent, s)); addWaitingForChunkListener(totalJobSize, targetLocation); final ImmutableMap.Builder<String, Path> folderMapBuilder = new ImmutableMap.Builder<>(); foldersMap.forEach((name, path) -> { try { Files.walk(path).filter(child -> !hasNestedItems(child)) .map(p -> new Pair<>(targetLocation + name + "/" + path.relativize(p).toString() + appendSlashWhenDirectory(p), p)) .forEach(p -> folderMapBuilder.put(p.getKey(), p.getValue())); } catch (final SecurityException ex) { loggingService.logMessage("Unable to access path, please check permssions on " + path.toString(), LogType.ERROR); LOG.error("Unable to access path", ex); } catch (final IOException ex) { loggingService.logMessage("Unable to read path " + path.toString(), LogType.ERROR); LOG.error("Unable to read path", ex); } }); folderMapBuilder.putAll(filesMap); final ImmutableMap<String, Path> allMap = folderMapBuilder.build(); if (isFilePropertiesEnabled && !filesMap.isEmpty()) { LOG.info("Registering metadata access Implementation"); job.withMetadata(new MetadataAccessImpl(allMap)); } job.attachDataTransferredListener(l -> setDataTransferredListener(l, totalJobSize, totalSent)); job.transfer(objectName -> buildTransfer(targetLocation, jobRequestType, filesMap, foldersMap, objectName)); Platform.runLater(() -> { updateProgressAndLog(jobRequestType, totalJobSize, totalSent, buildGetRecoveringMessage, buildPutRecoveringMessage); }); waitForTransfer(filesAndFolderMap, jobId, isCacheJobEnable, ds3Client).observeOn(JavaFxScheduler.platform()) .doOnError(throwable -> { LOG.error("Encountered a failure while waiting for transfer", throwable); }).doOnComplete(() -> { loggingService.logMessage(buildFinalMessage, SUCCESS); removeJobIdAndUpdateJobsBtn(jobInterruptionStore, uuid); }).subscribe(); }
From source file:de.ii.xtraplatform.ogc.api.wfs.client.GetFeature.java
@Override public Map<String, String> asKvp(XMLDocumentFactory documentFactory, Versions versions) throws TransformerException, IOException, SAXException { final XMLDocument doc = documentFactory.newDocument(); final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.put("SERVICE", "WFS"); builder.put("REQUEST", getOperationName(versions.getWfsVersion())); builder.put(GML.getWord(versions.getWfsVersion(), WFS.VOCABULARY.OUTPUT_FORMAT).toUpperCase(), GML.getWord(versions.getGmlVersion(), GML.VOCABULARY.OUTPUTFORMAT_VALUE)); builder.put(WFS.getWord(versions.getWfsVersion(), WFS.VOCABULARY.VERSION).toUpperCase(), versions.getWfsVersion().toString()); if (this.count != null) { builder.put(WFS.getWord(versions.getWfsVersion(), WFS.VOCABULARY.COUNT).toUpperCase(), String.valueOf(count)); }/*from ww w. ja va 2 s . com*/ if (this.startIndex != null && versions.getWfsVersion().isGreaterOrEqual(WFS.VERSION._2_0_0)) { builder.put(WFS.getWord(versions.getWfsVersion(), WFS.VOCABULARY.STARTINDEX).toUpperCase(), String.valueOf(startIndex)); } if (this.resultType == RESULT_TYPE.HITS) { builder.put(WFS.getWord(versions.getWfsVersion(), WFS.VOCABULARY.RESULT_TYPE).toUpperCase(), String.valueOf(RESULT_TYPE.HITS).toLowerCase()); } if (!query.isEmpty()) { builder.putAll(query.get(0).asKvp(doc, versions)); } final String namespaces = doc.getNamespaceNormalizer().getNamespaces().keySet().stream() .map(prefix -> "xmlns(" + prefix + "," + doc.getNamespaceNormalizer().getNamespaceURI(prefix) + ")") .collect(Collectors.joining(",")); builder.put("NAMESPACES", namespaces); return builder.build(); }
From source file:com.facebook.buck.android.NonPreDexedDexBuildable.java
Supplier<ImmutableMap<String, HashCode>> addAccumulateClassNamesStep(ImmutableSet<Path> classPathEntriesToDex, ImmutableList.Builder<Step> steps) { ImmutableMap.Builder<String, HashCode> builder = ImmutableMap.builder(); steps.add(new AbstractExecutionStep("collect_all_class_names") { @Override/* w w w . java2s.c o m*/ public StepExecutionResult execute(ExecutionContext context) { Map<String, Path> classesToSources = new HashMap<>(); for (Path path : classPathEntriesToDex) { Optional<ImmutableSortedMap<String, HashCode>> hashes = AccumulateClassNamesStep .calculateClassHashes(context, getProjectFilesystem(), path); if (!hashes.isPresent()) { return StepExecutionResults.ERROR; } builder.putAll(hashes.get()); for (String className : hashes.get().keySet()) { if (classesToSources.containsKey(className)) { throw new IllegalArgumentException( String.format("Duplicate class: %s was found in both %s and %s.", className, classesToSources.get(className), path)); } classesToSources.put(className, path); } } return StepExecutionResults.SUCCESS; } }); return MoreSuppliers.memoize(builder::build); }