@SuppressWarnings("unchecked") private static <K extends WritableComparable<?>, V extends Writable> Class<? extends SortedKeyValueIterator<K, V>> loadClass( boolean useAccumuloClassLoader, String context, IterInfo iterInfo) throws ClassNotFoundException, IOException { Class<? extends SortedKeyValueIterator<K, V>> clazz; if (useAccumuloClassLoader) { if (context != null && !context.equals("")) { clazz = (Class<? extends SortedKeyValueIterator<K, V>>) AccumuloVFSClassLoader.getContextManager() .loadClass(context, iterInfo.className, SortedKeyValueIterator.class); log.trace( "Iterator class {} loaded from context {}, classloader: {}", iterInfo.className, context, clazz.getClassLoader()); } else { clazz = (Class<? extends SortedKeyValueIterator<K, V>>) AccumuloVFSClassLoader.loadClass(iterInfo.className, SortedKeyValueIterator.class); log.trace( "Iterator class {} loaded from AccumuloVFSClassLoader: {}", iterInfo.className, clazz.getClassLoader()); } } else { clazz = (Class<? extends SortedKeyValueIterator<K, V>>) Class.forName(iterInfo.className).asSubclass(SortedKeyValueIterator.class); log.trace("Iterator class {} loaded from classpath", iterInfo.className); } return clazz; }
public <T> T instantiateClassProperty(Property property, Class<T> base, T defaultInstance) { String clazzName = get(property); T instance = null; try { Class<? extends T> clazz = AccumuloVFSClassLoader.loadClass(clazzName, base); instance = clazz.newInstance(); log.info("Loaded class : " + clazzName); } catch (Exception e) { log.warn("Failed to load class ", e); } if (instance == null) { log.info("Using " + defaultInstance.getClass().getName()); instance = defaultInstance; } return instance; }