/** * 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; }
/** * Get the Druid response timeout value for the given system property. * * @param timeOutSysProp The system property to read the timeout from * * @return the timeout */ private static Integer fetchDruidResponseTimeOut(String timeOutSysProp) { try { return SYSTEM_CONFIG.getIntProperty(timeOutSysProp, DRUID_REQUEST_TIMEOUT_DEFAULT); } catch (SystemConfigException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } }
/** * Creates cache hashing with provided algorithm. * * @param cache provided underlying cache * @param algorithm provided MessageDigest hash algorithm */ private HashDataCache(DataCache<Pair<String, T>> cache, String algorithm) { this.cache = cache; this.algorithm = algorithm; try { // verify algorithm availability at construction MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { String msg = "Unable to get hash generator with algorithm: " + algorithm; LOG.warn(msg, e); throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default int getIntProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getInt(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key, false if null * * @throws SystemConfigException A system exception if any errors occurred */ default boolean getBooleanProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getBoolean(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default String getStringProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getString(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default String getStringProperty(@NotNull String key, String defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getString(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default String getStringProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getString(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default int getIntProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getInt(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return requestedPropertyValue The value for the requested key, false if null * * @throws SystemConfigException A system exception if any errors occurred */ default boolean getBooleanProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getBoolean(key); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default boolean getBooleanProperty(@NotNull String key, boolean defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getBoolean(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default int getIntProperty(@NotNull String key, int defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getInt(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default boolean getBooleanProperty(@NotNull String key, boolean defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getBoolean(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default String getStringProperty(@NotNull String key, String defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getString(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * @param defaultValue The value to return if there is no configured value * * @return requestedPropertyValue The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default int getIntProperty(@NotNull String key, int defaultValue) throws SystemConfigException { try { return getMasterConfiguration().getInt(key, defaultValue); } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Remove property from the user-defined runtime configuration. * If value is null, clear the property, otherwise set property to value. * * @param key The key of the property to remove. * @param value The value to reset to (if not null) */ default void resetProperty(@NotNull String key, String value) { try { if (value == null) { getRuntimeProperties().remove(key); } else { getRuntimeProperties().setProperty(key, value); } } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Build a configuration object from a resource, processing it as a properties file. * * @param resource The resource referring to a properties file * * @return a Configuration object containing a properties configuration */ public Configuration loadConfigFromResource(Resource resource) { PropertiesConfiguration result = new PropertiesConfiguration(); try { result.load(resource.getInputStream()); return result; } catch (ConfigurationException | IOException e) { String message = CONFIGURATION_LOAD_ERROR.format(resource.getFilename()); LOG.error(message, e); throw new SystemConfigException(message, e); } }
/** * Build a configuration object from a resource, processing it as a properties file. * * @param resource The resource referring to a properties file * * @return a Configuration object containing a properties configuration */ public Configuration loadConfigFromResource(Resource resource) { PropertiesConfiguration result = new PropertiesConfiguration(); try { result.load(resource.getInputStream()); return result; } catch (ConfigurationException | IOException e) { String message = CONFIGURATION_LOAD_ERROR.format(resource.getFilename()); LOG.error(message, e); throw new SystemConfigException(message, e); } }
/** * Remove property from the user-defined runtime configuration. * If value is null, clear the property, otherwise set property to value. * * @param key The key of the property to remove. * @param value The value to reset to (if not null) */ default void resetProperty(@NotNull String key, String value) { try { if (value == null) { getRuntimeProperties().remove(key); } else { getRuntimeProperties().setProperty(key, value); } } catch (Exception e) { throw new SystemConfigException(e); } }
/** * Get property value for a key. * * @param key The key for which value needs to be fetched, not null * * @return The value for the requested key * * @throws SystemConfigException A system exception if any errors occurred */ default float getFloatProperty(@NotNull String key) throws SystemConfigException { try { return getMasterConfiguration().getFloat(key); } catch (Exception e) { throw new SystemConfigException(e); } }