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).

The newest version!
package org.jgroups.protocols;

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;

    public DISCARD_PAYLOAD() {
    }

    public Object down(Message msg) {
        if(msg.getLength() > 0) {
            try {
                Long payload=msg.getObject();
                if(payload != null) {
                    if(payload == seqno) {
                        synchronized(this) {
                            if(num_discards++ < 3) {
                                System.out.printf("** %s: discarded seqno %d\n", getTransport().getAddress(), payload);
                                return null;
                            }
                        }
                    }
                    if(payload == duplicate) { // inject a duplicate message
                        super.down(msg); // pass it down, will passed down a second time by the default down_prot.down(evt)
                    }
                }
            }
            catch(Throwable t) {
                ;
            }
        }
        return down_prot.down(msg);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy