Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7B6039E8C for ; Thu, 22 Dec 2011 16:27:32 +0000 (UTC) Received: (qmail 31840 invoked by uid 500); 22 Dec 2011 16:27:31 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 31782 invoked by uid 500); 22 Dec 2011 16:27:31 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 31773 invoked by uid 99); 22 Dec 2011 16:27:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Dec 2011 16:27:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Dec 2011 16:27:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 366E823888E7 for ; Thu, 22 Dec 2011 16:27:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1222329 - in /tomcat/trunk: java/org/apache/catalina/ha/context/ java/org/apache/catalina/ha/session/ java/org/apache/catalina/tribes/tipis/ test/org/apache/catalina/tribes/demos/ Date: Thu, 22 Dec 2011 16:27:02 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111222162703.366E823888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markt Date: Thu Dec 22 16:27:02 2011 New Revision: 1222329 URL: http://svn.apache.org/viewvc?rev=1222329&view=rev Log: Update AbstractReplicatedMap and sub-classes to use generics The key change is that it now implements Map rather than extends ConcurrentMap. There are several reasons for this: - The interface is K,V but K,MapEntry was placed in the extended ConcurrentMap so generics simply couldn't work. Hence the switch from extending ConcurrentMap to using a private ConcurrentMap instance - The API contract for ConcurrentMap can't be met as currently written (and without a lot of extra code) o switching to Map was the obvious approach. Modified: tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java tomcat/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java tomcat/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java tomcat/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java Modified: tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java Thu Dec 22 16:27:02 2011 @@ -16,10 +16,10 @@ */ package org.apache.catalina.ha.context; -import java.util.AbstractMap; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -60,8 +60,10 @@ public class ReplicatedContext extends S CatalinaCluster catclust = (CatalinaCluster)this.getCluster(); if (this.context == null) this.context = new ReplApplContext(this); if ( catclust != null ) { - ReplicatedMap map = new ReplicatedMap(this,catclust.getChannel(),DEFAULT_REPL_TIMEOUT, - getName(),getClassLoaders()); + ReplicatedMap map = + new ReplicatedMap(this, + catclust.getChannel(),DEFAULT_REPL_TIMEOUT, + getName(),getClassLoaders()); map.setChannelSendOptions(mapSendOptions); ((ReplApplContext)this.context).setAttributeMap(map); if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName()); @@ -85,10 +87,10 @@ public class ReplicatedContext extends S super.stopInternal(); - AbstractMap map = - ((ReplApplContext)this.context).getAttributeMap(); + Map map = + ((ReplApplContext)this.context).getAttributeMap(); if ( map!=null && map instanceof ReplicatedMap) { - ((ReplicatedMap)map).breakdown(); + ((ReplicatedMap)map).breakdown(); } } @@ -144,10 +146,10 @@ public class ReplicatedContext extends S return super.getFacade(); } - public AbstractMap getAttributeMap() { - return (AbstractMap)this.attributes; + public Map getAttributeMap() { + return this.attributes; } - public void setAttributeMap(AbstractMap map) { + public void setAttributeMap(Map map) { this.attributes = map; } Modified: tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java (original) +++ tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java Thu Dec 22 16:27:02 2011 @@ -92,7 +92,8 @@ public class BackupManager extends Clust @Override public ClusterMessage requestCompleted(String sessionId) { if (!getState().isAvailable()) return null; - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap map = + (LazyReplicatedMap)sessions; map.replicate(sessionId,false); return null; } @@ -143,11 +144,10 @@ public class BackupManager extends Clust try { cluster.registerManager(this); - LazyReplicatedMap map = new LazyReplicatedMap(this, - cluster.getChannel(), - rpcTimeout, - getMapName(), - getClassLoaders()); + LazyReplicatedMap map = + new LazyReplicatedMap(this, + cluster.getChannel(), rpcTimeout, getMapName(), + getClassLoaders()); map.setChannelSendOptions(mapSendOptions); this.sessions = map; } catch ( Exception x ) { @@ -183,7 +183,8 @@ public class BackupManager extends Clust setState(LifecycleState.STOPPING); if (sessions instanceof LazyReplicatedMap) { - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap map = + (LazyReplicatedMap)sessions; map.breakdown(); } @@ -234,15 +235,16 @@ public class BackupManager extends Clust @Override public int getActiveSessionsFull() { - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap map = + (LazyReplicatedMap)sessions; return map.sizeFull(); } @Override public Set getSessionIdsFull() { Set sessionIds = new HashSet(); - LazyReplicatedMap map = (LazyReplicatedMap)sessions; - @SuppressWarnings("unchecked") // sessions is of type Map + LazyReplicatedMap map = + (LazyReplicatedMap)sessions; Iterator keys = map.keySetFull().iterator(); while (keys.hasNext()) { sessionIds.add(keys.next()); Modified: tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java Thu Dec 22 16:27:02 2011 @@ -53,7 +53,10 @@ import org.apache.juli.logging.LogFactor * @author Filip Hanik * @version 1.0 */ -public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements RpcCallback, ChannelListener, MembershipListener, Heartbeat { +public abstract class AbstractReplicatedMap + implements Map, Serializable, RpcCallback, ChannelListener, + MembershipListener, Heartbeat { + private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(AbstractReplicatedMap.class); @@ -77,6 +80,8 @@ public abstract class AbstractReplicated //------------------------------------------------------------------------------ // INSTANCE VARIABLES //------------------------------------------------------------------------------ + private final ConcurrentHashMap> innerMap; + protected abstract int getStateMessageType(); @@ -172,7 +177,7 @@ public abstract class AbstractReplicated float loadFactor, int channelSendOptions, ClassLoader[] cls) { - super(initialCapacity, loadFactor, 15); + innerMap = new ConcurrentHashMap>(initialCapacity, loadFactor, 15); init(owner, channel, mapContextName, timeout, channelSendOptions, cls); } @@ -345,7 +350,7 @@ public abstract class AbstractReplicated this.rpcChannel = null; this.channel = null; this.mapMembers.clear(); - super.clear(); + innerMap.clear(); this.stateTransferred = false; this.externalLoaders = null; } @@ -359,7 +364,8 @@ public abstract class AbstractReplicated public boolean equals(Object o) { if ( !(o instanceof AbstractReplicatedMap)) return false; if ( !(o.getClass().equals(this.getClass())) ) return false; - AbstractReplicatedMap other = (AbstractReplicatedMap)o; + @SuppressWarnings("unchecked") + AbstractReplicatedMap other = (AbstractReplicatedMap)o; return Arrays.equals(mapContextName,other.mapContextName); } @@ -397,7 +403,7 @@ public abstract class AbstractReplicated public void replicate(Object key, boolean complete) { if ( log.isTraceEnabled() ) log.trace("Replicate invoked on key:"+key); - MapEntry entry = (MapEntry)super.get(key); + MapEntry entry = innerMap.get(key); if ( entry == null ) return; if ( !entry.isSerializable() ) return; if (entry.isPrimary() && entry.getBackupNodes()!= null && entry.getBackupNodes().length > 0) { @@ -458,7 +464,7 @@ public abstract class AbstractReplicated * @param complete boolean */ public void replicate(boolean complete) { - Iterator> i = super.entrySet().iterator(); + Iterator>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = i.next(); replicate(e.getKey(), complete); @@ -522,7 +528,7 @@ public abstract class AbstractReplicated //backup request if (mapmsg.getMsgType() == MapMessage.MSG_RETRIEVE_BACKUP) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry entry = innerMap.get(mapmsg.getKey()); if (entry == null || (!entry.isSerializable()) )return null; mapmsg.setValue( (Serializable) entry.getValue()); return mapmsg; @@ -532,10 +538,10 @@ public abstract class AbstractReplicated if (mapmsg.getMsgType() == MapMessage.MSG_STATE || mapmsg.getMsgType() == MapMessage.MSG_STATE_COPY) { synchronized (stateMutex) { //make sure we dont do two things at the same time ArrayList list = new ArrayList(); - Iterator> i = super.entrySet().iterator(); + Iterator>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + MapEntry entry = innerMap.get(e.getKey()); if ( entry != null && entry.isSerializable() ) { boolean copy = (mapmsg.getMsgType() == MapMessage.MSG_STATE_COPY); MapMessage me = new MapMessage(mapContextName, @@ -580,6 +586,7 @@ public abstract class AbstractReplicated } } + @SuppressWarnings("unchecked") @Override public void messageReceived(Serializable msg, Member sender) { if (! (msg instanceof MapMessage)) return; @@ -609,14 +616,14 @@ public abstract class AbstractReplicated } if (mapmsg.getMsgType() == MapMessage.MSG_PROXY) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry entry = innerMap.get(mapmsg.getKey()); if ( entry==null ) { - entry = new MapEntry(mapmsg.getKey(), mapmsg.getValue()); + entry = new MapEntry((K) mapmsg.getKey(), (V) mapmsg.getValue()); entry.setBackup(false); entry.setProxy(true); entry.setBackupNodes(mapmsg.getBackupNodes()); entry.setPrimary(mapmsg.getPrimary()); - super.put(entry.getKey(), entry); + innerMap.put(entry.getKey(), entry); } else { entry.setProxy(true); entry.setBackup(false); @@ -626,13 +633,13 @@ public abstract class AbstractReplicated } if (mapmsg.getMsgType() == MapMessage.MSG_REMOVE) { - super.remove(mapmsg.getKey()); + innerMap.remove(mapmsg.getKey()); } if (mapmsg.getMsgType() == MapMessage.MSG_BACKUP || mapmsg.getMsgType() == MapMessage.MSG_COPY) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry entry = innerMap.get(mapmsg.getKey()); if (entry == null) { - entry = new MapEntry(mapmsg.getKey(), mapmsg.getValue()); + entry = new MapEntry((K) mapmsg.getKey(), (V) mapmsg.getValue()); entry.setBackup(mapmsg.getMsgType() == MapMessage.MSG_BACKUP); entry.setProxy(false); entry.setBackupNodes(mapmsg.getBackupNodes()); @@ -657,18 +664,18 @@ public abstract class AbstractReplicated diff.unlock(); } } else { - if ( mapmsg.getValue()!=null ) entry.setValue(mapmsg.getValue()); + if ( mapmsg.getValue()!=null ) entry.setValue((V) mapmsg.getValue()); ((ReplicatedMapEntry)entry.getValue()).setOwner(getMapOwner()); } //end if } else if (mapmsg.getValue() instanceof ReplicatedMapEntry) { ReplicatedMapEntry re = (ReplicatedMapEntry)mapmsg.getValue(); re.setOwner(getMapOwner()); - entry.setValue(re); + entry.setValue((V) re); } else { - if ( mapmsg.getValue()!=null ) entry.setValue(mapmsg.getValue()); + if ( mapmsg.getValue()!=null ) entry.setValue((V) mapmsg.getValue()); } //end if } //end if - super.put(entry.getKey(), entry); + innerMap.put(entry.getKey(), entry); } //end if } @@ -695,10 +702,10 @@ public abstract class AbstractReplicated } if ( memberAdded ) { synchronized (stateMutex) { - Iterator> i = super.entrySet().iterator(); + Iterator>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { - Map.Entry e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + Map.Entry> e = i.next(); + MapEntry entry = innerMap.get(e.getKey()); if ( entry == null ) continue; if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) { try { @@ -749,10 +756,10 @@ public abstract class AbstractReplicated } } - Iterator> i = super.entrySet().iterator(); + Iterator>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { - Map.Entry e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + Map.Entry> e = i.next(); + MapEntry entry = innerMap.get(e.getKey()); if (entry==null) continue; if (entry.isPrimary() && inSet(member,entry.getBackupNodes())) { if (log.isDebugEnabled()) log.debug("[1] Primary choosing a new backup"); @@ -838,11 +845,11 @@ public abstract class AbstractReplicated * @return Object */ @Override - public Object remove(Object key) { + public V remove(Object key) { return remove(key,true); } - public Object remove(Object key, boolean notify) { - MapEntry entry = (MapEntry)super.remove(key); + public V remove(Object key, boolean notify) { + MapEntry entry = innerMap.remove(key); try { if (getMapMembers().length > 0 && notify) { @@ -855,13 +862,14 @@ public abstract class AbstractReplicated return entry!=null?entry.getValue():null; } - public MapEntry getInternal(Object key) { - return (MapEntry)super.get(key); + public MapEntry getInternal(Object key) { + return innerMap.get(key); } + @SuppressWarnings("unchecked") @Override - public Object get(Object key) { - MapEntry entry = (MapEntry)super.get(key); + public V get(Object key) { + MapEntry entry = innerMap.get(key); if (log.isTraceEnabled()) log.trace("Requesting id:"+key+" entry:"+entry); if ( entry == null ) return null; if ( !entry.isPrimary() ) { @@ -886,7 +894,7 @@ public abstract class AbstractReplicated ReplicatedMapEntry val = (ReplicatedMapEntry)entry.getValue(); val.setOwner(getMapOwner()); } - if ( msg.getValue()!=null ) entry.setValue(msg.getValue()); + if ( msg.getValue()!=null ) entry.setValue((V) msg.getValue()); } if (entry.isBackup()) { //select a new backup node @@ -924,17 +932,17 @@ public abstract class AbstractReplicated System.out.println("\nDEBUG MAP:"+header); System.out.println("Map[" + new String(mapContextName, CHARSET_ISO_8859_1) + - ", Map Size:" + super.size()); + ", Map Size:" + innerMap.size()); Member[] mbrs = getMapMembers(); for ( int i=0; iget(key) - * will make this entry primary for the group - * @param key Object - * @return boolean - */ - @Override - public boolean containsKey(Object key) { - return super.containsKey(key); - } + * Returns true if the key has an entry in the map. + * The entry can be a proxy or a backup entry, invoking get(key) + * will make this entry primary for the group + * @param key Object + * @return boolean + */ + @Override + public boolean containsKey(Object key) { + return innerMap.containsKey(key); + } - @Override - public Object put(Object key, Object value) { - return put(key,value,true); - } + @Override + public V put(K key, V value) { + return put(key, value, true); + } - public Object put(Object key, Object value, boolean notify) { - MapEntry entry = new MapEntry(key,value); - entry.setBackup(false); - entry.setProxy(false); - entry.setPrimary(channel.getLocalMember(false)); + public V put(K key, V value, boolean notify) { + MapEntry entry = new MapEntry(key,value); + entry.setBackup(false); + entry.setProxy(false); + entry.setPrimary(channel.getLocalMember(false)); - Object old = null; + V old = null; - //make sure that any old values get removed - if ( containsKey(key) ) old = remove(key); - try { - if ( notify ) { - Member[] backup = publishEntryInfo(key, value); - entry.setBackupNodes(backup); - } - } catch (ChannelException x) { - log.error("Unable to replicate out data for a LazyReplicatedMap.put operation", x); + //make sure that any old values get removed + if ( containsKey(key) ) old = remove(key); + try { + if ( notify ) { + Member[] backup = publishEntryInfo(key, value); + entry.setBackupNodes(backup); } - super.put(key,entry); - return old; + } catch (ChannelException x) { + log.error("Unable to replicate out data for a LazyReplicatedMap.put operation", x); } + innerMap.put(key,entry); + return old; + } - /** - * Copies all values from one map to this instance - * @param m Map - */ - @Override - public void putAll(Map m) { - Iterator> i = m.entrySet().iterator(); - while ( i.hasNext() ) { - Map.Entry entry = i.next(); - put(entry.getKey(),entry.getValue()); - } + /** + * Copies all values from one map to this instance + * @param m Map + */ + @Override + public void putAll(Map m) { + Iterator i = m.entrySet().iterator(); + while ( i.hasNext() ) { + @SuppressWarnings("unchecked") + Map.Entry entry = (Map.Entry) i.next(); + put(entry.getKey(),entry.getValue()); } + } - @Override - public void clear() { - clear(true); - } + @Override + public void clear() { + clear(true); + } - public void clear(boolean notify) { - if ( notify ) { - //only delete active keys - Iterator keys = keySet().iterator(); - while (keys.hasNext()) - remove(keys.next()); - } else { - super.clear(); - } + public void clear(boolean notify) { + if ( notify ) { + //only delete active keys + Iterator keys = keySet().iterator(); + while (keys.hasNext()) + remove(keys.next()); + } else { + innerMap.clear(); } + } - @Override - public boolean containsValue(Object value) { - if ( value == null ) { - return super.containsValue(value); - } else { - Iterator> i = super.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); - if (entry!=null && entry.isActive() && value.equals(entry.getValue())) return true; - }//while - return false; - }//end if - } + @Override + public boolean containsValue(Object value) { + if ( value == null ) { + return innerMap.containsValue(value); + } else { + Iterator>> i = innerMap.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry> e = i.next(); + MapEntry entry = innerMap.get(e.getKey()); + if (entry!=null && entry.isActive() && value.equals(entry.getValue())) return true; + }//while + return false; + }//end if + } - @Override - public Object clone() { - throw new UnsupportedOperationException("This operation is not valid on a replicated map"); - } + @Override + 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(); - } + /** + * 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 innerMap.entrySet(); + } - public Set keySetFull() { - return super.keySet(); - } + public Set keySetFull() { + return innerMap.keySet(); + } - public int sizeFull() { - return super.size(); - } + public int sizeFull() { + return innerMap.size(); + } - @Override - public Set entrySet() { - LinkedHashSet set = new LinkedHashSet(super.size()); - Iterator> i = super.entrySet().iterator(); - while ( i.hasNext() ) { - Map.Entry e = i.next(); - Object key = e.getKey(); - MapEntry entry = (MapEntry)super.get(key); - if ( entry != null && entry.isActive() ) { - set.add(new MapEntry(key, entry.getValue())); - } + @Override + public Set> entrySet() { + LinkedHashSet> set = new LinkedHashSet>(innerMap.size()); + Iterator>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry e = i.next(); + Object key = e.getKey(); + MapEntry entry = innerMap.get(key); + if ( entry != null && entry.isActive() ) { + set.add(entry); } - return Collections.unmodifiableSet(set); } + return Collections.unmodifiableSet(set); + } - @Override - 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 = i.next(); - Object key = e.getKey(); - MapEntry entry = (MapEntry)super.get(key); - if ( entry!=null && entry.isActive() ) set.add(key); - } - return Collections.unmodifiableSet(set); - + @Override + public Set keySet() { + //todo implement + //should only return keys where this is active. + LinkedHashSet set = new LinkedHashSet(innerMap.size()); + Iterator>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry> e = i.next(); + K key = e.getKey(); + MapEntry entry = innerMap.get(key); + if ( entry!=null && entry.isActive() ) set.add(key); } + return Collections.unmodifiableSet(set); + + } - @Override - public int size() { - //todo, implement a counter variable instead - //only count active members in this node - int counter = 0; - Iterator> it = super.entrySet().iterator(); - while (it!=null && it.hasNext() ) { - Map.Entry e = it.next(); - if ( e != null ) { - MapEntry entry = (MapEntry) super.get(e.getKey()); - if (entry!=null && entry.isActive() && entry.getValue() != null) counter++; - } + @Override + public int size() { + //todo, implement a counter variable instead + //only count active members in this node + int counter = 0; + Iterator>> it = innerMap.entrySet().iterator(); + while (it!=null && it.hasNext() ) { + Map.Entry e = it.next(); + if ( e != null ) { + MapEntry entry = innerMap.get(e.getKey()); + if (entry!=null && entry.isActive() && entry.getValue() != null) counter++; } - return counter; } + return counter; + } - @Override - public boolean isEmpty() { - return size()==0; - } + @Override + public boolean isEmpty() { + return size()==0; + } - @Override - public Collection values() { - ArrayList values = new ArrayList(); - Iterator> i = super.entrySet().iterator(); - while ( i.hasNext() ) { - Map.Entry e = i.next(); - MapEntry entry = (MapEntry)super.get(e.getKey()); - if (entry!=null && entry.isActive() && entry.getValue()!=null) values.add(entry.getValue()); - } - return Collections.unmodifiableCollection(values); + @Override + public Collection values() { + ArrayList values = new ArrayList(); + Iterator>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry> e = i.next(); + MapEntry entry = innerMap.get(e.getKey()); + if (entry!=null && entry.isActive() && entry.getValue()!=null) values.add(entry.getValue()); } + return Collections.unmodifiableCollection(values); + } //------------------------------------------------------------------------------ // Map Entry class //------------------------------------------------------------------------------ - public static class MapEntry implements Map.Entry { + public static class MapEntry implements Map.Entry { private boolean backup; private boolean proxy; private Member[] backupNodes; private Member primary; - private Object key; - private Object value; + private K key; + private V value; - public MapEntry(Object key, Object value) { + public MapEntry(K key, V value) { setKey(key); setValue(value); @@ -1190,24 +1199,24 @@ public abstract class AbstractReplicated } @Override - public Object getValue() { + public V getValue() { return value; } @Override - public Object setValue(Object value) { - Object old = this.value; + public V setValue(V value) { + V old = this.value; this.value = value; return old; } @Override - public Object getKey() { + public K getKey() { return key; } - public Object setKey(Object key) { - Object old = this.key; + public K setKey(K key) { + K old = this.key; this.key = key; return old; } @@ -1231,6 +1240,7 @@ public abstract class AbstractReplicated * @throws IOException * @throws ClassNotFoundException */ + @SuppressWarnings("unchecked") public void apply(byte[] data, int offset, int length, boolean diff) throws IOException, ClassNotFoundException { if (isDiffable() && diff) { ReplicatedMapEntry rentry = (ReplicatedMapEntry) value; @@ -1244,7 +1254,7 @@ public abstract class AbstractReplicated value = null; proxy = true; } else { - value = XByteBuffer.deserialize(data, offset, length); + value = (V) XByteBuffer.deserialize(data, offset, length); } } Modified: tomcat/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java Thu Dec 22 16:27:02 2011 @@ -63,7 +63,7 @@ import org.apache.juli.logging.LogFactor * @author Filip Hanik * @version 1.0 */ -public class LazyReplicatedMap extends AbstractReplicatedMap { +public class LazyReplicatedMap extends AbstractReplicatedMap { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(LazyReplicatedMap.class); Modified: tomcat/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java (original) +++ tomcat/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java Thu Dec 22 16:27:02 2011 @@ -46,7 +46,7 @@ import org.apache.catalina.tribes.Member * TODO memberDisappeared, should do nothing except change map membership * by default it relocates the primary objects */ -public class ReplicatedMap extends AbstractReplicatedMap { +public class ReplicatedMap extends AbstractReplicatedMap { private static final long serialVersionUID = 1L; Modified: tomcat/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java?rev=1222329&r1=1222328&r2=1222329&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java (original) +++ tomcat/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java Thu Dec 22 16:27:02 2011 @@ -56,7 +56,7 @@ public class MapDemo implements ChannelL /** * The Map containing the replicated data */ - protected LazyReplicatedMap map; + protected LazyReplicatedMap map; /** * Table to be displayed in Swing @@ -70,7 +70,8 @@ public class MapDemo implements ChannelL */ public MapDemo(Channel channel, String mapName ) { //instantiate the replicated map - map = new LazyReplicatedMap(null,channel,5000, mapName,null); + map = new LazyReplicatedMap(null, channel, 5000, + mapName, null); //create a gui, name it with the member name of this JVM table = SimpleTableDemo.createAndShowGUI(map,channel.getLocalMember(false).getName()); //add ourself as a listener for messages @@ -212,7 +213,7 @@ public class MapDemo implements ChannelL private static int WIDTH = 550; - private LazyReplicatedMap map; + private LazyReplicatedMap map; private boolean DEBUG = false; AbstractTableModel dataModel = new AbstractTableModel() { @@ -254,7 +255,8 @@ public class MapDemo implements ChannelL if ( row == 0 ) return columnNames[col]; Object[] keys = map.keySetFull().toArray(); String key = (String)keys [row-1]; - LazyReplicatedMap.MapEntry entry = map.getInternal(key); + LazyReplicatedMap.MapEntry entry = + map.getInternal(key); switch (col) { case 0: return String.valueOf(row); case 1: return entry.getKey(); @@ -281,7 +283,7 @@ public class MapDemo implements ChannelL JTextField txtChangeValue = new JTextField(20); JTable table = null; - public SimpleTableDemo(LazyReplicatedMap map) { + public SimpleTableDemo(LazyReplicatedMap map) { super(); this.map = map; @@ -370,7 +372,7 @@ public class MapDemo implements ChannelL } if ( "change".equals(e.getActionCommand()) ) { System.out.println("Change key:"+txtChangeKey.getText()+" value:"+txtChangeValue.getText()); - StringBuilder buf = (StringBuilder)map.get(txtChangeKey.getText()); + StringBuilder buf = map.get(txtChangeKey.getText()); if ( buf!=null ) { buf.delete(0,buf.length()); buf.append(txtChangeValue.getText()); @@ -499,7 +501,8 @@ public class MapDemo implements ChannelL * this method should be invoked from the * event-dispatching thread. */ - public static SimpleTableDemo createAndShowGUI(LazyReplicatedMap map, String title) { + public static SimpleTableDemo createAndShowGUI( + LazyReplicatedMap map, String title) { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org