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

org.jgroups.stack.CheckForAbsenceOfRED 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.stack;

import org.jgroups.protocols.RED;
import org.jgroups.protocols.TP;
import org.jgroups.util.ShutdownRejectedExecutionHandler;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * If either {@link org.jgroups.protocols.UNICAST3} or {@link org.jgroups.protocols.pbcast.NAKACK2} are missing, then
 * this policy checks that {@link org.jgroups.protocols.RED} is not in the protocol stack.
 * @author Bela Ban
 * @since 5.2.14
 */
public class CheckForAbsenceOfRED implements Policy {

    protected static final Class UNICAST3=org.jgroups.protocols.UNICAST3.class,
      NAKACK2=org.jgroups.protocols.pbcast.NAKACK2.class, RED=RED.class;

    @Override
    public void check(Protocol prot) throws Exception {
        if(!(prot instanceof TP))
            throw new IllegalStateException(String.format("%s needs to be run in the scope of a transport",
                                                          CheckForAbsenceOfRED.class.getSimpleName()));
        ProtocolStack stack=prot.getProtocolStack();
        if(stack.findProtocol(UNICAST3) == null || stack.findProtocol(NAKACK2) == null) {
            if(stack.findProtocol(RED) != null) {
                String e=String.format("found %s: when either %s or %s are missing, this can lead " +
                                         "to message loss. Please remove %s", RED.getSimpleName(),
                                       UNICAST3.getSimpleName(), NAKACK2.getSimpleName(), RED.getSimpleName());
                throw new IllegalStateException(e);
            }
        }
    }

    protected static boolean isCallerRunsHandler(RejectedExecutionHandler h) {
        return h instanceof ThreadPoolExecutor.CallerRunsPolicy ||
          (h instanceof ShutdownRejectedExecutionHandler
            && ((ShutdownRejectedExecutionHandler)h).handler() instanceof ThreadPoolExecutor.CallerRunsPolicy);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy