public Object down(Event evt) { switch(evt.getType()) { case Event.VIEW_CHANGE: down_prot.down(evt); View v=evt.getArg(); handleViewChange(v); return null; case Event.SET_LOCAL_ADDRESS: local_addr=evt.getArg(); break; case Event.UNSUSPECT: Address mbr=evt.getArg(); unsuspect(mbr); update(mbr); break; } return down_prot.down(evt); }
protected void handleViewChange(View v) { List<Address> mbrs=v.getMembers(); synchronized(this) { members.clear(); members.addAll(mbrs); if(suspected_mbrs.retainAll(mbrs)) has_suspected_mbrs=!suspected_mbrs.isEmpty(); timestamps.keySet().retainAll(mbrs); } mbrs.forEach(this::addIfAbsent); if(mbrs.size() > 1) { startHeartbeatSender(); startTimeoutChecker(); } else { stopHeartbeatSender(); stopTimeoutChecker(); } }
public void run() { List<Address> suspects=new LinkedList<>(); long current_time=getTimestamp(), diff; for(Iterator<Entry<Address,Long>> it=timestamps.entrySet().iterator(); it.hasNext();) { Entry<Address,Long> entry=it.next(); Address key=entry.getKey(); Long val=entry.getValue(); if(val == null) { it.remove(); continue; } diff=TimeUnit.MILLISECONDS.convert(current_time - val, TimeUnit.NANOSECONDS); if(diff > timeout) { log.debug("haven't received a heartbeat from " + key + " for " + diff + " ms, adding it to suspect list"); suspects.add(key); } } if(!suspects.isEmpty()) suspect(suspects); }
public synchronized void stop() { stopHeartbeatSender(); stopTimeoutChecker(); suspected_mbrs.clear(); has_suspected_mbrs=false; }
public Object up(Message msg) { Address sender=msg.getSrc(); Header hdr=msg.getHeader(this.id); if(hdr != null) { update(sender); // updates the heartbeat entry for 'sender' num_heartbeats_received++; unsuspect(sender); return null; // consume heartbeat message, do not pass to the layer above } else if(msg_counts_as_heartbeat) { // message did not originate from FD_ALL layer, but still count as heartbeat update(sender); // update when data is received too ? maybe a bit costly if(has_suspected_mbrs) unsuspect(sender); } return up_prot.up(msg); // pass up to the layer above us }
private void startTasks() { startHeartbeatSender(); startTimeoutChecker(); tasks_running=true; if(log.isTraceEnabled()) log.trace("started heartbeat sender and timeout checker tasks"); }
protected void addIfAbsent(Address mbr) { if(mbr != null && !mbr.equals(local_addr)) timestamps.putIfAbsent(mbr, getTimestamp()); }
hdr=(Header)msg.getHeader(name); if(msg_counts_as_heartbeat) update(msg.getSrc()); // update when data is received too ? maybe a bit costly if(hdr == null) break; // message did not originate from FD_ALL layer, just pass up shunInvalidHeartbeatSender(sender); break; update(sender); // updates the heartbeat entry for 'sender' num_heartbeats_received++; break; // don't pass up !
@ManagedOperation(description="Stops checking for crashed members") public void stopFailureDetection() { stopTimeoutChecker(); }
@ManagedOperation(description="Resumes checking for crashed members") public void startFailureDetection() { startTimeoutChecker(); }
public void run() { Map.Entry entry; Object key; Long val; if(log.isTraceEnabled()) log.trace("checking for expired senders, table is:\n" + printTimeStamps()); long current_time=System.currentTimeMillis(), diff; for(Iterator it=timestamps.entrySet().iterator(); it.hasNext();) { entry=(Map.Entry)it.next(); key=entry.getKey(); val=(Long)entry.getValue(); if(val == null) { it.remove(); continue; } diff=current_time - val.longValue(); if(diff > timeout) { if(log.isTraceEnabled()) log.trace("haven't received a heartbeat from " + key + " for " + diff + " ms, suspecting it"); suspect((Address)key); } } }
public Object down(Event evt) { switch(evt.getType()) { case Event.VIEW_CHANGE: down_prot.down(evt); View v=(View)evt.getArg(); handleViewChange(v); return null; } return down_prot.down(evt); }
@ManagedOperation(description="Prints timestamps") public String printTimestamps() { return _printTimestamps(); }
new MERGE3(), new FD_SOCK(), new FD_ALL(), new VERIFY_SUSPECT(), new BARRIER(),
public synchronized void stop() { stopHeartbeatSender(); stopTimeoutChecker(); suspected_mbrs.clear(); has_suspected_mbrs=false; }
protected String _printTimestamps() { StringBuilder sb=new StringBuilder(); long current_time=getTimestamp(); for(Iterator<Entry<Address,Long>> it=timestamps.entrySet().iterator(); it.hasNext();) { Entry<Address,Long> entry=it.next(); sb.append(entry.getKey()).append(": "); sb.append(TimeUnit.SECONDS.convert (current_time - entry.getValue(), TimeUnit.NANOSECONDS)).append(" secs old\n"); } return sb.toString(); }
@ManagedOperation(description="Stops checking for crashed members") public void stopFailureDetection() { stopTimeoutChecker(); }
@ManagedOperation(description="Resumes checking for crashed members") public void startFailureDetection() { startTimeoutChecker(); }
@ManagedOperation(description="Prints timestamps") public String printTimestamps() { return _printTimestamps(); }