public static Class get(String clazzname) throws ClassNotFoundException { return Util.loadClass(clazzname, ClassConfigurator.class); }
/** * Tries to load the class from the current thread's context class loader. If * not successful, tries to load the class from the current instance. * @param classname Desired class. * @param clazz Class object used to obtain a class loader * if no context class loader is available. * @return Class, or null on failure. */ public static Class loadClass(String classname,Class clazz) throws ClassNotFoundException { return loadClass(classname, clazz != null? clazz.getClassLoader() : null); }
protected static Constructor<? extends Log> findConstructor(String classname, Class<?> arg) throws Exception { Class<?> clazz=Util.loadClass(classname, (Class<?>)null); @SuppressWarnings("unchecked") Constructor<? extends Log> constructor = (Constructor<? extends Log>)clazz.getDeclaredConstructor(arg); return constructor; } }
/** * Loads and returns the class from the class name * * @param clazzname a fully classified class name to be loaded * @return a Class object that represents a class that implements java.io.Externalizable */ public static Class get(String clazzname, ClassLoader loader) throws ClassNotFoundException { return Util.loadClass(clazzname, loader != null? loader : ClassConfigurator.class.getClassLoader()); }
protected static RtTransport create(String transport) throws Exception { String clazzname=TRANSPORTS.get(transport); Class<?> clazz=Util.loadClass(clazzname != null? clazzname : transport, RoundTrip.class); return (RtTransport)clazz.newInstance(); }
protected static InetAddress getAddressByCustomCode(String value) throws Exception { Class<Supplier<InetAddress>> clazz=(Class<Supplier<InetAddress>>)Util.loadClass(value, (ClassLoader)null); Supplier<InetAddress> supplier=clazz.newInstance(); return supplier.get(); }
protected static void callAfterCreationHook(Protocol prot, String classname) throws Exception { if(classname == null || prot == null) return; Class<ProtocolHook> clazz=Util.loadClass(classname, prot.getClass()); ProtocolHook hook=clazz.newInstance(); hook.afterCreation(prot); }
@Property(description="The fully qualified name of a class implementing MembershipChangePolicy.") public void setMembershipChangePolicy(String classname) { try { membership_change_policy=(MembershipChangePolicy)Util.loadClass(classname, getClass()).newInstance(); } catch(Throwable e) { throw new IllegalArgumentException("membership_change_policy could not be created", e); } }
public CustomRejectionPolicy(String rejection_policy) { if (!rejection_policy.toLowerCase().startsWith("custom=")) { throw new IllegalStateException(rejection_policy); } String className = rejection_policy.substring(7); try { Class<?> policyClass = Util.loadClass(className, Util.class); Object policy = policyClass.newInstance(); if (!(policy instanceof RejectedExecutionHandler)) { throw new IllegalArgumentException(className + " does not implement RejectedExecutionHandler"); } else { custom = (RejectedExecutionHandler) policy; } } catch (Throwable e) { throw new RuntimeException("Cannot instantiate rejection policy '" + rejection_policy + "'", e); } }
protected void parseRule(Node root) throws Exception { if(root.getNodeType() != Node.ELEMENT_NODE) return; NamedNodeMap attrs=root.getAttributes(); if(attrs == null || attrs.getLength() == 0) return; Attr name_attr=(Attr)attrs.getNamedItem(NAME), classname_attr=(Attr)attrs.getNamedItem(CLASS), interval_attr=(Attr)attrs.getNamedItem(INTERVAL); Class<Rule> clazz=Util.loadClass(classname_attr.getValue(), getClass()); Rule rule=clazz.newInstance(); long interval=Long.parseLong(interval_attr.getValue()); installRule(name_attr.getValue(), interval, rule); }
protected Protocol createProtocol(String classname) throws Exception { String defaultProtocolName=ProtocolConfiguration.protocol_prefix + '.' + classname; Class<?> clazz=null; try { clazz=Util.loadClass(defaultProtocolName, getClass()); } catch(ClassNotFoundException e) { } if(clazz == null) { try { clazz=Util.loadClass(classname, getClass()); } catch(ClassNotFoundException e) { } if(clazz == null) { throw new Exception("unable to load class for protocol " + classname + " (either as an absolute - " + classname + " - or relative - " + defaultProtocolName + " - package name)"); } } Protocol retval=(Protocol)clazz.newInstance(); if(retval == null) throw new Exception("creation of instance for protocol " + classname + "failed"); retval.setProtocolStack(this); return retval; }
protected BiConsumer<Integer,Integer> createWaitStrategy(String st, BiConsumer<Integer,Integer> default_wait_strategy) { if(st == null) return default_wait_strategy; switch(st) { case "spin": return wait_strategy=SPIN; case "yield": return wait_strategy=YIELD; case "park": return wait_strategy=PARK; case "spin_park": case "spin-park": return wait_strategy=SPIN_PARK; case "spin_yield": case "spin-yield": return wait_strategy=SPIN_YIELD; default: try { Class<BiConsumer<Integer,Integer>> clazz=Util.loadClass(st, this.getClass()); return clazz.newInstance(); } catch(Throwable t) { log.error("failed creating wait_strategy " + st, t); return default_wait_strategy; } } }
@ManagedOperation(description="Installs the given rule with the given classname") public void installRule(String name, long interval, String classname) throws Exception { Class<Rule> clazz=Util.loadClass(classname,getClass()); Rule rule=clazz.newInstance(); installRule(name, interval, rule); }
key_store.load(input, keystore_password.toCharArray()); if(session_verifier_class != null) { Class<? extends SessionVerifier> verifier_class=Util.loadClass(session_verifier_class, getClass()); session_verifier=verifier_class.newInstance(); if(session_verifier_arg != null)
protected static Throwable readException(DataInput in, int recursion_count) throws Exception { Class<? extends Throwable> clazz=(Class<? extends Throwable>)Util.loadClass(classname, (ClassLoader)null);
@ManagedOperation(description="Changes the message processing policy. The fully qualified name of a class " + "implementing MessageProcessingPolicy needs to be given") public void setMessageProcessingPolicy(String policy) { if(policy == null) return; if(policy.startsWith("submit")) { msg_processing_policy=new SubmitToThreadPool(); msg_processing_policy.init(this); return; } else if(policy.startsWith("max")) { msg_processing_policy=new MaxOneThreadPerSender(); msg_processing_policy.init(this); return; } try { Class<MessageProcessingPolicy> clazz=Util.loadClass(policy, getClass()); msg_processing_policy=clazz.newInstance(); message_processing_policy=policy; msg_processing_policy.init(this); } catch(Exception e) { log.error("failed setting message_processing_policy", e); } }
protected static void init() throws Exception { Util.loadClass("javax.xml.parsers.DocumentBuilderFactory", ClassConfigurator.class); continue; Class clazz=Util.loadClass(tuple.getVal2(), ClassConfigurator.class); if(magicMap[m] != null) alreadyInMagicMap(m, clazz.getName()); Class clazz=Util.loadClass(tuple.getVal2(), ClassConfigurator.class); if(protocol_ids.containsKey(clazz)) alreadyInProtocolsMap(m, clazz.getName());
Class<SiteMasterPicker> clazz=Util.loadClass(site_master_picker_impl, (Class)null); this.site_master_picker=clazz.newInstance();
Class<Bundler> clazz=Util.loadClass(type, getClass()); return clazz.newInstance();