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

org.jgroups.protocols.DISCARD_PAYLOAD Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS 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).

There is a newer version: 33.0.2.Final
Show newest version
package org.jgroups.protocols;

import org.jgroups.Event;
import org.jgroups.Message;
import org.jgroups.annotations.Property;
import org.jgroups.annotations.Unsupported;
import org.jgroups.stack.Protocol;

/**
 * Discards a message whose sequence number (in the payload, as a Long) matches seqno 2 times,
 * before passing it down. Used for unit testing
 * of OOB messages
 * @author Bela Ban
 */
@Unsupported
public class DISCARD_PAYLOAD extends Protocol {
    @Property protected long seqno=3; // drop 3
    @Property protected long duplicate=4; // duplicate 4 (one time)
    protected int            num_discards=0;

    public DISCARD_PAYLOAD() {
    }

    public Object down(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            if(msg.getLength() > 0) {
                try {
                    Long payload=(Long)msg.getObject();
                    if(payload != null) {
                        if(payload == seqno) {
                            synchronized(this) {
                                if(num_discards < 3) {
                                    num_discards++;
                                    return null;
                                }
                            }
                        }
                        if(payload == duplicate) { // inject a duplicate message
                            super.down(evt); // pass it down, will passed down a second time by the default down_prot.down(evt)
                        }
                    }
                }
                catch(Throwable t) {
                    ;
                }
            }
        }
        return down_prot.down(evt);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy