All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.activemq.artemis.shaded.org.jgroups.util.CustomRejectionPolicy Maven / Gradle / Ivy

There is a newer version: 2.33.0
Show newest version
package org.apache.activemq.artemis.shaded.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 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.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 - 2024 Weber Informatics LLC | Privacy Policy