PbcastHeader hdr;
Message m, copy;
View v;
Vector mbrs;
Address key;
NakReceiverWindow win;
switch(evt.getType()) {
case Event.MSG:
m=(Message) evt.getArg();
if(m.getDest() != null && !m.getDest().isMulticastAddress()) {
break; // unicast address: not null and not mcast, pass down unchanged
}
else { // multicast address
hdr=new PbcastHeader(PbcastHeader.MCAST_MSG, seqno);
m.putHeader(getName(), hdr);
// put message in NakReceiverWindow (to be on the safe side if we don't receive it ...)
synchronized(digest) {
win=(NakReceiverWindow) digest.get(local_addr);
if(win == null) {
if(log.isInfoEnabled()) log.info("NakReceiverWindow for sender " + local_addr +
" not found. Creating new NakReceiverWindow starting at seqno=" + seqno);
win=new NakReceiverWindow(local_addr, seqno);
digest.put(local_addr, win);
}
copy=m.copy();
copy.setSrc(local_addr);
win.add(seqno, copy);
}
seqno++;
break;
}
case Event.SET_DIGEST:
setDigest((Digest) evt.getArg());
return; // don't pass down
case Event.GET_DIGEST: // don't pass down
passUp(new Event(Event.GET_DIGEST_OK, getDigest()));
return;
case Event.GET_DIGEST_STATE: // don't pass down
passUp(new Event(Event.GET_DIGEST_STATE_OK, getDigest()));
return;
case Event.VIEW_CHANGE:
v=(View) evt.getArg();
if(v == null) {
if(log.isErrorEnabled()) log.error("view is null !");
break;
}
mbrs=v.getMembers();
// update internal membership list
synchronized(members) {
members.removeAllElements();
for(int i=0; i < mbrs.size(); i++)
members.addElement(mbrs.elementAt(i));
}
// delete all members in digest that are not in new membership list
if(mbrs.size() > 0) {
synchronized(digest) {
for(Enumeration e=digest.keys(); e.hasMoreElements();) {
key=(Address) e.nextElement();
if(!mbrs.contains(key)) {
win=(NakReceiverWindow) digest.get(key);
win.reset();
digest.remove(key);
}
}
}
}
// add all members from new membership list that are not yet in digest
for(int i=0; i < mbrs.size(); i++) {
key=(Address) mbrs.elementAt(i);
if(!digest.containsKey(key)) {
digest.put(key, new NakReceiverWindow(key, 1));
}
}
if(dynamic) {
gossip_interval=computeGossipInterval(members.size(), desired_avg_gossip);