protected T createInstance(String className) throws ClassNotFoundException { @SuppressWarnings("unchecked") Class<T> clz = (Class<T>) Class.forName(className); return Instances.newInstance(clz); }
/** * Creates a new instance of the given class. It will use the default constructor if it is presents. * Otherwise it will try to use {@link sun.misc.Unsafe#allocateInstance(Class)} to create the instance. * @param clz Class of object to be instantiated. * @param <T> Type of the class * @return An instance of type {@code <T>} */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clz) { try { try { Constructor<T> cons = clz.getDeclaredConstructor(); if (!cons.isAccessible()) { cons.setAccessible(true); } return cons.newInstance(); } catch (Exception e) { // Try to use Unsafe Preconditions.checkState(UNSAFE != null, "Fail to instantiate with Unsafe."); return unsafeCreate(clz); } } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Creates a new instance of the given class. It will use the default constructor if it is presents. * Otherwise it will try to use {@link sun.misc.Unsafe#allocateInstance(Class)} to create the instance. * @param clz Class of object to be instantiated. * @param <T> Type of the class * @return An instance of type {@code <T>} */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clz) { try { try { Constructor<T> cons = clz.getDeclaredConstructor(); if (!cons.isAccessible()) { cons.setAccessible(true); } return cons.newInstance(); } catch (Exception e) { // Try to use Unsafe Preconditions.checkState(UNSAFE != null, "Fail to instantiate with Unsafe."); return unsafeCreate(clz); } } catch (Exception e) { throw Throwables.propagate(e); } }
protected T createInstance(String className) throws ClassNotFoundException { Class clz = Class.forName(className); return (T) Instances.newInstance(clz); }
protected T createInstance(String className) throws ClassNotFoundException { Class clz = Class.forName(className); return (T) Instances.newInstance(clz); }
protected T createInstance(String className) throws ClassNotFoundException { @SuppressWarnings("unchecked") Class<T> clz = (Class<T>) Class.forName(className); return Instances.newInstance(clz); }
protected T createInstance(String className) throws ClassNotFoundException { Class clz = Class.forName(className); return (T) Instances.newInstance(clz); }
TransactionPruningPlugin instance = Instances.newInstance(clazz); instance.initialize(conf); LOG.debug("Plugin {} initialized", plugin);
@SuppressWarnings("unchecked") @Override protected void doStart() throws Exception { for (Map.Entry<String, String> entry : containerLiveNodeData.getLogLevels().entrySet()) { String loggerName = entry.getKey(); String oldLogLevel = setLogLevel(loggerName, entry.getValue()); if (!defaultLogLevels.containsKey(loggerName)) { oldLogLevels.put(loggerName, oldLogLevel); } } commandExecutor = Executors.newSingleThreadExecutor( Threads.createDaemonThreadFactory("runnable-command-executor")); Class<?> runnableClass = classLoader.loadClass(specification.getClassName()); Preconditions.checkArgument(TwillRunnable.class.isAssignableFrom(runnableClass), "Class %s is not instance of TwillRunnable.", specification.getClassName()); runnable = Instances.newInstance((Class<TwillRunnable>) runnableClass); runnable.initialize(context); }
@SuppressWarnings("unchecked") @Override protected void doStart() throws Exception { for (Map.Entry<String, String> entry : containerLiveNodeData.getLogLevels().entrySet()) { String loggerName = entry.getKey(); String oldLogLevel = setLogLevel(loggerName, entry.getValue()); if (!defaultLogLevels.containsKey(loggerName)) { oldLogLevels.put(loggerName, oldLogLevel); } } commandExecutor = Executors.newSingleThreadExecutor( Threads.createDaemonThreadFactory("runnable-command-executor")); Class<?> runnableClass = classLoader.loadClass(specification.getClassName()); Preconditions.checkArgument(TwillRunnable.class.isAssignableFrom(runnableClass), "Class %s is not instance of TwillRunnable.", specification.getClassName()); runnable = Instances.newInstance((Class<TwillRunnable>) runnableClass); runnable.initialize(context); }
"Class {} does not implements {}", handlerClass, EventHandler.class.getName()); final EventHandler delegate = Instances.newInstance((Class<? extends EventHandler>) handlerClass);
"Class {} does not implements {}", handlerClass, EventHandler.class.getName()); final EventHandler delegate = Instances.newInstance((Class<? extends EventHandler>) handlerClass);