@Override public SharedResource getSharedResource(final String name) { final SharedResource result = sharedResources.get(name); if (result == null) { throw new ConfigurationException("Shared resource \"" + name + "\" not found"); } return result; }
public static void notNull(final Object xbean, final String name, final Object value) { if (value == null) { throw new ConfigurationException("Element \"" + name + "\" of " + determineBeanName(xbean) + " is mandatory"); } }
public static void validPattern(final Object xbean, final String name, final String value) { if (value != null) { try { Pattern.compile(value); } catch (final PatternSyntaxException e) { throw new ConfigurationException("Value \"" + value + "\" of attribute \"" + name + "\" of " + determineBeanName(xbean) + " must be a valid regular expression but compiling it failed with error: " + e.getMessage(), e); } } } }
public static void notEmpty(final Object xbean, final String name, final String value) { if (value == null || value.equals("")) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " is mandatory"); } }
public static void validPort(final Object xbean, final String name, final Integer value) { if (value == null) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " is mandatory"); } if (value < 1 || value > 65535) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " with value " + value + " is not a valid port in range [1,65535]"); } }
public static void notEmpty(final Object xbean, final String name, final Collection<?> value) { if (value == null || value.isEmpty()) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " is mandatory"); } }
public static void notNegative(final Object xbean, final String name, final Integer value) { if (value == null) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " is mandatory"); } if (value < 0) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " with value " + value + " is not a valid number greater than or equal to 0"); } }
public static void validPattern(final Object xbean, final String name, final String value) { if (value != null) { try { Pattern.compile(value); } catch (final PatternSyntaxException e) { throw new ConfigurationException("Value \"" + value + "\" of attribute \"" + name + "\" of " + determineBeanName(xbean) + " must be a valid regular expression but compiling it failed with error: " + e.getMessage(), e); } } } }
public static void notNegativeOptional(final Object xbean, final String name, final Integer value) { if (value != null) { if (value < 0) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " with value " + value + " is not a valid number greater than or equal to 0"); } } }
protected URL parseUrl() { try { return new URL(getUrl()); } catch (final MalformedURLException e) { throw new ConfigurationException("Invalid URL: " + e.getMessage()); } } }
protected HttpGet setupGetRequest(final String path) { try { final HttpGet result = new HttpGet(config.getUrl().toURI() + path); for (final Map.Entry<String, String> header : config.getHeaders().entrySet()) { result.setHeader(header.getKey(), header.getValue()); } return result; } catch (final URISyntaxException e) { throw new ConfigurationException("Failed to convert URL to URI", e); } }
protected void validate() { if ((fromName == null || fromName.equals("")) && (fromDescription == null || fromDescription.equals(""))) { throw new ConfigurationException("Either from-name or from-description must be set for regexp selector"); } notEmpty(this, "to-name", getToName()); } @Override
public static void validUrl(final Object xbean, final String name, final String value) { notEmpty(xbean, name, value); try { new URL(value); } catch (final MalformedURLException e) { throw new ConfigurationException("Attribute \"" + name + "\" of " + determineBeanName(xbean) + " is not a valid URL: " + e.getMessage()); } }
protected InputConfig configureInput(final Map<String, InputConfig> inputs) { final InputConfig result = inputs.get(getInput()); if (result == null) { throw new ConfigurationException("Input named \"" + getInput() + "\" not found"); } return result; }
@Override public MetricsWriter newWriterForOutput(final OutputConfig config) { for (final LocalObjectFactory factory : objectFactories) { if (factory.supportsOutput(config)) { return factory.newWriterForOutput(config); } } throw new ConfigurationException("Unsupported output: " + config); }
@Override public ValueTransformer newValueTransformer(final ValueTransformerConfig config) { for (final LocalObjectFactory factory : objectFactories) { if (factory.supportsValueTransformer(config)) { return factory.newValueTransformer(config); } } throw new ConfigurationException("Unsupported value transformer: " + config); }
public List<SelectorConfig> toConfig(final Map<String, List<SelectorConfig>> selectorGroups) { validate(); final List<SelectorConfig> result = selectorGroups.get(getName()); if (result == null) { throw new ConfigurationException("Selector group named \"" + getName() +"\" not found"); } return result; }
protected Configuration load(final String filename) { checkArgumentNotNullNorEmpty(filename, "filename"); final File file = new File(filename); final XStream xstream = createXStream(); try { final ConfigurationXBean result = loadFile(file, xstream); applyPostProcessing(result); return result.toConfig(); } catch (final XStreamException | IOException e) { throw new ConfigurationException("Failed to load configuration from \"" + file.getAbsolutePath() + "\"", e); } }
private static <T extends TemplatableXBean> void addDependency(final T item, final LinkedHashMap<String, T> result, final Map<String, T> map) { if (!result.containsKey(item.getName())) { if (item.hasParent()) { final T parent = map.get(item.getParent()); if (parent == null) { throw new ConfigurationException("Template named \"" + item.getParent() + "\" not found"); } addDependency(parent, result, map); } result.put(item.getName(), item); } }
@Override protected MetricsReader doNewReader(final InputConfig config) { final JdbcInputConfig jdbcConfig = (JdbcInputConfig) config; final SharedResource sharedResource = getGlobalFactory().getSharedResource(jdbcConfig.getPool()); if (sharedResource instanceof JdbcConnectionPool) { return new JdbcMetricsReader(jdbcConfig, (JdbcConnectionPool) sharedResource); } else { throw new ConfigurationException(jdbcConfig.getPool() + " is not a JDBC connection pool: " + sharedResource); } }