/** * @see java.util.Map#putAll(java.util.Map) */ public void _putAll(Map<? extends K,? extends V> map) { if(map == null) return; // Calling the method below seems okay, but would result in ... deadlock ! // The reason is that Map.putAll() calls put(), which we override, which results in // lock contention for the map. // ---> super.putAll(m); <--- CULPRIT !!!@#$%$ // That said let's do it the stupid way: for(Map.Entry<? extends K,? extends V> entry:map.entrySet()) { this.map.put(entry.getKey(), entry.getValue()); } if(!map.isEmpty()) { for(Notification notif:notifs) notif.contentsSet(map); } }
public boolean _remove(K key, V value) { boolean removed=map.remove(key, value); if(removed) { for(Notification notif:notifs) notif.entryRemoved(key); } return removed; }
public V _putIfAbsent(K key, V value) { V retval=map.putIfAbsent(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }
/** * @see java.util.Map#putAll(java.util.Map) */ public void _putAll(Map<? extends K, ? extends V> map) { if(map == null) return; // Calling the method below seems okay, but would result in ... deadlock ! // The reason is that Map.putAll() calls put(), which we override, which results in // lock contention for the map. // ---> super.putAll(m); <--- CULPRIT !!!@#$%$ // That said let's do it the stupid way: for(Map.Entry<? extends K,? extends V> entry: map.entrySet()) { super.put(entry.getKey(), entry.getValue()); } if(persistent) { try { persistence_mgr.saveAll(map); } catch(CannotPersistException persist_ex) { if(log.isErrorEnabled()) log.error("failed persisting contents: " + persist_ex); } catch(Throwable t) { if(log.isErrorEnabled()) log.error("failed persisting contents: " + t); } } for(int i=0; i < notifs.size(); i++) notifs.elementAt(i).contentsSet(map); }
void sendViewChangeNotifications(View view, Vector<Address> new_mbrs, Vector<Address> old_mbrs) { Vector<Address> joined, left; Notification n; if((notifs.isEmpty()) || (old_mbrs == null) || (new_mbrs == null) || (old_mbrs.isEmpty()) || (new_mbrs.isEmpty())) return; // 1. Compute set of members that joined: all that are in new_mbrs, but not in old_mbrs joined=new Vector<Address>(); for(Address mbr: new_mbrs) { if(!old_mbrs.contains(mbr)) joined.addElement(mbr); } // 2. Compute set of members that left: all that were in old_mbrs, but not in new_mbrs left=new Vector<Address>(); for(Address mbr: old_mbrs) { if(!new_mbrs.contains(mbr)) { left.addElement(mbr); } } for(int i=0; i < notifs.size(); i++) { n=notifs.elementAt(i); n.viewChange(view, joined, left); } }
/** * @see java.util.Map#putAll(java.util.Map) */ public void _putAll(Map<? extends K,? extends V> map) { if(map == null) return; // Calling the method below seems okay, but would result in ... deadlock ! // The reason is that Map.putAll() calls put(), which we override, which results in // lock contention for the map. // ---> super.putAll(m); <--- CULPRIT !!!@#$%$ // That said let's do it the stupid way: for(Map.Entry<? extends K,? extends V> entry:map.entrySet()) { this.map.put(entry.getKey(), entry.getValue()); } if(!map.isEmpty()) { for(Notification notif:notifs) notif.contentsSet(map); } }
public V _put(K key, V value) { V retval=super.put(key, value); if(persistent) { try { persistence_mgr.save(key, value); } catch(CannotPersistException cannot_persist_ex) { if(log.isErrorEnabled()) log.error("failed persisting " + key + " + " + value + ", exception=" + cannot_persist_ex); } catch(Throwable t) { if(log.isErrorEnabled()) log.error("failed persisting " + key + " + " + value + ", exception=" + Util.printStackTrace(t)); } } for(int i=0; i < notifs.size(); i++) notifs.elementAt(i).entrySet(key, value); return retval; }
public V _remove(Object key) { V retval=super.remove(key); if(persistent) { try { persistence_mgr.remove((Serializable)key); } catch(CannotRemoveException cannot_remove_ex) { if(log.isErrorEnabled()) log.error("failed clearing contents, exception=" + cannot_remove_ex); } catch(Throwable t) { if(log.isErrorEnabled()) log.error("failed clearing contents, exception=" + t); } } for(int i=0; i < notifs.size(); i++) notifs.elementAt(i).entryRemoved(key); return retval; }
public void _clear() { super.clear(); if(persistent) { try { persistence_mgr.clear(); } catch(CannotRemoveException cannot_remove_ex) { if(log.isErrorEnabled()) log.error("failed clearing contents, exception=" + cannot_remove_ex); } catch(Throwable t) { if(log.isErrorEnabled()) log.error("failed clearing contents, exception=" + t); } } for(int i=0; i < notifs.size(); i++) notifs.elementAt(i).contentsCleared(); }
public boolean _remove(K key, V value) { boolean removed=map.remove(key, value); if(removed) { for(Notification notif:notifs) notif.entryRemoved(key); } return removed; }
public V _remove(K key) { V retval=map.remove(key); if(retval != null) { for(Notification notif:notifs) notif.entryRemoved(key); } return retval; }
public V _replace(K key, V value) { V retval=map.replace(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }
public boolean _replace(K key, V oldValue, V newValue) { boolean replaced=map.replace(key, oldValue, newValue); if(replaced) { for(Notification notif:notifs) notif.entrySet(key, newValue); } return replaced; }
public V _putIfAbsent(K key, V value) { V retval=map.putIfAbsent(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }
public V _put(K key, V value) { V retval=map.put(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }
void sendViewChangeNotifications(View view, List<Address> new_mbrs, List<Address> old_mbrs) { if((notifs.isEmpty()) || (old_mbrs == null) || (new_mbrs == null)) return; // 1. Compute set of members that joined: all that are in new_mbrs, but not in old_mbrs List<Address> joined=new_mbrs.stream().filter(mbr -> !old_mbrs.contains(mbr)).collect(Collectors.toList()); // 2. Compute set of members that left: all that were in old_mbrs, but not in new_mbrs List<Address> left=old_mbrs.stream().filter(mbr -> !new_mbrs.contains(mbr)).collect(Collectors.toList()); notifs.forEach( notif -> notif.viewChange(view, joined, left)); }
public boolean _replace(K key, V oldValue, V newValue) { boolean replaced=map.replace(key, oldValue, newValue); if(replaced) { for(Notification notif:notifs) notif.entrySet(key, newValue); } return replaced; }
public V _remove(K key) { V retval=map.remove(key); if(retval != null) { for(Notification notif:notifs) notif.entryRemoved(key); } return retval; }
public V _replace(K key, V value) { V retval=map.replace(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }
public V _put(K key, V value) { V retval=map.put(key, value); for(Notification notif:notifs) notif.entrySet(key, value); return retval; }