Author: markt Date: Thu Apr 10 23:21:19 2014 New Revision: 1586500 URL: http://svn.apache.org/r1586500 Log: Backport refactoring of AbstractReplicatedMap to implement Map rather than extend ConcurrentHashMap to enable Tomcat 7 to be built with Java 8.
Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/BackupManager.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java tomcat/tc7.0.x/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1222329 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java Thu Apr 10 23:21:19 2014 @@ -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; @@ -61,8 +61,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<String,Object> map = + new ReplicatedMap<String,Object>(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()); @@ -86,10 +88,10 @@ public class ReplicatedContext extends S super.stopInternal(); - AbstractMap<String,Object> map = - ((ReplApplContext)this.context).getAttributeMap(); + Map<String,Object> map = + ((ReplApplContext)this.context).getAttributeMap(); if ( map!=null && map instanceof ReplicatedMap) { - ((ReplicatedMap)map).breakdown(); + ((ReplicatedMap<?,?>)map).breakdown(); } } @@ -145,10 +147,10 @@ public class ReplicatedContext extends S return super.getFacade(); } - public AbstractMap<String,Object> getAttributeMap() { - return (AbstractMap<String,Object>)this.attributes; + public Map<String,Object> getAttributeMap() { + return this.attributes; } - public void setAttributeMap(AbstractMap<String,Object> map) { + public void setAttributeMap(Map<String,Object> map) { this.attributes = map; } Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/BackupManager.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/BackupManager.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/BackupManager.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/ha/session/BackupManager.java Thu Apr 10 23:21:19 2014 @@ -115,7 +115,8 @@ public class BackupManager extends Clust @Override public ClusterMessage requestCompleted(String sessionId) { if (!getState().isAvailable()) return null; - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap<String,Session> map = + (LazyReplicatedMap<String,Session>)sessions; map.replicate(sessionId,false); return null; } @@ -159,7 +160,6 @@ public class BackupManager extends Clust * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ - @SuppressWarnings("unchecked") @Override protected synchronized void startInternal() throws LifecycleException { @@ -167,12 +167,10 @@ public class BackupManager extends Clust try { if (cluster == null) throw new LifecycleException(sm.getString("backupManager.noCluster", getName())); - LazyReplicatedMap map = new LazyReplicatedMap(this, - cluster.getChannel(), - rpcTimeout, - getMapName(), - getClassLoaders(), - terminateOnStartFailure); + LazyReplicatedMap<String,Session> map = + new LazyReplicatedMap<String,Session>(this, + cluster.getChannel(), rpcTimeout, getMapName(), + getClassLoaders(), terminateOnStartFailure); map.setChannelSendOptions(mapSendOptions); this.sessions = map; } catch ( Exception x ) { @@ -208,7 +206,8 @@ public class BackupManager extends Clust setState(LifecycleState.STOPPING); if (sessions instanceof LazyReplicatedMap) { - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap<String,Session> map = + (LazyReplicatedMap<String,Session>)sessions; map.breakdown(); } @@ -267,15 +266,16 @@ public class BackupManager extends Clust @Override public int getActiveSessionsFull() { - LazyReplicatedMap map = (LazyReplicatedMap)sessions; + LazyReplicatedMap<String,Session> map = + (LazyReplicatedMap<String,Session>)sessions; return map.sizeFull(); } @Override public Set<String> getSessionIdsFull() { Set<String> sessionIds = new HashSet<String>(); - LazyReplicatedMap map = (LazyReplicatedMap)sessions; - @SuppressWarnings("unchecked") // sessions is of type Map<String, Session> + LazyReplicatedMap<String,Session> map = + (LazyReplicatedMap<String,Session>)sessions; Iterator<String> keys = map.keySetFull().iterator(); while (keys.hasNext()) { sessionIds.add(keys.next()); Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java Thu Apr 10 23:21:19 2014 @@ -53,8 +53,10 @@ import org.apache.juli.logging.LogFactor * @author Filip Hanik * @version 1.0 */ -@SuppressWarnings("rawtypes") -public abstract class AbstractReplicatedMap extends ConcurrentHashMap implements RpcCallback, ChannelListener, MembershipListener, Heartbeat { +public abstract class AbstractReplicatedMap<K,V> + implements Map<K,V>, Serializable, RpcCallback, ChannelListener, + MembershipListener, Heartbeat { + private static final long serialVersionUID = 1L; private final Log log = LogFactory.getLog(AbstractReplicatedMap.class); @@ -78,6 +80,8 @@ public abstract class AbstractReplicated //------------------------------------------------------------------------------ // INSTANCE VARIABLES //------------------------------------------------------------------------------ + private final ConcurrentHashMap<K, MapEntry<K,V>> innerMap; + protected abstract int getStateMessageType(); @@ -174,7 +178,7 @@ public abstract class AbstractReplicated int channelSendOptions, ClassLoader[] cls, boolean terminate) { - super(initialCapacity, loadFactor, 15); + innerMap = new ConcurrentHashMap<K,MapEntry<K, V>>(initialCapacity, loadFactor, 15); init(owner, channel, mapContextName, timeout, channelSendOptions, cls, terminate); } @@ -282,7 +286,7 @@ public abstract class AbstractReplicated Member[] members = mapMembers.keySet().toArray(new Member[mapMembers.size()]); long now = System.currentTimeMillis(); for (Member member : members) { - long access = mapMembers.get(member); + long access = mapMembers.get(member).longValue(); if ( (now - access) > timeout ) { memberDisappeared(member); } @@ -350,7 +354,7 @@ public abstract class AbstractReplicated this.rpcChannel = null; this.channel = null; this.mapMembers.clear(); - super.clear(); + innerMap.clear(); this.stateTransferred = false; this.externalLoaders = null; } @@ -364,7 +368,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<K,V> other = (AbstractReplicatedMap<K,V>)o; return Arrays.equals(mapContextName,other.mapContextName); } @@ -402,7 +407,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<K,V> entry = innerMap.get(key); if ( entry == null ) return; if ( !entry.isSerializable() ) return; if (entry.isPrimary() && entry.getBackupNodes()!= null && entry.getBackupNodes().length > 0) { @@ -420,9 +425,8 @@ public abstract class AbstractReplicated return; } //check to see if the message is diffable - boolean diff = rentry != null && rentry.isDiffable(); MapMessage msg = null; - if (diff && (isDirty || complete)) { + if (rentry != null && rentry.isDiffable() && (isDirty || complete)) { try { rentry.lock(); //construct a diff message @@ -471,8 +475,7 @@ public abstract class AbstractReplicated * @param complete boolean */ public void replicate(boolean complete) { - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = super.entrySet().iterator(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry<?,?> e = i.next(); replicate(e.getKey(), complete); @@ -536,7 +539,7 @@ public abstract class AbstractReplicated //backup request if (mapmsg.getMsgType() == MapMessage.MSG_RETRIEVE_BACKUP) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry<K,V> entry = innerMap.get(mapmsg.getKey()); if (entry == null || (!entry.isSerializable()) )return null; mapmsg.setValue( (Serializable) entry.getValue()); return mapmsg; @@ -546,11 +549,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<MapMessage> list = new ArrayList<MapMessage>(); - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = super.entrySet().iterator(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry<?,?> e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + MapEntry<K,V> entry = innerMap.get(e.getKey()); if ( entry != null && entry.isSerializable() ) { boolean copy = (mapmsg.getMsgType() == MapMessage.MSG_STATE_COPY); MapMessage me = new MapMessage(mapContextName, @@ -625,14 +627,14 @@ public abstract class AbstractReplicated } if (mapmsg.getMsgType() == MapMessage.MSG_PROXY) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry<K,V> entry = innerMap.get(mapmsg.getKey()); if ( entry==null ) { - entry = new MapEntry(mapmsg.getKey(), mapmsg.getValue()); + entry = new MapEntry<K,V>((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); @@ -642,13 +644,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<K,V> entry = innerMap.get(mapmsg.getKey()); if (entry == null) { - entry = new MapEntry(mapmsg.getKey(), mapmsg.getValue()); + entry = new MapEntry<K,V>((K) mapmsg.getKey(), (V) mapmsg.getValue()); entry.setBackup(mapmsg.getMsgType() == MapMessage.MSG_BACKUP); entry.setProxy(false); entry.setBackupNodes(mapmsg.getBackupNodes()); @@ -673,22 +675,22 @@ 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 if (mapmsg.getMsgType() == MapMessage.MSG_ACCESS) { - MapEntry entry = (MapEntry)super.get(mapmsg.getKey()); + MapEntry<K, V> entry = innerMap.get(mapmsg.getKey()); if (entry != null) { entry.setBackupNodes(mapmsg.getBackupNodes()); entry.setPrimary(mapmsg.getPrimary()); @@ -722,11 +724,10 @@ public abstract class AbstractReplicated } if ( memberAdded ) { synchronized (stateMutex) { - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = super.entrySet().iterator(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { - Map.Entry<?,?> e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + Map.Entry<K,MapEntry<K,V>> e = i.next(); + MapEntry<K,V> entry = innerMap.get(e.getKey()); if ( entry == null ) continue; if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) { try { @@ -780,11 +781,10 @@ public abstract class AbstractReplicated if (log.isInfoEnabled()) log.info("Member["+member+"] disappeared. Related map entries will be relocated to the new node."); long start = System.currentTimeMillis(); - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = super.entrySet().iterator(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); while (i.hasNext()) { - Map.Entry<?,?> e = i.next(); - MapEntry entry = (MapEntry) super.get(e.getKey()); + Map.Entry<K,MapEntry<K,V>> e = i.next(); + MapEntry<K,V> 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"); @@ -872,11 +872,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<K,V> entry = innerMap.remove(key); try { if (getMapMembers().length > 0 && notify) { @@ -889,13 +889,14 @@ public abstract class AbstractReplicated return entry!=null?entry.getValue():null; } - public MapEntry getInternal(Object key) { - return (MapEntry)super.get(key); + public MapEntry<K,V> 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<K,V> entry = innerMap.get(key); if (log.isTraceEnabled()) log.trace("Requesting id:"+key+" entry:"+entry); if ( entry == null ) return null; if ( !entry.isPrimary() ) { @@ -920,7 +921,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 @@ -958,18 +959,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; i<mbrs.length;i++ ) { System.out.println("Mbr["+(i+1)+"="+mbrs[i].getName()); } - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = super.entrySet().iterator(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); int cnt = 0; while (i.hasNext()) { Map.Entry<?,?> e = i.next(); - System.out.println( (++cnt) + ". " + super.get(e.getKey())); + System.out.println( (++cnt) + ". " + innerMap.get(e.getKey())); } System.out.println("EndMap]\n\n"); }catch ( Exception ignore) { @@ -978,197 +978,191 @@ public abstract class AbstractReplicated } /** - * 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 - */ - @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 <code>get(key)</code> + * 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); + } - @SuppressWarnings("unchecked") - 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<K,V> entry = new MapEntry<K,V>(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) { + /** + * Copies all values from one map to this instance + * @param m Map + */ + @Override + public void putAll(Map<? extends K, ? extends V> m) { + Iterator<?> i = m.entrySet().iterator(); + while ( i.hasNext() ) { @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> i = m.entrySet().iterator(); - while ( i.hasNext() ) { - Map.Entry<?,?> entry = i.next(); - put(entry.getKey(),entry.getValue()); - } + Map.Entry<K,V> entry = (Map.Entry<K,V>) 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<Object> keys = keySet().iterator(); - while (keys.hasNext()) - remove(keys.next()); - } else { - super.clear(); - } + public void clear(boolean notify) { + if ( notify ) { + //only delete active keys + Iterator<K> 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 { - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> 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<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry<K,MapEntry<K,V>> e = i.next(); + MapEntry<K,V> 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<Map.Entry<K,MapEntry<K,V>>> entrySetFull() { + return innerMap.entrySet(); + } - public Set keySetFull() { - return super.keySet(); - } + public Set<K> keySetFull() { + return innerMap.keySet(); + } - public int sizeFull() { - return super.size(); - } + public int sizeFull() { + return innerMap.size(); + } - @Override - public Set<MapEntry> entrySet() { - LinkedHashSet<MapEntry> set = new LinkedHashSet<MapEntry>(super.size()); - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> 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<Map.Entry<K,V>> entrySet() { + LinkedHashSet<Map.Entry<K,V>> set = new LinkedHashSet<Map.Entry<K,V>>(innerMap.size()); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry<?,?> e = i.next(); + Object key = e.getKey(); + MapEntry<K,V> entry = innerMap.get(key); + if ( entry != null && entry.isActive() ) { + set.add(entry); } - return Collections.unmodifiableSet(set); } + return Collections.unmodifiableSet(set); + } - @Override - public Set<Object> keySet() { - //todo implement - //should only return keys where this is active. - LinkedHashSet<Object> set = new LinkedHashSet<Object>(super.size()); - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> 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<K> keySet() { + //todo implement + //should only return keys where this is active. + LinkedHashSet<K> set = new LinkedHashSet<K>(innerMap.size()); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry<K,MapEntry<K,V>> e = i.next(); + K key = e.getKey(); + MapEntry<K,V> 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; - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> 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<Map.Entry<K,MapEntry<K,V>>> it = innerMap.entrySet().iterator(); + while (it!=null && it.hasNext() ) { + Map.Entry<?,?> e = it.next(); + if ( e != null ) { + MapEntry<K,V> 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<Object> values() { - ArrayList<Object> values = new ArrayList<Object>(); - @SuppressWarnings("unchecked") - Iterator<Map.Entry<?,?>> 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<V> values() { + ArrayList<V> values = new ArrayList<V>(); + Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry<K,MapEntry<K,V>> e = i.next(); + MapEntry<K,V> 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<Object,Object> { + public static class MapEntry<K,V> implements Map.Entry<K,V> { 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); @@ -1232,24 +1226,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; } @@ -1273,6 +1267,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; @@ -1286,7 +1281,7 @@ public abstract class AbstractReplicated value = null; proxy = true; } else { - value = XByteBuffer.deserialize(data, offset, length); + value = (V) XByteBuffer.deserialize(data, offset, length); } } @@ -1478,7 +1473,7 @@ public abstract class AbstractReplicated * @deprecated Unused - will be removed in 8.0.x */ @Deprecated - protected Member[] readMembers(ObjectInput in) throws IOException, ClassNotFoundException { + protected Member[] readMembers(ObjectInput in) throws IOException { int nodecount = in.readInt(); Member[] members = new Member[nodecount]; for ( int i=0; i<members.length; i++ ) { Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/LazyReplicatedMap.java Thu Apr 10 23:21:19 2014 @@ -63,7 +63,7 @@ import org.apache.juli.logging.LogFactor * @author Filip Hanik * @version 1.0 */ -public class LazyReplicatedMap extends AbstractReplicatedMap { +public class LazyReplicatedMap<K,V> extends AbstractReplicatedMap<K,V> { private static final long serialVersionUID = 1L; private final Log log = LogFactory.getLog(LazyReplicatedMap.class); Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/tribes/tipis/ReplicatedMap.java Thu Apr 10 23:21:19 2014 @@ -46,7 +46,7 @@ import org.apache.catalina.tribes.Member * @author Filip Hanik * @version 1.0 */ -public class ReplicatedMap extends AbstractReplicatedMap { +public class ReplicatedMap<K,V> extends AbstractReplicatedMap<K,V> { private static final long serialVersionUID = 1L; Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java (original) +++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/tribes/demos/MapDemo.java Thu Apr 10 23:21:19 2014 @@ -56,7 +56,7 @@ public class MapDemo implements ChannelL /** * The Map containing the replicated data */ - protected LazyReplicatedMap map; + protected LazyReplicatedMap<String,StringBuilder> 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<String,StringBuilder>(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<String,StringBuilder> 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<String,StringBuilder> 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<String,StringBuilder> 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<String,StringBuilder> map, String title) { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1586500&r1=1586499&r2=1586500&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Apr 10 23:21:19 2014 @@ -112,6 +112,11 @@ <code>SimpleTcpCluster.unregisterClusterValve</code> is called. Set null than cluster instance for cleanup. (kfujino) </fix> + <scode> + Backport refactoring of <code>AbstractReplicatedMap</code> to implement + <code>Map</code> rather than extend <code>ConcurrentHashMap</code> to + enable Tomcat 7 to be built with Java 8. (markt) + </scode> </changelog> </subsection> <subsection name="WebSocket"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org