public void readFrom(DataInput in) throws Exception { byte flags=in.readByte(); // 1. view if((flags & VIEW_PRESENT) == VIEW_PRESENT) { view=new View(); view.readFrom(in); } // 2. digest if((flags & DIGEST_PRESENT) == DIGEST_PRESENT) { digest=new Digest(view.getMembersRaw()); digest.readFrom(in, false); } // 3. fail_reason if((flags & FAIL_REASON_PRESENT) == FAIL_REASON_PRESENT) fail_reason=in.readUTF(); }
public void writeTo(DataOutput out) throws Exception { writeTo(out, true); }
/** Creates a new digest from an existing map by copying the keys and values from map */ public Digest(Map<Address, long[]> map) { createArrays(map); checkPostcondition(); }
public String toString(final Address[] order, boolean print_highest_received) { StringBuilder sb=new StringBuilder(); boolean first=true; if(capacity() == 0) return "[]"; int count=0, capacity=capacity(); for(Address key: order) { long[] tmp_seqnos=key != null? get(key) : null; if(key == null || tmp_seqnos == null) continue; if(!first) sb.append(", "); else first=false; sb.append(key).append(": ").append('[').append(tmp_seqnos[0]); if(print_highest_received) sb.append(" (").append(tmp_seqnos[1]).append(")"); sb.append("]"); if(Util.MAX_LIST_PRINT_SIZE > 0 && ++count >= Util.MAX_LIST_PRINT_SIZE) { if(capacity > count) sb.append(", ..."); break; } } return sb.toString(); }
public Digest highestSequence(Digest other) { if(other == null) return copy(); if(this.equals(other)) { return this; Entry e1=this.get(address); Entry e2=other.get(address); thisMinusInteresection.removeAll(intersection); for(Address address : thisMinusInteresection) { resultMap.put(address, new Entry(this.get(address))); otherMinusInteresection.removeAll(intersection); for(Address address : otherMinusInteresection) { resultMap.put(address, new Entry(other.get(address))); result=new Digest(resultMap);
public Digest copy() { return new Digest(members, Arrays.copyOf(seqnos, seqnos.length)); }
public int serializedSize() { int retval=Global.BYTE_SIZE; // type retval+=Global.BYTE_SIZE; // presence byte for my_digest if(my_digest != null) retval+=my_digest.serializedSize(true); return retval; } }
protected static Buffer marshal(final View view, final Digest digest) { try { int expected_size=Global.SHORT_SIZE; if(view != null) expected_size+=view.serializedSize(); boolean write_addrs=writeAddresses(view, digest); if(digest != null) expected_size=(int)digest.serializedSize(write_addrs); final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size +10); out.writeShort(determineFlags(view, digest)); if(view != null) view.writeTo(out); if(digest != null) digest.writeTo(out, write_addrs); return out.getBuffer(); } catch(Exception ex) { return null; } }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { type=in.readInt(); boolean digest_not_null=in.readBoolean(); if(digest_not_null) { stableDigest=new Digest(); stableDigest.readExternal(in); } }
their_digest=rebroadcast_digest.getSenders(); sender=entry.getKey(); their_entry=entry.getValue(); my_entry=my_digest.get(sender); if(my_entry == null) continue; try { my_digest=getDigest(); if(!rebroadcasting || my_digest.isGreaterThanOrEqual(rebroadcast_digest)) { return;
/** * Returns true if all senders of the current digest have their seqnos >= the ones from other */ protected static boolean isGreaterThanOrEqual(Digest first, Digest other) { if(other == null) return true; for(Digest.Entry entry: first) { Address sender=entry.getMember(); long[] their_entry=other.get(sender); if(their_entry == null) continue; long my_highest=entry.getHighest(); long their_highest=Math.max(their_entry[0],their_entry[1]); if(my_highest < their_highest) return false; } return true; }
public boolean hasNext() { return index < capacity(); }
/** * Returns true if all senders of the current digest have their seqnos >= the ones from other * @param other * @return */ public boolean isGreaterThanOrEqual(Digest other) { if(other == null) return true; Map<Address,Entry> our_map=getSenders(); Address sender; Entry my_entry, their_entry; long my_highest, their_highest; for(Map.Entry<Address,Entry> entry: our_map.entrySet()) { sender=entry.getKey(); my_entry=entry.getValue(); their_entry=other.get(sender); if(their_entry == null) continue; my_highest=my_entry.getHighest(); their_highest=their_entry.getHighest(); if(my_highest < their_highest) return false; } return true; }
public void readFrom(DataInput in) throws Exception { readFrom(in, true); }
protected boolean isJoinResponseValid(final JoinRsp rsp) { if(rsp.getFailReason() != null) throw new SecurityException(rsp.getFailReason()); Digest tmp_digest=rsp.getDigest(); if(tmp_digest == null || tmp_digest.capacity() == 0) { log.warn("%s: digest is empty: digest=%s", gms.local_addr, rsp.getDigest()); return false; } if(!tmp_digest.contains(gms.local_addr)) { log.error("%s: digest in JOIN_RSP does not contain myself; join response: %s", gms.local_addr, rsp); return false; } if(rsp.getView() == null) { log.error("%s: JoinRsp has a null view, skipping it", gms.local_addr); return false; } return true; }
protected static boolean same(final List<Digest> digests) { if(digests == null) return false; Digest first=digests.get(0); for(int i=1; i < digests.size(); i++) { Digest current=digests.get(i); if(!first.equals(current)) return false; } return true; }
/** Only used for testing */ public Digest(Digest digest) { if(digest == null) return; this.members=digest.members; // the members list is immutable this.seqnos=(digest instanceof MutableDigest || this instanceof MutableDigest)? Arrays.copyOf((digest).seqnos, digest.seqnos.length) : digest.seqnos; checkPostcondition(); }
public Gossip copy() { Gossip ret=new Gossip(sender, id); if(digest != null) ret.digest=digest.copy(); if(not_seen != null) ret.not_seen=(Vector)not_seen.clone(); if(seen != null) ret.seen=(Vector)seen.clone(); return ret; }
public boolean containsAll(Address ... members) { for(Address member: members) if(!contains(member)) return false; return true; }