/** * Adds a key/value to the cache, replacing a previous item if there was one * @param key The key * @param val The value * @param caching_time Time to live. -1 means never cache, 0 means cache forever. All other (positive) values * are the number of milliseconds to cache the item */ @ManagedOperation public void put(K key, V val, long caching_time) { Address dest_node=getNode(key); if(dest_node.equals(local_addr)) { l2_cache.put(key, val, caching_time); } else { sendPut(dest_node, key, val, caching_time, false); } if(l1_cache != null && caching_time >= 0) l1_cache.put(key, val, caching_time); }
@ManagedOperation public void stop() { if(l1_cache != null) l1_cache.stop(); if(migrate_data) { List<Address> members_without_me=new ArrayList<>(view.getMembers()); members_without_me.remove(local_addr); for(Map.Entry<K,Cache.Value<V>> entry: l2_cache.entrySet()) { K key=entry.getKey(); Address node=hash_function.hash(key, members_without_me); if(!node.equals(local_addr)) { Cache.Value<V> val=entry.getValue(); sendPut(node, key, val.getValue(), val.getTimeout(), true); if(log.isTraceEnabled()) log.trace("migrated " + key + " from " + local_addr + " to " + node); } } } l2_cache.stop(); disp.stop(); ch.close(); }
/** * Adds a key/value to the cache, replacing a previous item if there was one * @param key The key * @param val The value * @param caching_time Time to live. -1 means never cache, 0 means cache forever. All other (positive) values * are the number of milliseconds to cache the item */ @ManagedOperation public void put(K key, V val, long caching_time) { Address dest_node=getNode(key); if(dest_node.equals(local_addr)) { l2_cache.put(key, val, caching_time); } else { sendPut(dest_node, key, val, caching_time, false); } if(l1_cache != null && caching_time >= 0) l1_cache.put(key, val, caching_time); }
@ManagedOperation public void stop() { if(l1_cache != null) l1_cache.stop(); if(migrate_data) { List<Address> members_without_me=new ArrayList<>(view.getMembers()); members_without_me.remove(local_addr); for(Map.Entry<K,Cache.Value<V>> entry: l2_cache.entrySet()) { K key=entry.getKey(); Address node=hash_function.hash(key, members_without_me); if(!node.equals(local_addr)) { Cache.Value<V> val=entry.getValue(); sendPut(node, key, val.getValue(), val.getTimeout(), true); if(log.isTraceEnabled()) log.trace("migrated " + key + " from " + local_addr + " to " + node); } } } l2_cache.stop(); disp.stop(); ch.close(); }