public static LedgerStorage createLedgerStorage(String name) throws IOException { try { return ReflectionUtils.newInstance(name, LedgerStorage.class); } catch (Throwable t) { throw new IOException("Failed to instantiate ledger storage : " + name, t); } } }
/** * Get ledger manager factory class. * * @return ledger manager factory class */ public Class<? extends LedgerManagerFactory> getLedgerManagerFactoryClass() throws ConfigurationException { return ReflectionUtils.getClass(this, LEDGER_MANAGER_FACTORY_CLASS, null, LedgerManagerFactory.class, DEFAULT_LOADER); }
public static SecurityHandlerFactory getSecurityProviderFactory(String securityHandler) throws SecurityException { if ((securityHandler == null) || (securityHandler.equals(""))) { return null; } SecurityHandlerFactory shFactory; try { Class<? extends SecurityHandlerFactory> shFactoryClass = ReflectionUtils.forName(securityHandler, SecurityHandlerFactory.class); shFactory = ReflectionUtils.newInstance(shFactoryClass); LOG.info("Loaded security handler for {}", securityHandler); } catch (RuntimeException re) { LOG.error("Unable to load security handler for {}: ", securityHandler, re.getCause()); throw new SecurityException(re.getCause()); } return shFactory; }
public static List<ServerLifecycleComponent> loadServerComponents(String[] componentClassNames, BookieConfiguration conf, StatsLogger statsLogger) { List<Class<? extends ServerLifecycleComponent>> componentClasses = Lists.newArrayListWithExpectedSize(componentClassNames.length); for (String componentClsName : componentClassNames) { componentClasses.add(ReflectionUtils.forName(componentClsName, ServerLifecycleComponent.class)); } return Lists.transform(componentClasses, cls -> newComponent(cls, conf, statsLogger)); }
@Override public boolean validate(String name, Object value) { if (value instanceof String) { try { ReflectionUtils.forName((String) value, interfaceClass); return true; } catch (RuntimeException re) { log.warn("Setting value of '{}' is not '{}' : {}", name, interfaceClass.getName(), value, re); return false; } } else if (value instanceof Class) { Class cls = (Class) value; if (!interfaceClass.isAssignableFrom(cls)) { log.warn("Setting value of '{}' is not '{}' : {}", name, interfaceClass.getName(), cls.getName()); return false; } else { return true; } } else { return false; } }
public static MetaStore createMetaStore(String name) throws MetastoreException { try { return ReflectionUtils.newInstance(name, MetaStore.class); } catch (Throwable t) { throw new MetastoreException("Failed to instantiate metastore : " + name); } }
/** * Get Ensemble Placement Policy Class. * * @return ensemble placement policy class. */ public Class<? extends EnsemblePlacementPolicy> getEnsemblePlacementPolicy() throws ConfigurationException { return ReflectionUtils.getClass(this, ENSEMBLE_PLACEMENT_POLICY, RackawareEnsemblePlacementPolicy.class, EnsemblePlacementPolicy.class, DEFAULT_LOADER); }
/** * Create an object using the given class name. * * @param clsName * class name of which an object is created. * @param xface * The interface implemented by the named class. * @return a new object */ @SuppressWarnings("unchecked") public static <T> T newInstance(String clsName, Class<T> xface) { Class<?> theCls; try { theCls = Class.forName(clsName); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } if (!xface.isAssignableFrom(theCls)) { throw new RuntimeException(clsName + " not " + xface.getName()); } return newInstance(theCls.asSubclass(xface)); } }
/** * Get ledger id formatter class. * * @return LedgerIdFormatter class */ public Class<? extends LedgerIdFormatter> getLedgerIdFormatterClass() throws ConfigurationException { return ReflectionUtils.getClass(this, LEDGERID_FORMATTER_CLASS, DEFAULT_LEDGERID_FORMATTER, LedgerIdFormatter.class, DEFAULT_LOADER); }
/** * Retrieve the client driver for {@code scheme}. * * @param scheme the scheme for the metadata client driver * @return the metadata client driver * @throws NullPointerException when scheme is null */ public static MetadataClientDriver getClientDriver(String scheme) { checkNotNull(scheme, "Client Driver Scheme is null"); if (!initialized) { initialize(); } MetadataClientDriverInfo driverInfo = clientDrivers.get(scheme.toLowerCase()); if (null == driverInfo) { throw new IllegalArgumentException("Unknown backend " + scheme); } return ReflectionUtils.newInstance(driverInfo.driverClass); }
/** * Get entry formatter class. * * @return EntryFormatter class */ public Class<? extends EntryFormatter> getEntryFormatterClass() throws ConfigurationException { return ReflectionUtils.getClass(this, ENTRY_FORMATTER_CLASS, DEFAULT_ENTRY_FORMATTER, EntryFormatter.class, DEFAULT_LOADER); }
/** * Retrieve the namespace driver for {@code scheme}. * * @param scheme the scheme for the namespace driver * @return the namespace driver * @throws NullPointerException when scheme is null */ public static NamespaceDriver getDriver(String scheme) { checkNotNull(scheme, "Driver Scheme is null"); if (!initialized) { initialize(); } NamespaceDriverInfo driverInfo = drivers.get(scheme.toLowerCase()); if (null == driverInfo) { throw new IllegalArgumentException("Unknown backend " + scheme); } return ReflectionUtils.newInstance(driverInfo.driverClass); }
/** * Get the stats provider used by bookie. * * @return stats provider class * @throws ConfigurationException */ public Class<? extends StatsProvider> getStatsProviderClass() throws ConfigurationException { return ReflectionUtils.getClass(this, STATS_PROVIDER_CLASS, NullStatsProvider.class, StatsProvider.class, DEFAULT_LOADER); }
/** * Retrieve the bookie driver for {@code scheme}. * * @param scheme the scheme for the metadata bookie driver * @return the metadata bookie driver * @throws NullPointerException when scheme is null */ public static MetadataBookieDriver getBookieDriver(String scheme) { checkNotNull(scheme, "Bookie Driver Scheme is null"); if (!initialized) { initialize(); } MetadataBookieDriverInfo driverInfo = bookieDrivers.get(scheme.toLowerCase()); if (null == driverInfo) { throw new IllegalArgumentException("Unknown backend " + scheme); } return ReflectionUtils.newInstance(driverInfo.driverClass); }
/** * Get feature provider class. * * @return feature provider class. * @throws ConfigurationException */ public Class<? extends FeatureProvider> getFeatureProviderClass() throws ConfigurationException { return ReflectionUtils.getClass(this, BKDL_FEATURE_PROVIDER_CLASS, DefaultFeatureProvider.class, FeatureProvider.class, FeatureProvider.class.getClassLoader()); }
public static LedgerIdFormatter newLedgerIdFormatter(AbstractConfiguration<?> conf) { LedgerIdFormatter formatter; try { Class<? extends LedgerIdFormatter> ledgerIdFormatterClass = conf.getLedgerIdFormatterClass(); formatter = ReflectionUtils.newInstance(ledgerIdFormatterClass); } catch (Exception e) { LOG.warn("No formatter class found", e); LOG.warn("Using Default Long Formatter."); formatter = new LongLedgerIdFormatter(); } return formatter; }
/** * Get Registration Manager Class. * * @return registration manager class. * @deprecated since 4.7.0, in favor of using {@link #getMetadataServiceUri()} */ @Deprecated public Class<? extends RegistrationManager> getRegistrationManagerClass() throws ConfigurationException { return ReflectionUtils.getClass(this, REGISTRATION_MANAGER_CLASS, ZKRegistrationManager.class, RegistrationManager.class, DEFAULT_LOADER); }
public static EntryFormatter newEntryFormatter(AbstractConfiguration<?> conf) { EntryFormatter formatter; try { Class<? extends EntryFormatter> entryFormatterClass = conf.getEntryFormatterClass(); formatter = ReflectionUtils.newInstance(entryFormatterClass); } catch (Exception e) { LOG.warn("No formatter class found", e); LOG.warn("Using Default String Formatter."); formatter = new StringEntryFormatter(); } return formatter; }
/** * Get Registration Client Class. * * @return registration manager class. * @deprecated since 4.7.0 */ @Deprecated public Class<? extends RegistrationClient> getRegistrationClientClass() throws ConfigurationException { return ReflectionUtils.getClass(this, REGISTRATION_CLIENT_CLASS, ZKRegistrationClient.class, RegistrationClient.class, DEFAULT_LOADER); }
public static void main(String args[]) { int rc = -1; if (args.length <= 0) { System.err.println("No tool to run."); System.err.println(""); System.err.println("Usage : Tool <tool_class_name> <options>"); System.exit(-1); } String toolClass = args[0]; try { Tool tool = ReflectionUtils.newInstance(toolClass, Tool.class); String[] newArgs = new String[args.length - 1]; System.arraycopy(args, 1, newArgs, 0, newArgs.length); rc = tool.run(newArgs); } catch (Throwable t) { System.err.println("Fail to run tool " + toolClass + " : "); t.printStackTrace(); } System.exit(rc); } }