private static int getTransactionRetries(Configuration configuration) { String retries = configuration.getProperty(BaseInventory.TRANSACTION_RETRIES, "10"); return Integer.parseInt(retries); }
public boolean getFlag(Property property, String defaultValue) { return Boolean.valueOf(getProperty(property, defaultValue)); }
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; }