/** * Because these fields share a common value when that value is updated, clear all the cached values. */ protected static void resetAll() { for (CacheFeatureFlag featureFlag: CacheFeatureFlag.values()) { SYSTEM_CONFIG.clearProperty(SYSTEM_CONFIG.getPackageVariableName("query_response_caching_strategy")); featureFlag.on = null; } }
/** * Returns whether the feature flag has been configured. * * @return true if the feature flag has been configured. */ default boolean isSet() { SystemConfig systemConfig = SystemConfigProvider.getInstance(); try { return systemConfig.getStringProperty(systemConfig.getPackageVariableName(getName())) != null; } catch (SystemConfigException exception) { return false; } }
@Override public boolean isOn() { if (on == null) { on = SYSTEM_CONFIG.getBooleanProperty(SYSTEM_CONFIG.getPackageVariableName(propertyName), false); } return on; }
/** * Get a package scoped variable name. * * @param suffix The variable name of the configuration variable without the package prefix * @return variable name */ default String getPackageVariableName(String suffix) { return getStringProperty("package_name") + "__" + suffix; }
@Override public void reset() { SYSTEM_CONFIG.clearProperty(SYSTEM_CONFIG.getPackageVariableName(propertyName)); on = null; } }
/** * Return true if response status code indicates an error. * <p> * If etag cache is enabled, no error on 200 OK and 304 NOT-MODIFIED. * Otherwise, no error only on 200 OK. * * @param status The Status object that contains status code to be checked * * @return true if the status code indicates an error */ protected boolean hasError(Status status) { return CacheFeatureFlag.ETAG.isOn() ? status != Status.OK && status != Status.NOT_MODIFIED : status != Status.OK; }
/** * Constructor. * * @param client The Memcached client to support this cache */ public MemDataCache(MemcachedClient client) { // validate expiration value if (EXPIRATION > EXPIRATION_MAX_VALUE) { throw new SystemConfigException("memcached_expiration_seconds exceeds " + EXPIRATION_MAX_VALUE); } this.client = client; }
@Override public void setOn(Boolean newValue) { SYSTEM_CONFIG.setProperty(SYSTEM_CONFIG.getPackageVariableName(propertyName), newValue.toString()); on = newValue; }
/** * Set property value for a key. * * @param key The key of the property to change, not null * @param value The new value * * @throws SystemConfigException A system exception if any errors occurred */ default void setProperty(@NotNull String key, String value) throws SystemConfigException { resetProperty(key, value); }
/** * Register the feature flag. * * @param featureFlag FeatureFlag to register. */ public void add(FeatureFlag featureFlag) { NAMES_TO_VALUES.put(featureFlag.name() + "_ENABLED", featureFlag); }
/** * Get a package scoped variable name. * * @param suffix The variable name of the configuration variable without the package prefix * @return variable name */ default String getPackageVariableName(String suffix) { return getStringProperty("package_name") + "__" + suffix; }
@Override public void reset() { SYSTEM_CONFIG.clearProperty(SYSTEM_CONFIG.getPackageVariableName("query_response_caching_strategy")); on = null; } }
@Override public void setOn(Boolean newValue) { LOG.warn("setOn(Boolean) method does not apply in CacheFeatureFlag"); on = null; isOn(); }
/** * Remove property from the user-defined runtime configuration. * * @param key The key of the property to remove. */ default void clearProperty(@NotNull String key) { resetProperty(key, null); }
/** * Fetches the URL of the druid coordinator. * * @return druid coordinator URL */ public static String getDruidCoordUrl() { return SYSTEM_CONFIG.getStringProperty(DRUID_COORD_URL_KEY, null); }
/** * Set property value for a key. * * @param key The key of the property to change, not null * @param value The new value * * @throws SystemConfigException A system exception if any errors occurred */ default void setProperty(@NotNull String key, String value) throws SystemConfigException { resetProperty(key, value); }
/** * Get the output formatter for the system. * * @return the output formatter, pulling it from a configuration if we've not gotten it before. */ public static DateTimeFormatter getOutputFormatter() { if (DATETIME_OUTPUT_FORMATTER == null) { String formatString = SYSTEM_CONFIG.getStringProperty(OUTPUT_DATETIME_FORMAT, "yyyy-MM-dd' 'HH:mm:ss.SSS"); DATETIME_OUTPUT_FORMATTER = DateTimeFormat.forPattern(formatString); } return DATETIME_OUTPUT_FORMATTER; }
/** * Remove property from the user-defined runtime configuration. * * @param key The key of the property to remove. */ default void clearProperty(@NotNull String key) { resetProperty(key, null); }
/** * Fetches the druid Priority. * * @return druid priority */ public static Integer getDruidPriority() { String priority = SYSTEM_CONFIG.getStringProperty(DRUID_PRIORITY_KEY, "1"); return Integer.parseInt(priority); }
/** * Fetches the druid URL. * * @return druid URL */ public static String getDruidUrl() { String url = SYSTEM_CONFIG.getStringProperty(DRUID_BROKER_URL_KEY, null); validateUrl(url); return url; }