/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input; * in particular setAccessible allows private constructors to be used (not the default) */ public static <T> Maybe<T> invokeConstructorFromArgs(Class<? extends T> clazz, Object[] argsArray, boolean setAccessible) { Reflections reflections = new Reflections(clazz.getClassLoader()); return invokeConstructorFromArgs(reflections, clazz, argsArray, setAccessible); }
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input; * in particular setAccessible allows private constructors to be used (not the default) */ public static <T> Maybe<T> invokeConstructorFromArgs(ClassLoader classLoader, Class<T> clazz, Object[] argsArray, boolean setAccessible) { Reflections reflections = new Reflections(classLoader); return invokeConstructorFromArgs(reflections, clazz, argsArray, setAccessible); }
/** As {@link #invokeConstructorFromArgs(Class, Object...)} but will use private constructors (with setAccessible = true) */ public static <T> Maybe<T> invokeConstructorFromArgsIncludingPrivate(Class<? extends T> clazz, Object ...argsArray) { return Reflections.invokeConstructorFromArgs(new Reflections(clazz.getClassLoader()), clazz, argsArray, true); } /** As {@link #invokeConstructorFromArgs(Class, Object...)} but allowing more configurable input;
/** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */ public static <T> Maybe<T> invokeConstructorFromArgsUntyped(ClassLoader classLoader, String className, Object...argsArray) { Reflections reflections = new Reflections(classLoader); @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>)reflections.loadClass(className); return invokeConstructorFromArgs(reflections, clazz, argsArray, false); }
/** @deprecated since 0.11.0, use {@link org.apache.brooklyn.util.core.ClassLoaderUtils} in a combination with {@link #invokeConstructorFromArgs(Class, Object...)} instead */ @SuppressWarnings("unchecked") public static <T> Maybe<T> invokeConstructorFromArgs(ClassLoader classLoader, Class<T> optionalSupertype, String className, Object...argsArray) { Reflections reflections = new Reflections(classLoader); Class<?> clazz = reflections.loadClass(className); if (optionalSupertype!=null && !optionalSupertype.isAssignableFrom(clazz)) { return Maybe.absent("The type requested '"+className+"' is not assignable to "+optionalSupertype); } return invokeConstructorFromArgs(reflections, (Class<T>)clazz, argsArray, false); }
public RebindIteration(RebindManagerImpl rebindManager, ManagementNodeState mode, ClassLoader classLoader, RebindExceptionHandler exceptionHandler, Semaphore rebindActive, AtomicInteger readOnlyRebindCount, PersistenceActivityMetrics rebindMetrics, BrooklynMementoPersister persistenceStoreAccess ) { // NB: there is no particularly deep meaning in what is passed in vs what is looked up from the RebindManager which calls us // (this is simply a refactoring of previous code to a new class) this.rebindManager = rebindManager; this.mode = mode; this.classLoader = checkNotNull(classLoader, "classLoader"); this.exceptionHandler = checkNotNull(exceptionHandler, "exceptionHandler"); this.rebindActive = rebindActive; this.readOnlyRebindCount = readOnlyRebindCount; this.rebindMetrics = rebindMetrics; this.persistenceStoreAccess = persistenceStoreAccess; managementContext = rebindManager.getManagementContext(); rebindContext = new RebindContextImpl(managementContext, exceptionHandler, classLoader); reflections = new Reflections(classLoader).applyClassRenames(DeserializingClassRenamesProvider.INSTANCE.loadDeserializingMapping()); instantiator = new BrooklynObjectInstantiator(classLoader, rebindContext, reflections); if (mode==ManagementNodeState.HOT_STANDBY || mode==ManagementNodeState.HOT_BACKUP) { rebindContext.setAllReadOnly(); } else { Preconditions.checkState(mode==ManagementNodeState.MASTER, "Must be either master or read only to rebind (mode "+mode+")"); } }
Reflections reflections = new Reflections(CatalogOsgiVersionMoreEntityRebindTest.class.getClassLoader()); Class<? extends Location> locationClazz = (Class<? extends Location>) new ClassLoaderUtils(reflections.getClassLoader(), mgmt()).loadClass(locationTypeWithBundlePrefix); Location loc = mgmt().getLocationManager().createLocation(LocationSpec.create(locationClazz));