1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Address; 6 import org.jgroups.Event; 7 import org.jgroups.Message; 8 import org.jgroups.stack.Protocol; 9 10 import java.util.Properties ; 11 import java.util.Vector ; 12 13 14 15 20 21 public class DISCARD extends Protocol 22 { 23 final Vector members = new Vector (); 24 double up = 0.0; double down = 0.0; boolean excludeItself = false; Address localAddress; 28 final int num_sent = 25; 30 31 32 public String getName() 33 { 34 return "DISCARD"; 35 } 36 37 38 public boolean setProperties(Properties props) 39 { 40 String str; 41 42 super.setProperties(props); 43 str = props.getProperty("up"); 44 if (str != null) 45 { 46 up = Double.parseDouble(str); 47 props.remove("up"); 48 } 49 50 str = props.getProperty("down"); 51 if (str != null) 52 { 53 down = Double.parseDouble(str); 54 props.remove("down"); 55 } 56 57 str = props.getProperty("excludeitself"); 58 if (str != null) 59 { 60 excludeItself = Boolean.valueOf(str).booleanValue(); 61 props.remove("excludeitself"); 62 } 63 64 65 if (props.size() > 0) 66 { 67 System.err.println("DISCARD.setProperties(): these properties are not recognized:"); 68 props.list(System.out); 69 return false; 70 } 71 return true; 72 } 73 74 75 public void up(Event evt) 76 { 77 Message msg; 78 double r; 79 80 if (evt.getType() == Event.SET_LOCAL_ADDRESS) 81 localAddress = (Address) evt.getArg(); 82 83 84 if (evt.getType() == Event.MSG) 85 { 86 msg = (Message) evt.getArg(); 87 if (up > 0) 88 { 89 94 95 96 r = Math.random(); 97 if (r < up) 98 { 99 if (excludeItself && msg.getSrc().equals(localAddress)) 100 { 101 if(log.isInfoEnabled()) log.info("excluding itself"); 102 } 103 else 104 { 105 if(log.isInfoEnabled()) log.info("dropping message"); 106 return; 107 } 108 } 109 } 110 } 111 112 113 passUp(evt); 114 } 115 116 117 public void down(Event evt) 118 { 119 Message msg; 120 double r; 121 122 if (evt.getType() == Event.MSG) 123 { 124 msg = (Message) evt.getArg(); 125 126 if (down > 0) 127 { 128 133 r = Math.random(); 134 if (r < down) 135 { 136 137 if (excludeItself && msg.getSrc().equals(localAddress)) 138 { 139 if(log.isInfoEnabled()) log.info("excluding itself"); 140 } 141 else 142 { 143 if(log.isInfoEnabled()) log.info("dropping message"); 144 return; 145 } 146 } 147 } 148 149 } 150 passDown(evt); 151 } 152 } 153 | Popular Tags |