private static int getTransactionRetries(Configuration configuration) { String retries = configuration.getProperty(BaseInventory.TRANSACTION_RETRIES, "10"); return Integer.parseInt(retries); }
public Configuration build() { return new Configuration(strategy, resultFilter, configuration); } }
/** * Returns the implementation configuration with the values changed to conform the provided properties. * <p> * I.e. if a system property defined by some of the provided property objects overrides a property in the * implementation configuration, the value of the system property is used instead for that property (i.e. the key * stays the same but the value gets overridden to the value of the system property). * <p> * Additionally, if some of the {@code overridableProperties} are not present in this configuration, an attempt is * made to load them from the system properties or environment variables according to the rules specified at * {@link #getProperty(Property, String)}. * * @param overridableProperties the properties to override the implementation configuration with. * @return an overridden implementation configuration */ public Map<String, String> getImplementationConfiguration(Collection<? extends Property> overridableProperties) { return getOverriddenImplementationConfiguration(overridableProperties); }
/** * If the inventory configuration provided a {@link ResultFilter}, this calls it to tell whether provided element * is applicable. If the result filter is not provided by the configuration, true will always be returned. * * @param result the potential result to be checked for applicability in the result set * @return true or false (!!!) */ protected boolean isApplicable(AbstractElement<?, ?> result) { ResultFilter filter = context.configuration.getResultFilter(); return filter == null || filter.isApplicable(result); }
public boolean getFlag(String key, String defaultValue) { return getFlag(Property.builder().withPropertyNameAndSystemProperty(key).build(), defaultValue); }
Configuration cfg = Configuration.builder() .withFeedIdStrategy(new AcceptWithFallbackFeedIdStrategy(new RandomUUIDFeedIdStrategy()))
@Override protected String getProposedId(Transaction<BE> tx, Feed.Blueprint blueprint) { BE tenant = tx.querySingle(context.sourcePath.extend().filter() .with(type(Tenant.class)).get()); if (tenant == null) { throw new EntityNotFoundException(Tenant.class, Query.filters(context.sourcePath)); } CanonicalPath feedPath = tx.extractCanonicalPath(tenant) .extend(Feed.SEGMENT_TYPE, blueprint.getId()).get(); return context.configuration.getFeedIdStrategy().generate(context.inventory.keepTransaction(tx), new Feed(feedPath, null, null, null)); }
(e) -> new Pair<>(e, tx.convert(e, context.entityClass)); Function<Pair<BE, E>, Boolean> filter = context.configuration.getResultFilter() == null ? null : (p) -> context.configuration.getResultFilter().isApplicable(p.second);
public boolean getFlag(Property property, String defaultValue) { return Boolean.valueOf(getProperty(property, defaultValue)); }
/** * Filters out all the configuration entries whose keys don't start with any of the white-listed prefixes * * @param prefixes * @return */ public Configuration prefixedWith(String... prefixes) { if (prefixes == null || prefixes.length == 0) { return this; } Map<String, String> filteredConfig = implementationConfiguration.entrySet().stream() .filter(e -> Arrays.stream(prefixes).anyMatch(p -> e.getKey() .startsWith(p))).collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); return new Configuration(feedIdStrategy, resultFilter, filteredConfig); }
private GraphProvider instantiateGraphProvider(Configuration config) { String implClass = config.getProperty(GRAPH_PROVIDER_IMPL_CLASS, null); if (implClass != null) { try { return (GraphProvider) Class.forName(implClass).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalStateException("Could not instantiate graph provider class '" + implClass + "'.", e); } } else { return ServiceLoader.load(GraphProvider.class).iterator().next(); } } }
private Inventory instantiateNew(Configuration config) { String implClass = config.getProperty(IMPL_PROPERTY, null); if (implClass != null) { try { return (Inventory) Class.forName(implClass).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalStateException("Failed to instantiate inventory using class '" + implClass + "'.", e); } } else { return ServiceLoader.load(Inventory.class).iterator().next(); } } }
private <T extends Property> Map<String, String> getOverriddenImplementationConfiguration( Collection<T> overridableProperties) { Map<String, String> ret = new HashMap<>(); overridableProperties.forEach(p -> { String val = getProperty(p, null); if (val != null) { ret.put(p.getPropertyName(), val); } }); implementationConfiguration.forEach(ret::putIfAbsent); return ret; }