org.jgroups.util.CustomRejectionPolicy Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
The newest version!
package org.jgroups.util;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
/**
* // TODO: Document this
*
* @author Radim Vansa <[email protected]>
* @since 1/29/13
*/
public class CustomRejectionPolicy implements RejectedExecutionHandler {
public final static String NAME = "custom";
private final RejectedExecutionHandler custom;
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.getDeclaredConstructor().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);
}
}
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
custom.rejectedExecution(r, executor);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy