本文整理了Java中org.jgroups.util.Util.loadClass()
方法的一些代码示例,展示了Util.loadClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.loadClass()
方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:loadClass
[英]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.
[中]
代码示例来源:origin: wildfly/wildfly
public static Class get(String clazzname) throws ClassNotFoundException {
return Util.loadClass(clazzname, ClassConfigurator.class);
}
代码示例来源:origin: wildfly/wildfly
/**
* 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);
}
代码示例来源:origin: wildfly/wildfly
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;
}
}
代码示例来源:origin: wildfly/wildfly
/**
* 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());
}
代码示例来源:origin: wildfly/wildfly
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();
}
代码示例来源:origin: wildfly/wildfly
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();
}
代码示例来源:origin: wildfly/wildfly
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);
}
代码示例来源:origin: wildfly/wildfly
@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);
}
}
代码示例来源:origin: wildfly/wildfly
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);
}
}
代码示例来源:origin: wildfly/wildfly
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);
}
代码示例来源:origin: wildfly/wildfly
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;
}
代码示例来源:origin: wildfly/wildfly
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;
}
}
}
代码示例来源:origin: wildfly/wildfly
@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);
}
代码示例来源:origin: wildfly/wildfly
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)
代码示例来源:origin: wildfly/wildfly
protected static Throwable readException(DataInput in, int recursion_count) throws Exception {
Class<? extends Throwable> clazz=(Class<? extends Throwable>)Util.loadClass(classname, (ClassLoader)null);
代码示例来源:origin: wildfly/wildfly
@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);
}
}
代码示例来源:origin: wildfly/wildfly
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());
代码示例来源:origin: wildfly/wildfly
Class<SiteMasterPicker> clazz=Util.loadClass(site_master_picker_impl, (Class)null);
this.site_master_picker=clazz.newInstance();
代码示例来源:origin: wildfly/wildfly
clazz=Util.loadClass(defaultProtocolName, stack != null? stack.getClass() : null);
clazz=Util.loadClass(protocol_name, config.getClassLoader());
代码示例来源:origin: wildfly/wildfly
Class<Bundler> clazz=Util.loadClass(type, getClass());
return clazz.newInstance();
内容来源于网络,如有侵权,请联系作者删除!