📄 lazyreplicatedmap.java
字号:
entry.setBackupNodes(backup); entry.setBackup(false); entry.setProxy(false); } catch (Exception x) { log.error("Unable to replicate out data for a LazyReplicatedMap.get operation", x); return null; } } if (log.isTraceEnabled()) log.trace("Requesting id:"+key+" result:"+entry.getValue()); return entry.getValue(); } /** * Returns true if the key has an entry in the map. * The entry can be a proxy or a backup entry, invoking <code>get(key)</code> * will make this entry primary for the group * @param key Object * @return boolean */ public boolean containsKey(Object key) { return super.containsKey(key); } public Object put(Object key, Object value) { if ( !(key instanceof Serializable) ) throw new IllegalArgumentException("Key is not serializable:"+key.getClass().getName()); if ( value == null ) return remove(key); if ( !(value instanceof Serializable) ) throw new IllegalArgumentException("Value is not serializable:"+value.getClass().getName()); MapEntry entry = new MapEntry((Serializable)key,(Serializable)value); entry.setBackup(false); entry.setProxy(false); Object old = null; //make sure that any old values get removed if ( containsKey(key) ) old = remove(key); try { Member[] backup = publishEntryInfo(key, value); entry.setBackupNodes(backup); } catch (ChannelException x) { log.error("Unable to replicate out data for a LazyReplicatedMap.put operation", x); } super.put(key,entry); return old; } /** * Copies all values from one map to this instance * @param m Map */ public void putAll(Map m) { Iterator i = m.entrySet().iterator(); while ( i.hasNext() ) { Map.Entry entry = (Map.Entry)i.next(); put(entry.getKey(),entry.getValue()); } } /** * Removes an object from this map, it will also remove it from * * @param key Object * @return Object */ public Object remove(Object key) { MapEntry entry = (MapEntry)super.remove(key); try { MapMessage msg = new MapMessage(getMapContextName(),MapMessage.MSG_REMOVE,false,(Serializable)key,null,null,null); getChannel().send(getMapMembers(), msg,getChannelSendOptions()); } catch ( ChannelException x ) { log.error("Unable to replicate out data for a LazyReplicatedMap.remove operation",x); } return entry!=null?entry.getValue():null; } public void clear() { //only delete active keys Iterator keys = keySet().iterator(); while ( keys.hasNext() ) remove(keys.next()); } public boolean containsValue(Object value) { if ( value == null ) { return super.containsValue(value); } else { Iterator i = super.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry) i.next(); MapEntry entry = (MapEntry) e.getValue(); if (entry.isPrimary() && value.equals(entry.getValue())) return true; }//while return false; }//end if } public Object clone() { throw new UnsupportedOperationException("This operation is not valid on a replicated map"); } /** * Returns the entire contents of the map * Map.Entry.getValue() will return a LazyReplicatedMap.MapEntry object containing all the information * about the object. * @return Set */ public Set entrySetFull() { return super.entrySet(); } public Set keySetFull() { return super.keySet(); } public int sizeFull() { return super.size(); } public Set entrySet() { LinkedHashSet set = new LinkedHashSet(super.size()); Iterator i = super.entrySet().iterator(); while ( i.hasNext() ) { Map.Entry e = (Map.Entry)i.next(); MapEntry entry = (MapEntry)e.getValue(); if ( entry.isPrimary() ) set.add(entry); } return Collections.unmodifiableSet(set); } public Set keySet() { //todo implement //should only return keys where this is active. LinkedHashSet set = new LinkedHashSet(super.size()); Iterator i = super.entrySet().iterator(); while ( i.hasNext() ) { Map.Entry e = (Map.Entry)i.next(); MapEntry entry = (MapEntry)e.getValue(); if ( entry.isPrimary() ) set.add(entry.getKey()); } return Collections.unmodifiableSet(set); } public int size() { //todo, implement a counter variable instead //only count active members in this node int counter = 0; Iterator i = super.entrySet().iterator(); while ( i.hasNext() ) { Map.Entry e = (Map.Entry)i.next(); MapEntry entry = (MapEntry)e.getValue(); if ( entry.isPrimary() && entry.getValue()!=null ) counter++; } return counter; } protected boolean removeEldestEntry(Map.Entry eldest) { return false; } public boolean isEmpty() { return size()==0; } public Collection values() { ArrayList values = new ArrayList(super.size()); Iterator i = super.entrySet().iterator(); while ( i.hasNext() ) { Map.Entry e = (Map.Entry)i.next(); MapEntry entry = (MapEntry)e.getValue(); if ( entry.isPrimary() && entry.getValue()!=null) values.add(entry.getValue()); } return Collections.unmodifiableCollection(values); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -