List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:org.trnltk.morphology.contextless.rootfinder.BruteForceVerbRootFinder.java
private Set<DynamicRoot> getPossibleCausativeRoots(TurkicLetter lastLetter, TurkishSequence partialInput, TurkishSequence wholeSurface, DynamicRoot noAttrRoot) { // no voicing can happen on causative_t final String wholeSurfaceStr = wholeSurface.getUnderlyingString(); final String partialInputStr = partialInput.getUnderlyingString(); final boolean mightHaveCausative_t = wholeSurfaceStr.startsWith(partialInputStr + 't') && (lastLetter.isContinuant() || lastLetter.isVowel()); final boolean mightHaveCausative_Ir = this.strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("r", "ir", "ur", "r")); // no voicing can happen on causative_It final boolean mightHaveCausative_It = this.strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("t", "it", "ut", "t")); final boolean mightHaveCausative_Ar = this.strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("ar", "er")); final boolean mightHaveCausative_dIr = this.strStartsWithAnyAdditionOfStr(wholeSurfaceStr, partialInputStr, Arrays.asList("dr", "dir", "dur", "dr", "tr", "tir", "tur", "tr")); final ImmutableMap<LexemeAttribute, Boolean> mightHaveCausatives = new ImmutableMap.Builder<LexemeAttribute, Boolean>() .put(LexemeAttribute.Causative_t, mightHaveCausative_t) .put(LexemeAttribute.Causative_Ir, mightHaveCausative_Ir) .put(LexemeAttribute.Causative_It, mightHaveCausative_It) .put(LexemeAttribute.Causative_Ar, mightHaveCausative_Ar) .put(LexemeAttribute.Causative_dIr, mightHaveCausative_dIr).build(); final HashSet<DynamicRoot> causativeRoots = new HashSet<DynamicRoot>(); for (Map.Entry<LexemeAttribute, Boolean> lexemeAttributeBooleanEntry : mightHaveCausatives.entrySet()) { final LexemeAttribute causativeAttr = lexemeAttributeBooleanEntry.getKey(); final Boolean mightHaveHappened = lexemeAttributeBooleanEntry.getValue(); if (!mightHaveHappened) continue; // cannot have other causatives at the same time // cannot have any other passive at the same time // cannot have progressive vowel drop at the same time // cannot have aorist_A or aorist_I at the same time final DynamicRoot generatedRoot = new DynamicRoot(noAttrRoot); generatedRoot.getLexeme().setAttributes(EnumSet.of(causativeAttr)); generatedRoot.setPhoneticAttributes(this.phoneticsAnalyzer.calculatePhoneticAttributes(partialInput, generatedRoot.getLexeme().getAttributes())); causativeRoots.add(generatedRoot); }/*from w w w. j av a 2s .c om*/ return causativeRoots; }
From source file:com.facebook.buck.thrift.ThriftJavaEnhancer.java
@Override public BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, ThriftConstructorArg args, ImmutableMap<String, ThriftSource> sources, ImmutableSortedSet<BuildRule> deps) throws NoSuchBuildTargetException { SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver); if (params.getBuildTarget().getFlavors().contains(CalculateAbi.FLAVOR)) { BuildTarget libraryTarget = params.getBuildTarget().withoutFlavors(CalculateAbi.FLAVOR); resolver.requireRule(libraryTarget); return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params, new BuildTargetSourcePath(libraryTarget)); }// www .java 2s . c o m // Pack all the generated sources into a single source zip that we'll pass to the // java rule below. ImmutableSortedSet.Builder<BuildRule> sourceZipsBuilder = ImmutableSortedSet.naturalOrder(); UnflavoredBuildTarget unflavoredBuildTarget = params.getBuildTarget().getUnflavoredBuildTarget(); for (ImmutableMap.Entry<String, ThriftSource> ent : sources.entrySet()) { String name = ent.getKey(); BuildRule compilerRule = ent.getValue().getCompileRule(); Path sourceDirectory = ent.getValue().getOutputDir().resolve("gen-java"); BuildTarget sourceZipTarget = getSourceZipBuildTarget(unflavoredBuildTarget, name); Path sourceZip = getSourceZipOutputPath(params.getProjectFilesystem(), unflavoredBuildTarget, name); sourceZipsBuilder.add(new SrcZip(params.copyWithChanges(sourceZipTarget, Suppliers.ofInstance(ImmutableSortedSet.of(compilerRule)), Suppliers.ofInstance(ImmutableSortedSet.of())), sourceZip, sourceDirectory)); } ImmutableSortedSet<BuildRule> sourceZips = sourceZipsBuilder.build(); resolver.addAllToIndex(sourceZips); // Create to main compile rule. BuildRuleParams javaParams = params.copyWithChanges( BuildTargets.createFlavoredBuildTarget(unflavoredBuildTarget, getFlavor()), Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(sourceZips).addAll(deps) .addAll(BuildRules.getExportedRules(deps)) .addAll(ruleFinder.filterBuildRuleInputs(templateOptions.getInputs(ruleFinder))).build()), Suppliers.ofInstance(ImmutableSortedSet.of())); BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR); final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder); return new DefaultJavaLibrary(javaParams, pathResolver, ruleFinder, FluentIterable.from(sourceZips).transform(SourcePaths.getToBuildTargetSourcePath()) .toSortedSet(Ordering.natural()), /* resources */ ImmutableSet.of(), templateOptions.getGeneratedSourceFolderName(), /* proguardConfig */ Optional.empty(), /* postprocessClassesCommands */ ImmutableList.of(), /* exportedDeps */ ImmutableSortedSet.of(), /* providedDeps */ ImmutableSortedSet.of(), /* abiJar */ abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, javaParams.getDeps()), templateOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.of(), new JavacToJarStepFactory(templateOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */ Optional.empty(), /* manifest file */ Optional.empty(), /* mavenCoords */ Optional.empty(), /* tests */ ImmutableSortedSet.of(), /* classesToRemoveFromJar */ ImmutableSet.of()); }
From source file:com.facebook.buck.thrift.ThriftLibraryDescription.java
@Override public <A extends ThriftConstructorArg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException { BuildTarget target = params.getBuildTarget(); // Extract the thrift language we're using from our build target. Optional<Map.Entry<Flavor, ThriftLanguageSpecificEnhancer>> enhancerFlavor = enhancers .getFlavorAndValue(target);/*from ww w . ja v a 2 s. c o m*/ SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver)); ImmutableMap<String, SourcePath> namedSources = pathResolver.getSourcePathNames(target, "srcs", args.srcs.keySet()); // The dependencies listed in "deps", which should all be of type "ThriftLibrary". ImmutableSortedSet<ThriftLibrary> thriftDeps = resolveThriftDeps(target, resolver.getAllRules(args.deps)); // The unflavored version of this rule is responsible for setting up the the various // build rules to facilitate dependents including it's thrift sources. if (!enhancerFlavor.isPresent()) { // Namespace the thrift files using our target's base path. ImmutableMap.Builder<Path, SourcePath> includesBuilder = ImmutableMap.builder(); for (ImmutableMap.Entry<String, SourcePath> entry : namedSources.entrySet()) { includesBuilder.put(target.getBasePath().resolve(entry.getKey()), entry.getValue()); } ImmutableMap<Path, SourcePath> includes = includesBuilder.build(); // Create the symlink tree build rule and add it to the resolver. Path includeRoot = getIncludeRoot(target, params.getProjectFilesystem()); BuildTarget symlinkTreeTarget = createThriftIncludeSymlinkTreeTarget(target); HeaderSymlinkTree symlinkTree = new HeaderSymlinkTree(params.copyWithChanges(symlinkTreeTarget, Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), pathResolver, includeRoot, includes); resolver.addToIndex(symlinkTree); // Create a dummy rule that dependents can use to grab the information they need // about this rule from the action graph. return new ThriftLibrary(params, pathResolver, thriftDeps, symlinkTree, includes); } ThriftLanguageSpecificEnhancer enhancer = enhancerFlavor.get().getValue(); String language = enhancer.getLanguage(); ImmutableSet<String> options = enhancer.getOptions(target, args); ImmutableSet<BuildTarget> implicitDeps = enhancer.getImplicitDepsForTargetFromConstructorArg(target, args); // Lookup the thrift library corresponding to this rule. We add an implicit dep onto // this rule in the findImplicitDepsFromParams method, so this should always exist by // the time we get here. ThriftLibrary thriftLibrary = (ThriftLibrary) resolver .getRule(BuildTarget.of(target.getUnflavoredBuildTarget())); // We implicitly pass the language-specific flavors of your thrift lib dependencies as // language specific deps to the language specific enhancer. ImmutableSortedSet<BuildRule> languageSpecificDeps = BuildRules.toBuildRulesFor(target, resolver, Iterables.concat( BuildTargets.propagateFlavorDomains(target, ImmutableList.of(enhancers), FluentIterable.from(thriftDeps).transform(HasBuildTarget::getBuildTarget)), implicitDeps)); // Form the set of generated sources, so that compiler rules know what output paths to record. ImmutableMap.Builder<String, ImmutableSortedSet<String>> generatedSourcesBuilder = ImmutableMap.builder(); for (ImmutableMap.Entry<String, SourcePath> ent : namedSources.entrySet()) { String thriftName = ent.getKey(); ImmutableList<String> services = Preconditions.checkNotNull(args.srcs.get(ent.getValue())); generatedSourcesBuilder.put(thriftName, enhancer.getGeneratedSources(target, args, thriftName, services)); } ImmutableMap<String, ImmutableSortedSet<String>> generatedSources = generatedSourcesBuilder.build(); // Create a a build rule for thrift source file, to compile the language specific sources. // They keys in this map are the logical names of the thrift files (e.g as specific in a BUCK // file, such as "test.thrift"). ImmutableMap<String, ThriftCompiler> compilerRules = createThriftCompilerBuildRules(params, resolver, enhancer.getCompilerType(), args.flags, language, options, namedSources, ImmutableSortedSet.<ThriftLibrary>naturalOrder().add(thriftLibrary) .addAll(getTransitiveThriftLibraryDeps(thriftDeps)).build(), generatedSources); resolver.addAllToIndex(compilerRules.values()); // Build up the map of {@link ThriftSource} objects to pass the language specific enhancer. // They keys in this map are the logical names of the thrift files (e.g as specific in a BUCK // file, such as "test.thrift"). ImmutableMap.Builder<String, ThriftSource> thriftSourceBuilder = ImmutableMap.builder(); for (ImmutableMap.Entry<String, SourcePath> ent : namedSources.entrySet()) { ImmutableList<String> services = Preconditions.checkNotNull(args.srcs.get(ent.getValue())); ThriftCompiler compilerRule = Preconditions.checkNotNull(compilerRules.get(ent.getKey())); thriftSourceBuilder.put(ent.getKey(), new ThriftSource(compilerRule, services, getThriftCompilerOutputDir(params.getProjectFilesystem(), target, ent.getKey()))); } ImmutableMap<String, ThriftSource> thriftSources = thriftSourceBuilder.build(); // Generate language specific rules. return enhancer.createBuildRule(targetGraph, params, resolver, args, thriftSources, languageSpecificDeps); }
From source file:org.apache.calcite.adapter.geode.rel.GeodeTable.java
/** * Executes an OQL query on the underlying table. * * <p>Called by the {@link GeodeQueryable} which in turn is * called via the generated code./* w ww.ja v a 2 s.co m*/ * * @param clientCache Geode client cache * @param fields List of fields to project * @param predicates A list of predicates which should be used in the query * @return Enumerator of results */ public Enumerable<Object> query(final GemFireCache clientCache, final List<Map.Entry<String, Class>> fields, final List<Map.Entry<String, String>> selectFields, final List<Map.Entry<String, String>> aggregateFunctions, final List<String> groupByFields, List<String> predicates, List<String> orderByFields, Long limit) { final RelDataTypeFactory typeFactory = new JavaTypeFactoryExtImpl(); final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder(); for (Map.Entry<String, Class> field : fields) { SqlTypeName typeName = typeFactory.createJavaType(field.getValue()).getSqlTypeName(); fieldInfo.add(field.getKey(), typeFactory.createSqlType(typeName)).nullable(true); } final RelProtoDataType resultRowType = RelDataTypeImpl.proto(fieldInfo.build()); ImmutableMap<String, String> aggFuncMap = ImmutableMap.of(); if (!aggregateFunctions.isEmpty()) { ImmutableMap.Builder<String, String> aggFuncMapBuilder = ImmutableMap.builder(); for (Map.Entry<String, String> e : aggregateFunctions) { aggFuncMapBuilder.put(e.getKey(), e.getValue()); } aggFuncMap = aggFuncMapBuilder.build(); } // Construct the list of fields to project Builder<String> selectBuilder = ImmutableList.builder(); if (!groupByFields.isEmpty()) { // manually add GROUP BY to select clause (GeodeProjection was not visited) for (String groupByField : groupByFields) { selectBuilder.add(groupByField + " AS " + groupByField); } if (!aggFuncMap.isEmpty()) { for (Map.Entry<String, String> e : aggFuncMap.entrySet()) { selectBuilder.add(e.getValue() + " AS " + e.getKey()); } } } else { if (selectFields.isEmpty()) { if (!aggFuncMap.isEmpty()) { for (Map.Entry<String, String> e : aggFuncMap.entrySet()) { selectBuilder.add(e.getValue() + " AS " + e.getKey()); } } else { selectBuilder.add("*"); } } else { if (!aggFuncMap.isEmpty()) { for (Map.Entry<String, String> e : aggFuncMap.entrySet()) { selectBuilder.add(e.getValue() + " AS " + e.getKey()); } } else { for (Map.Entry<String, String> field : selectFields) { selectBuilder.add(field.getKey() + " AS " + field.getValue()); } } } } final String oqlSelectStatement = Util.toString(selectBuilder.build(), "", ", ", ""); // Combine all predicates conjunctively String whereClause = ""; if (!predicates.isEmpty()) { whereClause = " WHERE "; whereClause += Util.toString(predicates, "", " AND ", ""); } // Build and issue the query and return an Enumerator over the results StringBuilder queryBuilder = new StringBuilder("SELECT "); queryBuilder.append(oqlSelectStatement); queryBuilder.append(" FROM /" + regionName); queryBuilder.append(whereClause); if (!groupByFields.isEmpty()) { queryBuilder.append(Util.toString(groupByFields, " GROUP BY ", ", ", "")); } if (!orderByFields.isEmpty()) { queryBuilder.append(Util.toString(orderByFields, " ORDER BY ", ", ", "")); } if (limit != null) { queryBuilder.append(" LIMIT " + limit); } final String oqlQuery = queryBuilder.toString(); Hook.QUERY_PLAN.run(oqlQuery); LOGGER.info("OQL: " + oqlQuery); return new AbstractEnumerable<Object>() { public Enumerator<Object> enumerator() { final QueryService queryService = clientCache.getQueryService(); try { SelectResults results = (SelectResults) queryService.newQuery(oqlQuery).execute(); return new GeodeEnumerator(results, resultRowType); } catch (Exception e) { String message = String.format(Locale.ROOT, "Failed to execute query [%s] on %s", oqlQuery, clientCache.getName()); throw new RuntimeException(message, e); } } }; }
From source file:com.facebook.buck.cxx.toolchain.PrefixMapDebugPathSanitizer.java
@Override public ImmutableList<String> getCompilationFlags(Compiler compiler, Path workingDir, ImmutableMap<Path, Path> prefixMap) { if (compiler instanceof WindowsCompiler) { return ImmutableList.of(); }//from w w w .ja va 2 s . co m ImmutableList.Builder<String> flags = ImmutableList.builder(); // As these replacements are processed one at a time, if one is a prefix (or actually is just // contained in) another, it must be processed after that other one. To ensure that we can // process them in the correct order, they are inserted into allPaths in order of length // (shortest first) so that prefixes will be handled correctly. RichStream.<Map.Entry<Path, String>>empty() // GCC has a bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71850) where it won't // properly pass arguments down to subprograms using argsfiles, which can make it prone to // argument list too long errors, so avoid adding `-fdebug-prefix-map` flags for each // `prefixMap` entry. .concat(compiler instanceof GccCompiler ? Stream.empty() : prefixMap.entrySet().stream().map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), useUnixPathSeparator ? MorePaths.pathWithUnixSeparators(e.getValue().toString()) : e.getValue().toString()))) .concat(RichStream.from(getAllPaths(Optional.of(workingDir)))) .sorted(Comparator.<Map.Entry<Path, String>>comparingInt( entry -> entry.getKey().toString().length()).thenComparing(entry -> entry.getKey())) .map(p -> getDebugPrefixMapFlag(p.getKey(), p.getValue())).forEach(flags::add); if (compiler instanceof GccCompiler) { // If we recorded switches in the debug info, the -fdebug-prefix-map values would contain the // unsanitized paths. flags.add("-gno-record-gcc-switches"); } return flags.build(); }
From source file:com.techcavern.pircbotz.InputParser.java
/** * Process any lines relevant to connect. Only called before bot is logged into the server * @param rawLine Raw, unprocessed line from the server * @param code //w ww . ja v a2s . com * @param target * @param parsedLine Processed line * @throws IrcException If the server rejects the bot (nick already in use or a 4** or 5** code * @throws IOException If an error occurs during upgrading to SSL */ public void processConnect(String rawLine, String code, String target, List<String> parsedLine) throws IrcException, IOException { if (CONNECT_CODES.contains(code)) { // We're connected to the server. bot.loggedIn(configuration.getName() + (nickSuffix == 0 ? "" : nickSuffix)); log.debug("Logged onto server."); configuration.getListenerManager().dispatchEvent(new ConnectEvent<PircBotZ>(bot)); //Handle automatic on connect stuff if (configuration.getNickservPassword() != null) bot.sendIRC().identify(configuration.getNickservPassword()); ImmutableMap<String, String> autoConnectChannels = bot.reconnectChannels(); if (autoConnectChannels == null) autoConnectChannels = configuration.getAutoJoinChannels(); for (Map.Entry<String, String> channelEntry : autoConnectChannels.entrySet()) bot.sendIRC().joinChannel(channelEntry.getKey(), channelEntry.getValue()); } else if (code.equals("433")) { //EXAMPLE: * AnAlreadyUsedName :Nickname already in use //Nickname in use, rename String usedNick = parsedLine.get(1); boolean autoNickChange = configuration.isAutoNickChange(); String autoNewNick = null; if (autoNickChange) { nickSuffix++; bot.sendIRC().changeNick(autoNewNick = configuration.getName() + nickSuffix); } configuration.getListenerManager() .dispatchEvent(new NickAlreadyInUseEvent<PircBotZ>(bot, usedNick, autoNewNick, autoNickChange)); } else if (code.equals("439")) { //EXAMPLE: PircBotX: Target change too fast. Please wait 104 seconds // No action required. //TODO: Should we delay joining channels here or something? log.warn("Ignoring too fast error"); } else if (configuration.isCapEnabled() && code.equals("421") && parsedLine.get(1).equals("CAP")) { //EXAMPLE: 421 you CAP :Unknown command log.warn("Ignoring unknown command error, server does not support CAP negotiation"); } else if (configuration.isCapEnabled() && code.equals("451") && target.equals("CAP")) { //EXAMPLE: 451 CAP :You have not registered //Ignore, this is from servers that don't support CAP log.warn("Ignoring not registered error, server does not support CAP negotiation"); } else if (code.startsWith("5") || code.startsWith("4")) throw new IrcException(IrcException.Reason.CannotLogin, "Received error: " + rawLine); else if (code.equals("670")) { //Server is saying that we can upgrade to TLS SSLSocketFactory sslSocketFactory = ((SSLSocketFactory) SSLSocketFactory.getDefault()); for (CapHandler curCapHandler : configuration.getCapHandlers()) if (curCapHandler instanceof TLSCapHandler) sslSocketFactory = ((TLSCapHandler) curCapHandler).getSslSocketFactory(); SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(bot.getSocket(), bot.getLocalAddress().getHostAddress(), bot.getSocket().getPort(), true); sslSocket.startHandshake(); bot.changeSocket(sslSocket); //Notify CAP Handlers for (CapHandler curCapHandler : configuration.getCapHandlers()) curCapHandler.handleUnknown(bot, rawLine); } else if (code.equals("CAP")) { //Handle CAP Code; remove extra from params String capCommand = parsedLine.get(1); ImmutableList<String> capParams = ImmutableList.copyOf(StringUtils.split(parsedLine.get(2))); if (capCommand.equals("LS")) for (CapHandler curCapHandler : configuration.getCapHandlers()) { log.debug("Executing cap handler " + curCapHandler); if (curCapHandler.handleLS(bot, capParams)) { log.debug("Cap handler " + curCapHandler + " finished"); capHandlersFinished.add(curCapHandler); } } else if (capCommand.equals("ACK")) { //Server is enabling a capability, store that bot.getEnabledCapabilities().addAll(capParams); for (CapHandler curCapHandler : configuration.getCapHandlers()) if (curCapHandler.handleACK(bot, capParams)) { log.trace("Removing cap handler " + curCapHandler); capHandlersFinished.add(curCapHandler); } } else if (capCommand.equals("NAK")) { for (CapHandler curCapHandler : configuration.getCapHandlers()) if (curCapHandler.handleNAK(bot, capParams)) capHandlersFinished.add(curCapHandler); } else //Maybe the CapHandlers know how to use it for (CapHandler curCapHandler : configuration.getCapHandlers()) if (curCapHandler.handleUnknown(bot, rawLine)) capHandlersFinished.add(curCapHandler); } else //Pass to CapHandlers, could be important for (CapHandler curCapHandler : configuration.getCapHandlers()) if (curCapHandler.handleUnknown(bot, rawLine)) capHandlersFinished.add(curCapHandler); //Send CAP END if all CapHandlers are finished if (configuration.isCapEnabled() && !capEndSent && capHandlersFinished.containsAll(configuration.getCapHandlers())) { capEndSent = true; bot.sendCAP().end(); bot.enabledCapabilities = Collections.unmodifiableList(bot.enabledCapabilities); } }
From source file:com.facebook.buck.config.BuckConfig.java
public Optional<ImmutableSet<PatternAndMessage>> getUnexpectedFlavorsMessages() { ImmutableMap<String, String> entries = config.get("unknown_flavors_messages"); if (!entries.isEmpty()) { Set<PatternAndMessage> patternAndMessages = new HashSet<>(); for (Map.Entry<String, String> entry : entries.entrySet()) { patternAndMessages.add(PatternAndMessage.of(Pattern.compile(entry.getKey()), entry.getValue())); }// w ww .j a v a 2 s . c om return Optional.of(ImmutableSet.copyOf(patternAndMessages)); } return Optional.empty(); }
From source file:com.google.devtools.build.lib.analysis.BuildView.java
/** * Sets the possible artifact roots in the artifact factory. This allows the factory to resolve * paths with unknown roots to artifacts. *//*from ww w . ja v a2 s . c o m*/ @VisibleForTesting // for BuildViewTestCase public void setArtifactRoots(ImmutableMap<PackageIdentifier, Path> packageRoots) { Map<Path, Root> rootMap = new HashMap<>(); Map<PackageIdentifier, Root> realPackageRoots = new HashMap<>(); for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) { Root root = rootMap.get(entry.getValue()); if (root == null) { root = Root.asSourceRoot(entry.getValue(), entry.getKey().getRepository().isMain()); rootMap.put(entry.getValue(), root); } realPackageRoots.put(entry.getKey(), root); } // Source Artifact roots: getArtifactFactory().setPackageRoots(realPackageRoots); }
From source file:org.apache.hadoop.yarn.server.security.CertificateLocalizationService.java
/** * Method invoked by a JMX client to get the state of the CertificateLocalization service. * Under the attributes tab./* w w w. j a v a2 s . co m*/ * @return It returns a map with the name of the material and the number of references. */ @Override public String getState() { ImmutableMap<StorageKey, SecurityMaterial> state; try { lock.lock(); state = ImmutableMap.copyOf(materialLocation); } finally { lock.unlock(); } ReturnState<String, String> returnState = new ReturnState<>(); ReturnState<String, Integer> internalState = new ReturnState<>(); for (Map.Entry<StorageKey, SecurityMaterial> entry : state.entrySet()) { internalState.put(entry.getKey().compactToString(), entry.getValue().getRequestedApplications()); } returnState.put(JMX_MATERIALIZED_KEY, JSON.toString(internalState)); return JSON.toString(returnState); }
From source file:com.google.devtools.build.lib.bazel.repository.downloader.HttpConnector.java
URLConnection connect(URL originalUrl, ImmutableMap<String, String> requestHeaders) throws IOException { if (Thread.interrupted()) { throw new InterruptedIOException(); }//from www .j a v a2 s . c om URL url = originalUrl; if (HttpUtils.isProtocol(url, "file")) { return url.openConnection(); } List<Throwable> suppressions = new ArrayList<>(); int retries = 0; int redirects = 0; int connectTimeout = MIN_CONNECT_TIMEOUT_MS; while (true) { HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(proxyHelper.createProxyIfNeeded(url)); boolean isAlreadyCompressed = COMPRESSED_EXTENSIONS.contains(HttpUtils.getExtension(url.getPath())) || COMPRESSED_EXTENSIONS.contains(HttpUtils.getExtension(originalUrl.getPath())); for (Map.Entry<String, String> entry : requestHeaders.entrySet()) { if (isAlreadyCompressed && Ascii.equalsIgnoreCase(entry.getKey(), "Accept-Encoding")) { // We're not going to ask for compression if we're downloading a file that already // appears to be compressed. continue; } connection.setRequestProperty(entry.getKey(), entry.getValue()); } connection.setConnectTimeout(connectTimeout); // The read timeout is always large because it stays in effect after this method. connection.setReadTimeout(READ_TIMEOUT_MS); // Java tries to abstract HTTP error responses for us. We don't want that. So we're going // to try and undo any IOException that doesn't appepar to be a legitimate I/O exception. int code; try { connection.connect(); code = connection.getResponseCode(); } catch (FileNotFoundException ignored) { code = connection.getResponseCode(); } catch (UnknownHostException e) { String message = "Unknown host: " + e.getMessage(); eventHandler.handle(Event.progress(message)); throw new UnrecoverableHttpException(message); } catch (IllegalArgumentException e) { // This will happen if the user does something like specify a port greater than 2^16-1. throw new UnrecoverableHttpException(e.getMessage()); } catch (IOException e) { if (!e.getMessage().startsWith("Server returned")) { throw e; } code = connection.getResponseCode(); } // 206 means partial content and only happens if caller specified Range. See RFC7233 4.1. if (code == 200 || code == 206) { return connection; } else if (code == 301 || code == 302 || code == 307) { readAllBytesAndClose(connection.getInputStream()); if (++redirects == MAX_REDIRECTS) { eventHandler.handle(Event.progress("Redirect loop detected in " + originalUrl)); throw new UnrecoverableHttpException("Redirect loop detected"); } url = HttpUtils.getLocation(connection); if (code == 301) { originalUrl = url; } } else if (code == 403) { // jart@ has noticed BitBucket + Amazon AWS downloads frequently flake with this code. throw new IOException(describeHttpResponse(connection)); } else if (code == 408) { // The 408 (Request Timeout) status code indicates that the server did not receive a // complete request message within the time that it was prepared to wait. Server SHOULD // send the "close" connection option (Section 6.1 of [RFC7230]) in the response, since // 408 implies that the server has decided to close the connection rather than continue // waiting. If the client has an outstanding request in transit, the client MAY repeat // that request on a new connection. Quoth RFC7231 6.5.7 throw new IOException(describeHttpResponse(connection)); } else if (code < 500 // 4xx means client seems to have erred quoth RFC7231 6.5 || code == 501 // Server doesn't support function quoth RFC7231 6.6.2 || code == 502 // Host not configured on server cf. RFC7231 6.6.3 || code == 505) { // Server refuses to support version quoth RFC7231 6.6.6 // This is a permanent error so we're not going to retry. readAllBytesAndClose(connection.getErrorStream()); throw new UnrecoverableHttpException(describeHttpResponse(connection)); } else { // However we will retry on some 5xx errors, particularly 500 and 503. throw new IOException(describeHttpResponse(connection)); } } catch (UnrecoverableHttpException e) { throw e; } catch (IOException e) { if (connection != null) { // If we got here, it means we might not have consumed the entire payload of the // response, if any. So we're going to force this socket to disconnect and not be // reused. This is particularly important if multiple threads end up establishing // connections to multiple mirrors simultaneously for a large file. We don't want to // download that large file twice. connection.disconnect(); } // We don't respect the Retry-After header (RFC7231 7.1.3) because it's rarely used and // tends to be too conservative when it is. We're already being good citizens by using // exponential backoff. Furthermore RFC law didn't use the magic word "MUST". int timeout = IntMath.pow(2, retries) * MIN_RETRY_DELAY_MS; if (e instanceof SocketTimeoutException) { eventHandler.handle(Event.progress("Timeout connecting to " + url)); connectTimeout = Math.min(connectTimeout * 2, MAX_CONNECT_TIMEOUT_MS); // If we got connect timeout, we're already doing exponential backoff, so no point // in sleeping too. timeout = 1; } else if (e instanceof InterruptedIOException) { // Please note that SocketTimeoutException is a subtype of InterruptedIOException. throw e; } if (++retries == MAX_RETRIES) { if (!(e instanceof SocketTimeoutException)) { eventHandler .handle(Event.progress(format("Error connecting to %s: %s", url, e.getMessage()))); } for (Throwable suppressed : suppressions) { e.addSuppressed(suppressed); } throw e; } // Java 7 allows us to create a tree of all errors that led to the ultimate failure. suppressions.add(e); eventHandler.handle( Event.progress(format("Failed to connect to %s trying again in %,dms", url, timeout))); url = originalUrl; try { sleeper.sleepMillis(timeout); } catch (InterruptedException translated) { throw new InterruptedIOException(); } } catch (RuntimeException e) { if (connection != null) { connection.disconnect(); } eventHandler.handle(Event.progress(format("Unknown error connecting to %s: %s", url, e))); throw e; } } }