diff --git a/platform/feedback/src/com/intellij/platform/feedback/impl/GeneralFeedbackSubmit.kt b/platform/feedback/src/com/intellij/platform/feedback/impl/GeneralFeedbackSubmit.kt index 7bd8f1010c76..653cd6f5b610 100644 --- a/platform/feedback/src/com/intellij/platform/feedback/impl/GeneralFeedbackSubmit.kt +++ b/platform/feedback/src/com/intellij/platform/feedback/impl/GeneralFeedbackSubmit.kt @@ -113,7 +113,7 @@ fun submitFeedback(feedbackData: FeedbackRequestDataHolder, FeedbackRequestType.PRODUCTION_REQUEST -> PRODUCTION_FEEDBACK_URL } - val regionalFeedbackUrl = RegionUrlMapper.mapUrl(feedbackUrl) + val regionalFeedbackUrl = RegionUrlMapper.tryMapUrlBlocking(feedbackUrl) LOG.info("Feedback sent to $regionalFeedbackUrl") sendFeedback(regionalFeedbackUrl, feedbackData, onDone, onError) } diff --git a/platform/platform-impl/internal/src/com/intellij/internal/statistic/StatisticsRegionUrlMapperServiceImpl.kt b/platform/platform-impl/internal/src/com/intellij/internal/statistic/StatisticsRegionUrlMapperServiceImpl.kt index e46ba212bb65..4dd9e9ee2b67 100644 --- a/platform/platform-impl/internal/src/com/intellij/internal/statistic/StatisticsRegionUrlMapperServiceImpl.kt +++ b/platform/platform-impl/internal/src/com/intellij/internal/statistic/StatisticsRegionUrlMapperServiceImpl.kt @@ -30,7 +30,7 @@ private class StatisticsRegionUrlMapperServiceImpl(val scope: CoroutineScope) : scope.launch { while (isActive) { withContext(Dispatchers.IO) { - url = RegionUrlMapper.mapUrl(EventLogInternalApplicationInfo.EVENT_LOG_SETTINGS_URL_TEMPLATE) + url = RegionUrlMapper.tryMapUrlBlocking(EventLogInternalApplicationInfo.EVENT_LOG_SETTINGS_URL_TEMPLATE) } delay(10.minutes) } @@ -42,7 +42,7 @@ private class StatisticsRegionUrlMapperServiceImpl(val scope: CoroutineScope) : fun updateUrl() { scope.launch { withContext(Dispatchers.IO) { - url = RegionUrlMapper.mapUrl(EventLogInternalApplicationInfo.EVENT_LOG_SETTINGS_URL_TEMPLATE) + url = RegionUrlMapper.tryMapUrlBlocking(EventLogInternalApplicationInfo.EVENT_LOG_SETTINGS_URL_TEMPLATE) } } } diff --git a/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java b/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java index 60ba3ff01efe..5bcce3ba7073 100644 --- a/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java +++ b/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java @@ -34,7 +34,7 @@ public final class RegionUrlMapper { // augment the table with other regions if needed Region.CHINA, "https://www.jetbrains.com.cn/config/JetBrainsResourceMapping.json" ); - + private static final Map OVERRIDE_CONFIG_URL_TABLE = new HashMap<>(); // for testing static { for (Region reg : Region.values()) { @@ -57,31 +57,50 @@ public final class RegionUrlMapper { } /** - * Maps the specified resource URL to a corresponding region-specific URL for the region that is configured for the IDE - * see {@link #mapUrl(String, Region)} - * - * IMPORTANT: the method is potentially long-executing; involves network calls - * - * @param url the original resource URL - * @return the possibly adjusted URL that is specific to the currently specified IDE region. + * @deprecated Use the more explicitly named {@link #tryMapUrlBlocking}, or {@link #tryMapUrl} when calling from a suspending context. */ + @Deprecated @RequiresBackgroundThread @RequiresReadLockAbsence public static @NotNull String mapUrl(@NotNull String url) { - return mapUrl(url, RegionSettings.getRegion()); + return tryMapUrlBlocking(url); } /** - * Maps the specified resource URL to a corresponding region-specific URL - * IMPORTANT: the method is potentially long-executing; involves network calls - * - * @param url the original resource URL - * @param region the region for which the original url might be adjusted - * @return the adjusted url, in case the mapping is configured or the original url, if no adjustments are required + * @deprecated Use the more explicitly named {@link #tryMapUrlBlocking}, or {@link #tryMapUrl} when calling from a suspending context. */ + @Deprecated @RequiresBackgroundThread @RequiresReadLockAbsence public static @NotNull String mapUrl(@NotNull String url, @NotNull Region region) { + return tryMapUrlBlocking(url, region); + } + + /** + * @see #tryMapUrlBlocking(String, Region) + * @see #tryMapUrl(String) when calling from a suspending context, consider using the async version + * @see RegionSettings + */ + @RequiresBackgroundThread + @RequiresReadLockAbsence + public static @NotNull String tryMapUrlBlocking(@NotNull String url) { + return tryMapUrlBlocking(url, RegionSettings.getRegion()); + } + + /** + * Maps the specified resource URL to a corresponding region-specific URL. + *

+ * IMPORTANT: the method is potentially long-executing; involves network calls. + * Also note that in case the network call fails, this method returns the original URL silently (hence, "try" in its name). + * + * @param url the original resource URL + * @param region the region for which the original url might be adjusted + * @return the adjusted url in case the mapping is configured, or the original url if no adjustments are required + * @see #tryMapUrl(String, Region) when calling from a suspending context, consider using the async version + */ + @RequiresBackgroundThread + @RequiresReadLockAbsence + public static @NotNull String tryMapUrlBlocking(@NotNull String url, @NotNull Region region) { RegionMapping mappings = ourCache.get(region); return mappings.apply(url); }