/** * Creates a new instance of a class specified in a configuration property. * * @param conf * configuration containing property * @param property * property specifying class name * @param base * base class of type * @param defaultInstance * instance to use if creation fails * @return new class instance, or default instance if creation failed * @see AccumuloVFSClassLoader */ public static <T> T createInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) { String clazzName = conf.get(property); return ConfigurationTypeHelper.getClassInstance(null, clazzName, base, defaultInstance); }
@Override public Long convert(String value) { return ConfigurationTypeHelper.getFixedMemoryAsBytes(value); } }
@Override public Long convert(String value) { return ConfigurationTypeHelper.getTimeInMillis(value); } }
/** * Gets a property of type {@link PropertyType#BYTES} or {@link PropertyType#MEMORY}, interpreting * the value properly. * * @param property * Property to get * @return property value * @throws IllegalArgumentException * if the property is of the wrong type */ public long getAsBytes(Property property) { String memString = get(property); if (property.getType() == PropertyType.MEMORY) { return ConfigurationTypeHelper.getMemoryAsBytes(memString); } else if (property.getType() == PropertyType.BYTES) { return ConfigurationTypeHelper.getFixedMemoryAsBytes(memString); } else { throw new IllegalArgumentException(property.getKey() + " is not of BYTES or MEMORY type"); } }
public Long getBytes(Properties properties) { String value = getValue(properties); if (value.isEmpty()) { return null; } checkState(getType() == PropertyType.BYTES, "Invalid type getting bytes. Type must be " + PropertyType.BYTES + ", not " + getType()); return ConfigurationTypeHelper.getMemoryAsBytes(value); }
/** * Gets a property of type {@link PropertyType#FRACTION}, interpreting the value properly. * * @param property * property to get * @return property value * @throws IllegalArgumentException * if the property is of the wrong type */ public double getFraction(Property property) { checkType(property, PropertyType.FRACTION); return ConfigurationTypeHelper.getFraction(get(property)); }
private SortedMap<KeyExtent,Bulk.Files> computeMappingFromFiles(FileSystem fs, Table.ID tableId, Path dirPath) throws IOException { Executor executor; ExecutorService service = null; if (this.executor != null) { executor = this.executor; } else if (numThreads > 0) { executor = service = Executors.newFixedThreadPool(numThreads); } else { String threads = context.getConfiguration().get(ClientProperty.BULK_LOAD_THREADS.getKey()); executor = service = Executors .newFixedThreadPool(ConfigurationTypeHelper.getNumThreads(threads)); } try { return computeFileToTabletMappings(fs, tableId, dirPath, executor, context); } finally { if (service != null) { service.shutdown(); } } }
@Override public int getZooKeepersSessionTimeOut() { return (int) ConfigurationTypeHelper .getTimeInMillis(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getValue(properties)); }
@Override public void init(Map<String,String> options) { limit = ConfigurationTypeHelper.getFixedMemoryAsBytes(options.get(SIZE_LIMIT_OPT)); }
/** * Loads a class in the given classloader context, suppressing any exceptions, and optionally * providing a default instance to use. * * @param context * the per-table context, can be null * @param clazzName * the name of the class to load * @param base * the type of the class * @param defaultInstance * a default instance if the class cannot be loaded * @return a new instance of the class, or the defaultInstance */ public static <T> T getClassInstance(String context, String clazzName, Class<T> base, T defaultInstance) { T instance = null; try { instance = getClassInstance(context, clazzName, base); } catch (RuntimeException | ClassNotFoundException | IOException | InstantiationException | IllegalAccessException e) { log.warn("Failed to load class {}", clazzName, e); } if (instance == null && defaultInstance != null) { log.info("Using default class {}", defaultInstance.getClass().getName()); instance = defaultInstance; } return instance; }
private static Long getDefaultTimeout() { Long def = ConfigurationTypeHelper.getTimeInMillis(BATCH_WRITER_TIMEOUT_MAX.getDefaultValue()); if (def.equals(0L)) return Long.MAX_VALUE; else return def; }
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { sourceIter = source; if (options.containsKey(MAX_BUFFER_SIZE_OPT)) { maxBufferSize = ConfigurationTypeHelper .getFixedMemoryAsBytes(options.get(MAX_BUFFER_SIZE_OPT)); } }
return ConfigurationTypeHelper.getClassInstance(context, className, VolumeChooser.class); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IOException e) {
protected long getTimeout(final CommandLine cl) { if (cl.hasOption(timeoutOption.getLongOpt())) { return ConfigurationTypeHelper.getTimeInMillis(cl.getOptionValue(timeoutOption.getLongOpt())); } return Long.MAX_VALUE; }
@Override public String convert(String str) { long size = ConfigurationTypeHelper.getFixedMemoryAsBytes(str); checkArgument(size > 0); return Long.toString(size); } }
private ExecutorService createPriorityExecutor(ScanExecutorConfig sec, Map<String,Queue<?>> scanExecQueues) { BlockingQueue<Runnable> queue; if (sec.prioritizerClass.orElse("").isEmpty()) { queue = new LinkedBlockingQueue<>(); } else { ScanPrioritizer factory = null; try { factory = ConfigurationTypeHelper.getClassInstance(null, sec.prioritizerClass.get(), ScanPrioritizer.class); } catch (Exception e) { throw new RuntimeException(e); } if (factory == null) { queue = new LinkedBlockingQueue<>(); } else { Comparator<ScanInfo> comparator = factory.createComparator(() -> sec.prioritizerOpts); // function to extract scan scan session from runnable Function<Runnable,ScanInfo> extractor = r -> ((ScanSession.ScanMeasurer) ((TraceRunnable) r) .getRunnable()).getScanInfo(); queue = new PriorityBlockingQueue<>(sec.maxThreads, Comparator.comparing(extractor, comparator)); } } scanExecQueues.put(sec.name, queue); return createEs(() -> sec.getCurrentMaxThreads(), "scan-" + sec.name, queue, sec.priority); }
protected long getTimeout(final CommandLine cl) { if (cl.hasOption(timeoutOption.getLongOpt())) { return ConfigurationTypeHelper.getTimeInMillis(cl.getOptionValue(timeoutOption.getLongOpt())); } return Long.MAX_VALUE; }
@Override public boolean validateOptions(Map<String,String> options) { String maxBufferSizeStr = options.get(MAX_BUFFER_SIZE_OPT); try { ConfigurationTypeHelper.getFixedMemoryAsBytes(maxBufferSizeStr); } catch (Exception e) { throw new IllegalArgumentException( "Failed to parse opt " + MAX_BUFFER_SIZE_OPT + " " + maxBufferSizeStr, e); } return true; }
/** * Creates a new instance of a class specified in a configuration property. The table classpath * context is used if set. * * @param conf * configuration containing property * @param property * property specifying class name * @param base * base class of type * @param defaultInstance * instance to use if creation fails * @return new class instance, or default instance if creation failed * @see AccumuloVFSClassLoader */ public static <T> T createTableInstanceFromPropertyName(AccumuloConfiguration conf, Property property, Class<T> base, T defaultInstance) { String clazzName = conf.get(property); String context = conf.get(TABLE_CLASSPATH); return ConfigurationTypeHelper.getClassInstance(context, clazzName, base, defaultInstance); }
protected long getTimeout(final CommandLine cl) { if (cl.hasOption(timeoutOption.getLongOpt())) { return ConfigurationTypeHelper.getTimeInMillis(cl.getOptionValue(timeoutOption.getLongOpt())); } return Long.MAX_VALUE; }