1 package org.jgroups.protocols; 2 3 import org.jgroups.Event; 4 import org.jgroups.Message; 5 import org.jgroups.stack.Protocol; 6 7 import java.util.Properties ; 8 9 16 public class DISCARD_PAYLOAD extends Protocol { 17 long seqno=3; long duplicate=4; int num_discards=0; 20 21 public DISCARD_PAYLOAD() { 22 } 23 24 public String getName() { 25 return "DISCARD_PAYLOAD"; 26 } 27 28 public boolean setProperties(Properties props) { 29 String str; 30 31 super.setProperties(props); 32 33 str=props.getProperty("seqno"); 34 if(str != null) { 35 seqno=Long.parseLong(str); 36 props.remove("seqno"); 37 } 38 39 str=props.getProperty("duplicate"); 40 if(str != null) { 41 duplicate=Long.parseLong(str); 42 props.remove("duplicate"); 43 } 44 45 if(!props.isEmpty()) { 46 log.error("these properties are not recognized: " + props); 47 return false; 48 } 49 return true; 50 } 51 52 53 public Object up(Event evt) { 54 if(evt.getType() == Event.MSG) { 55 Message msg=(Message)evt.getArg(); 56 if(msg.getLength() > 0) { 57 try { 58 Long payload=(Long )msg.getObject(); 59 if(payload != null) { 60 long val=payload.longValue(); 61 62 if(val == seqno) { 63 synchronized(this) { 64 if(num_discards < 3) { 65 num_discards++; 66 return null; 67 } 68 } 69 } 70 if(val == duplicate) { super.up(evt); } 73 } 74 } 75 catch(Throwable t) { 76 ; 77 } 78 } 79 } 80 return up_prot.up(evt); 81 } 82 } 83 | Popular Tags |