river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1182211 [1/2] - /river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/
Date Wed, 12 Oct 2011 06:11:48 GMT
Author: peter_firmstone
Date: Wed Oct 12 06:11:47 2011
New Revision: 1182211

URL: http://svn.apache.org/viewvc?rev=1182211&view=rev
Log:
Creating some simple Referrer objects, that don't extend java Reference classes, these objects are short lived for lookups and reads, not shared with other threads.  The jvm (1.6 and later) will likely only create these objects using stack memory, avoiding cache misses.

Also includes some serialisation improvements

Added:
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java
      - copied, changed from r1180582, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractSerializationOfRC.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialDataDefensiveCopy.java
      - copied, changed from r1180542, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerialDataReferenceCollection.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java   (with props)
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempIdentityReferrer.java   (with props)
Removed:
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractSerializationOfRC.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerialDataReferenceCollection.java
Modified:
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/CollectionWrapper.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ComparableReferrerWrapper.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntryFacadeConverter.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntrySetFacade.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingDeque.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingQueue.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollection.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMap.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceDeque.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceEntryFacade.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceFactory.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceList.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMap.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableMap.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableSet.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceProcessor.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceQueuingFactory.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializationFactory.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializedForm.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedMap.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedSet.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferencedQueue.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Referrer.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferrerWrapper.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceCollection.java
    river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java

Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java?rev=1182211&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java Wed Oct 12 06:11:47 2011
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.impl.util;
+
+import java.io.Serializable;
+
+/**
+ * This class exists purely for allowing a client with their own Collection
+ * implementation or Collection wrapper to perform custom serialisation of the 
+ * References by replacing the standard Referrer's with their own implementation.
+ * 
+ * During de-serialisation the client's Referrer can 
+ * perform any required de-serialisation defensive copying or integrity checks.
+ * 
+ * The client Referrer will be replaced after de-serialisation is complete.
+ * 
+ * The client doesn't need to implement this class, just Referrer.
+ * 
+ * @param <T> - the referent.
+ * @author peter
+ */
+abstract class AbstractReferrerWrapper<T> implements Referrer<T> {
+
+     AbstractReferrerWrapper() {
+    }
+
+    final void refresh(ReferenceQueuingFactory<T, Referrer<T>> rqf){
+        T object = get();
+        if (object != null){
+            refresh(rqf.referenced(object, true, false));
+        }
+    }
+    
+    /**
+     * This method is called after de-serialisation, to update the Referrer,
+     * the Ref type will be governed by the ReferenceCollection, the queue will 
+     * have also been defined.  
+     * 
+     * The object will be retrieved and encapsulated in the Referrer
+     * using the get() method.
+     * 
+     * @param r 
+     */
+    abstract void refresh(Referrer<T> r);
+
+    public String toString() {
+        return get().toString();
+    }
+
+    public void clear() {
+        getReference().clear();
+    }
+
+    public boolean enqueue() {
+        return getReference().enqueue();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o)  return true; // Same reference.
+        if (!(o instanceof Referrer))  return false;
+        return getReference().equals(o);
+    }
+
+    public final T get() {
+        return getReference().get();
+    }
+
+    /**
+     * @return the Referrer.
+     */
+    abstract Referrer<T> getReference();
+
+    @Override
+    public int hashCode() {
+        return getReference().hashCode();
+    }
+
+    public boolean isEnqueued() {
+        return getReference().isEnqueued();
+    }
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractReferrerWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/CollectionWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/CollectionWrapper.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/CollectionWrapper.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/CollectionWrapper.java Wed Oct 12 06:11:47 2011
@@ -18,7 +18,6 @@
 
 package org.apache.river.impl.util;
 
-import java.lang.ref.Reference;
 import java.util.AbstractCollection;
 import java.util.Collection;
 import java.util.Iterator;
@@ -31,11 +30,13 @@ public class CollectionWrapper<T> extend
     private final Collection<T> col;
     private final ReferenceQueuingFactory<T, Referrer<T>> rqf;
     private final boolean enque;
+    private final boolean temporary;
     
-    CollectionWrapper(Collection<T> col, ReferenceQueuingFactory<T, Referrer<T>> rqf, boolean enque){
+    CollectionWrapper(Collection<T> col, ReferenceQueuingFactory<T, Referrer<T>> rqf, boolean enque, boolean temporary){
         this.col = col;
         this.rqf = rqf;
         this.enque = enque;
+        this.temporary = temporary;
     }
 
     @Override
@@ -67,7 +68,7 @@ public class CollectionWrapper<T> extend
 
         @Override
         public Referrer<T> next() {
-            return rqf.referenced( iterator.next(), enque);
+            return rqf.referenced( iterator.next(), enque, temporary);
         }
 
         @Override

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ComparableReferrerWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ComparableReferrerWrapper.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ComparableReferrerWrapper.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ComparableReferrerWrapper.java Wed Oct 12 06:11:47 2011
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 package org.apache.river.impl.util;
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntryFacadeConverter.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntryFacadeConverter.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntryFacadeConverter.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntryFacadeConverter.java Wed Oct 12 06:11:47 2011
@@ -41,10 +41,10 @@ class EntryFacadeConverter<K,V> implemen
         return new ReferenceEntryFacade<K, V>(u, vrqf);
     }
 
-    public Entry<Referrer<K>, Referrer<V>> referenced(Entry<K,V> w, boolean enque) {
+    public Entry<Referrer<K>, Referrer<V>> referenced(Entry<K,V> w, boolean enque, boolean temporary) {
         // The entry could alread by a Referrer based Entry obscured by a facade.
         return new SimpleEntry<Referrer<K>, Referrer<V>>(
-            krqf.referenced(w.getKey(), enque), vrqf.referenced(w.getValue(), enque)
+            krqf.referenced(w.getKey(), enque, false), vrqf.referenced(w.getValue(), enque, false)
         );
         }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntrySetFacade.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntrySetFacade.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntrySetFacade.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/EntrySetFacade.java Wed Oct 12 06:11:47 2011
@@ -65,6 +65,6 @@ class EntrySetFacade<O, R> extends Abstr
     public boolean add(O e) {
         factory.processQueue();
         if ( e == null ) return false;
-        return set.add(factory.referenced(e, true));
+        return set.add(factory.referenced(e, true, false));
     }
     }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/RC.java Wed Oct 12 06:11:47 2011
@@ -123,10 +123,20 @@ import java.util.concurrent.ConcurrentNa
  * {@link Iterator} and {@link ListIterator} views preserve reference behaviour, all methods
  * are fully implemented and supported.
  * </p><p>
+ * Serialisation is supported, provided it is also supported by underlying
+ * collections.  Collections are not defensively copied during de-serialisation,
+ * due in part to an inability of determining whether a Comparator is
+ * used and in part, that if it is, it prevents Class.newInstance() construction.
+ * </p><p>
+ * Note that when a collection is first de-serialised, it's contents are
+ * strongly referenced, then changed to the correct reference type.  This
+ * will still occur, even if the Collection is immutable.
+ * </p><p>
  * RC stands for Reference Collection and is abbreviated due to the length of
  * generic parameter arguments typically required.
  * </p>
  * @see Ref
+ * @see Referrer
  * @see Reference
  * @author Peter Firmstone.
  */
@@ -158,6 +168,8 @@ public class RC {
     public static <T> Collection<T> collection(Collection<Referrer<T>> internal, Ref type){
         return new ReferenceCollection<T>(internal, type);
             }
+    
+    
             
     /**
      * Wrap a List for holding references so it appears as a List

Copied: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java (from r1180582, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractSerializationOfRC.java)
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java?p2=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java&p1=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractSerializationOfRC.java&r1=1180582&r2=1182211&rev=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/AbstractSerializationOfRC.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReadResolveCircularReferencesFix.java Wed Oct 12 06:11:47 2011
@@ -23,7 +23,6 @@ import java.io.InvalidClassException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamException;
-import java.io.Serializable;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Deque;
@@ -41,22 +40,23 @@ import java.util.concurrent.TimeUnit;
 /**
  * The purpose of this class is to implement all the possible interfaces
  * that subclasses of ReferenceCollection may implement.  This is designed
- * to fix the readResolve issue that occurs in object graphs containing
- * circular references.
+ * to fix the readResolve issue that occurs in de-serialised object graphs 
+ * containing circular references.
  * 
  * @author Peter Firmstone.
  */
-abstract class AbstractSerializationOfRC<T> extends SerializationOfReferenceCollection<T>
-implements Serializable, List<T>, Set<T>, SortedSet<T>, NavigableSet<T> , 
+abstract class ReadResolveCircularReferencesFix<T> extends SerializationOfReferenceCollection<T>
+implements List<T>, Set<T>, SortedSet<T>, NavigableSet<T> , 
 Queue<T>, Deque<T>, BlockingQueue<T>, BlockingDeque<T>{
-    private static final long serialVersionUID = 1L;
    
     // This abstract class must not hold any serial data.
     
     // Builder created List on deserialization
-    private volatile transient Collection<T> serialBuilt = null;
-    private volatile transient boolean built = false;
+    private volatile Collection<T> serialBuilt = null;
+    private volatile boolean built = false;
    
+    ReadResolveCircularReferencesFix(){}
+    
     @Override
     Collection<T> build() throws InstantiationException, IllegalAccessException,
     ObjectStreamException {
@@ -86,31 +86,31 @@ Queue<T>, Deque<T>, BlockingQueue<T>, Bl
      * @serialData 
      * @return the type
      */
-    public abstract Ref getType();
+    abstract Ref getType();
 
     /**
      * @serialData
      * @return the collection
      */
-    public abstract Collection<Referrer<T>> getCollection();
+    abstract Collection<Referrer<T>> getCollection();
 
     /**
      * @serialData
      * @return the class
      */
-    public abstract Class getClazz();
+    abstract Class getClazz();
 
     /**
      * @return the serialBuilt
      */
-    public Collection<T> getSerialBuilt() {
+    Collection<T> getSerialBuilt() {
         return serialBuilt;
     }
 
     /**
      * @param serialBuilt the serialBuilt to set
      */
-    public Collection<T> setSerialBuilt(Collection<T> serialBuilt) {
+    Collection<T> setSerialBuilt(Collection<T> serialBuilt) {
         this.serialBuilt = serialBuilt;
         return serialBuilt;
     }
@@ -118,14 +118,14 @@ Queue<T>, Deque<T>, BlockingQueue<T>, Bl
     /**
      * @return the built
      */
-    public boolean isBuilt() {
+    boolean isBuilt() {
         return built;
     }
 
     /**
      * 
      */
-    public void setBuilt() {
+    void setBuilt() {
         built = true;
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingDeque.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingDeque.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingDeque.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingDeque.java Wed Oct 12 06:11:47 2011
@@ -45,28 +45,28 @@ class ReferenceBlockingDeque<T> extends 
 
     public void putFirst(T e) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.putFirst(r);
     }
 
 
     public void putLast(T e) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.putLast(r);
     }
 
 
     public boolean offerFirst(T e, long timeout, TimeUnit unit) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return deque.offerFirst(r, timeout, unit);
     }
 
 
     public boolean offerLast(T e, long timeout, TimeUnit unit) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return deque.offerLast(r, timeout, unit);
     }
 
@@ -105,14 +105,14 @@ class ReferenceBlockingDeque<T> extends 
 
     public void put(T e) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.put(r);
     }
 
 
     public boolean offer(T e, long timeout, TimeUnit unit) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return deque.offer(r,timeout, unit);
     }
 
@@ -143,7 +143,7 @@ class ReferenceBlockingDeque<T> extends 
         if (c == null) throw new NullPointerException();
         if (c == this) throw new IllegalArgumentException();
         @SuppressWarnings("unchecked")
-        Collection<Referrer<T>> dr = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), true);
+        Collection<Referrer<T>> dr = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), false, true);
         return deque.drainTo(dr);
         }
 
@@ -153,7 +153,7 @@ class ReferenceBlockingDeque<T> extends 
         if (c == null) throw new NullPointerException();
         if (c == this) throw new IllegalArgumentException();
         @SuppressWarnings("unchecked")
-        Collection<Referrer<T>> drain = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), true);
+        Collection<Referrer<T>> drain = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), false, true);
         return deque.drainTo(drain, maxElements);
         }
     }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingQueue.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingQueue.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingQueue.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceBlockingQueue.java Wed Oct 12 06:11:47 2011
@@ -45,13 +45,13 @@ class ReferenceBlockingQueue<T> extends 
 
     public void put(T e) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         queue.put(r);
     }
 
     public boolean offer(T e, long timeout, TimeUnit unit) throws InterruptedException {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return queue.offer(r, timeout, unit);
     }
 
@@ -79,7 +79,7 @@ class ReferenceBlockingQueue<T> extends 
         if (c == null) throw new NullPointerException();
         if (c == this) throw new IllegalArgumentException();
         @SuppressWarnings("unchecked")
-        Collection<Referrer<T>> dr = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), true);
+        Collection<Referrer<T>> dr = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), false, true);
         return queue.drainTo(dr);   
         }
 
@@ -88,7 +88,7 @@ class ReferenceBlockingQueue<T> extends 
         if (c == null) throw new NullPointerException();
         if (c == this) throw new IllegalArgumentException();
         @SuppressWarnings("unchecked")
-        Collection<Referrer<T>> drain = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), true);
+        Collection<Referrer<T>> drain = new CollectionWrapper<T>( (Collection<T>) c, getRQF(), false, true);
         return queue.drainTo(drain, maxElements);
         }
     

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollection.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollection.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollection.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollection.java Wed Oct 12 06:11:47 2011
@@ -87,8 +87,8 @@ class ReferenceCollection<T> extends Abs
         return type;
     }
     
-    Referrer<T> wrapObj(T t, boolean enqueue){
-        return rqf.referenced(t, enqueue);
+    Referrer<T> wrapObj(T t, boolean enqueue, boolean temporary){
+        return rqf.referenced(t, enqueue, temporary);
     }
     
     public int size() {
@@ -103,7 +103,7 @@ class ReferenceCollection<T> extends Abs
 
     public boolean contains(Object o) {
         processQueue();
-        return col.contains(wrapObj((T) o, false));
+        return col.contains(wrapObj((T) o, false, true));
     }
     
     /**
@@ -121,26 +121,26 @@ class ReferenceCollection<T> extends Abs
 
     public boolean add(T e) {
         processQueue();
-        return col.add(wrapObj(e, true));
+        return col.add(wrapObj(e, true, false));
     }
 
     public boolean remove(Object o) {
         processQueue();
-        return col.remove(wrapObj((T) o, false));
+        return col.remove(wrapObj((T) o, false, true));
     }
 
  
     @SuppressWarnings("unchecked")
     public boolean containsAll(Collection<?> c) {
         processQueue();
-        return col.containsAll(new CollectionWrapper<T>((Collection<T>) c, getRQF(), false));
+        return col.containsAll(new CollectionWrapper<T>((Collection<T>) c, getRQF(), false, true));
     }
 
     
     @SuppressWarnings("unchecked")
     public boolean addAll(Collection<? extends T> c) {
         processQueue();
-        return col.addAll(new CollectionWrapper<T>((Collection<T>) c, getRQF(), true));
+        return col.addAll(new CollectionWrapper<T>((Collection<T>) c, getRQF(), true, false));
     }
 
     public void clear() {

Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java?rev=1182211&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java Wed Oct 12 06:11:47 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.impl.util;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ *
+ * @author peter
+ */
+abstract class ReferenceCollectionRefreshAfterSerialization<T> 
+                            extends ReadResolveCircularReferencesFix<T> {
+
+    ReferenceCollectionRefreshAfterSerialization() {
+    }
+
+    @Override
+    final Collection<T> build() throws InstantiationException, IllegalAccessException, ObjectStreamException {
+        Collection<T> result = super.build();
+        /* What if the underlying collection is immutable?
+         * The ReferenceQueuingFactory is unknown until the ReferenceCollection
+         * has been built.
+         */
+        if (result instanceof ReferenceCollection) {
+            ReferenceCollection<T> refCol = (ReferenceCollection<T>) result;
+            ReferenceQueuingFactory<T, Referrer<T>> rqf = refCol.getRQF();
+            Iterator<Referrer<T>> colIt = getCollection().iterator();
+            while (colIt.hasNext()) {
+                Referrer<T> ref = colIt.next();
+                if (ref == null) {
+                    continue;
+                }
+                if (ref instanceof AbstractReferrerWrapper) {
+                    ((AbstractReferrerWrapper<T>) ref).refresh(rqf);
+                } else {
+                    throw new InvalidObjectException("Referrer's must be an AbstractReferrerWraper for ReferenceCollection");
+                }
+            }
+        }
+        return result;
+    }
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionRefreshAfterSerialization.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java?rev=1182211&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java Wed Oct 12 06:11:47 2011
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.impl.util;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ *This class is the serial form of ReferenceCollection and all it's subclasses.
+ * 
+ * While the serial form of this class will remain compatible with itself,
+ * ReferenceCollection may replace this implementation with another
+ * at some point in the future.
+ * 
+ * This class will still be able to de-serialise into a ReferenceCollection.
+ * 
+ * @author peter
+ */
+ class ReferenceCollectionSerialData<T> 
+    extends ReferenceCollectionRefreshAfterSerialization<T> implements Serializable {
+    private static final long serialVersionUID = 1L;
+    
+    /** @serialField  */
+    private Ref type;
+    /** @serialField */
+    private Collection<Referrer<T>> collection;
+    /** @serialField */
+    private Class referenceCollectionClass;
+
+    @SuppressWarnings("unchecked")
+   ReferenceCollectionSerialData( Class clazz,
+            Collection<Referrer<T>> underlyingCollection, Ref type) 
+           throws InstantiationException, IllegalAccessException{
+        // Create a new instance of the underlying collection and
+        // add all objects.
+        if ( clazz == null || underlyingCollection == null || type == null){
+            throw new NullPointerException("null parameters prohibited");
+        }
+        this.collection = underlyingCollection;
+        this.type = type;
+        this.referenceCollectionClass = clazz;
+   }
+    
+    @Override
+    public Ref getType() {
+        return type;
+    }
+
+    @Override
+    public Collection<Referrer<T>> getCollection() {
+        return collection;
+    }
+
+    @Override
+    public Class getClazz() {
+        return referenceCollectionClass;
+    }
+
+     private void readObject(ObjectInputStream in)
+        throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        if ( referenceCollectionClass == null || collection == null || type == null){
+            throw new InvalidObjectException("null fields found after deserialization");
+        }
+    }
+    
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+    }
+    
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialDataDefensiveCopy.java (from r1180542, river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerialDataReferenceCollection.java)
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialDataDefensiveCopy.java?p2=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialDataDefensiveCopy.java&p1=river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerialDataReferenceCollection.java&r1=1180542&r2=1182211&rev=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerialDataReferenceCollection.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceCollectionSerialDataDefensiveCopy.java Wed Oct 12 06:11:47 2011
@@ -22,33 +22,46 @@ import java.io.IOException;
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.util.Collection;
-import java.util.Iterator;
+import java.util.Comparator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
- * This class is the serial form of ReferenceCollection and all it's subclasses.
+ * This class is an experimental serial form of ReferenceCollection and 
+ * all it's subclasses.
  * 
  * While the serial form of this class will remain compatible with itself,
  * ReferenceCollection may replace this implementation with another
  * at some point in the future.
  * 
- * This class will still be able to deserialize into a ReferenceCollection.
+ * This class will still be able to de-serialise into a ReferenceCollection.
  * 
+ * The issue with defensive copying a collection is, there may be a number
+ * of collection views serialised together, such as a Set and a SubSet or
+ * any number of sub set's.  If we perform a defensive copy, these instances
+ * will no longer refer to the same underlying set.
+ * 
+ * @param <T> referent type.
  * @author peter
  */
-public class SerialDataReferenceCollection<T> extends AbstractSerializationOfRC<T> {
+public class ReferenceCollectionSerialDataDefensiveCopy<T> 
+extends ReferenceCollectionRefreshAfterSerialization<T> implements Serializable{
     private static final long serialVersionUID = 1L;
+    private static final String method = "comparator";
 
    /** @serialField  */
    private Ref type;
    /** @serialField */
    private Collection<Referrer<T>> collection;
    /** @serialField */
-   private Class clazz;
+   private Class referenceCollectionClass;
    
     @SuppressWarnings("unchecked")
-   SerialDataReferenceCollection( Class clazz,
+   ReferenceCollectionSerialDataDefensiveCopy( Class clazz,
             Collection<Referrer<T>> underlyingCollection, Ref type) 
            throws InstantiationException, IllegalAccessException{
         // Create a new instance of the underlying collection and
@@ -58,7 +71,7 @@ public class SerialDataReferenceCollecti
         }
         this.collection = underlyingCollection;
         this.type = type;
-        this.clazz = clazz;
+        this.referenceCollectionClass = clazz;
    }
     
     @Override
@@ -73,40 +86,53 @@ public class SerialDataReferenceCollecti
 
     @Override
     public Class getClazz() {
-        return clazz;
-    }
-    
-    @Override
-    final Collection<T> build() throws InstantiationException, IllegalAccessException, 
-    ObjectStreamException{
-        Collection<T> result = super.build();
-        /* What if the underlying collection is immutable?
-         * The ReferenceQueuingFactory is unknown until the ReferenceCollection
-         * has been built.
-         */
-        if ( result instanceof ReferenceCollection){
-            ReferenceCollection<T> refCol = (ReferenceCollection<T>) result;
-            ReferenceQueuingFactory<T, Referrer<T>> rqf = refCol.getRQF();
-            Iterator<Referrer<T>> colIt = collection.iterator();
-            while (colIt.hasNext()){
-                Referrer<T> ref = colIt.next();
-                if ( ref == null ) continue;
-                if (ref instanceof ReferrerWrapper){
-                    ((ReferrerWrapper<T>) ref).refresh(rqf);
-                } else {
-                    throw new InvalidObjectException("Referrer's must be a ReferrerWraper for ReferenceCollection");
-                }
-            }
-        }
-        return result;
+        return referenceCollectionClass;
     }
 
      private void readObject(ObjectInputStream in)
         throws IOException, ClassNotFoundException {
         in.defaultReadObject();
-        if ( clazz == null || collection == null || type == null){
+        if ( referenceCollectionClass == null || collection == null || type == null){
             throw new InvalidObjectException("null fields found after deserialization");
         }
+        // Attempt Defensive copy of collection.
+        Class cl = collection.getClass();
+        Collection replacement = null;
+        Comparator comparator = null;
+        boolean comparatorAbsenceConfirmed = false;
+        Method comparatorMethod = null;
+        try {
+            comparatorMethod = cl.getMethod(method, (Class[]) null);
+        } catch (NoSuchMethodException ex) {
+            comparatorAbsenceConfirmed = true;
+        } catch (SecurityException ex) {
+            Logger.getLogger(ReferenceCollectionSerialDataDefensiveCopy.class.getName())
+                    .log(Level.WARNING, "Insufficient privileges for defensive copying of serial data", ex);
+            return; // Insufficient privileges, giving up.
+        }
+        if ( comparatorMethod != null ){
+            try {
+                comparator = (Comparator) comparatorMethod.invoke(collection, (Object[]) null);
+                if ( comparator == null ) comparatorAbsenceConfirmed = true;
+            } catch (Exception e) {
+                comparatorAbsenceConfirmed = true;
+                // nothing to see here, move along.
+            }
+        }
+        if (comparatorAbsenceConfirmed){
+            // There is no comparator
+            Constructor[] constructors = cl.getConstructors();
+            // Check for an int only arg constructor, this is important
+            // For Queue's that may be capacity limited, since, we're
+            // transferring to another machine, an unlimited capacity 
+            // Queue would be rude.
+        }
+        // Comparator is confirmed, here's where we construct a new
+        // object with a comparator and size constructor ,or a comparator
+        // constructor.
+        
+        // Now use an iterator to add all elements.
+        
     }
     
     private void writeObject(ObjectOutputStream out) throws IOException {

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentMap.java Wed Oct 12 06:11:47 2011
@@ -64,8 +64,8 @@ class ReferenceConcurrentMap<K, V> exten
     
     public V putIfAbsent(K key, V value) {
         processQueue();  //may be a slight delay before atomic putIfAbsent
-        Referrer<K> k = wrapKey(key, true);
-        Referrer<V> v = wrapVal(value, true);
+        Referrer<K> k = wrapKey(key, true, false);
+        Referrer<V> v = wrapVal(value, true, false);
         Referrer<V> val = map.putIfAbsent(k, v);
         while ( val != null ) {
             V existed = val.get();
@@ -90,17 +90,17 @@ class ReferenceConcurrentMap<K, V> exten
     @SuppressWarnings("unchecked")
     public boolean remove(Object key, Object value) {
         processQueue();
-        return map.remove(wrapKey((K) key, false), wrapVal((V) value, false));
+        return map.remove(wrapKey((K) key, false, true), wrapVal((V) value, false, true));
     }
 
     public boolean replace(K key, V oldValue, V newValue) {
         processQueue();
-        return map.replace(wrapKey(key, true), wrapVal(oldValue, false), wrapVal(newValue, false));
+        return map.replace(wrapKey(key, false, true), wrapVal(oldValue, false, true), wrapVal(newValue, true, false));
     }
 
     public V replace(K key, V value) {
         processQueue();
-        Referrer<V> val = map.replace(wrapKey(key, true), wrapVal(value, true));
+        Referrer<V> val = map.replace(wrapKey(key, false, true), wrapVal(value, true, false));
         if ( val != null ) return val.get();
         return null;
     }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMap.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMap.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceConcurrentNavigableMap.java Wed Oct 12 06:11:47 2011
@@ -18,7 +18,6 @@
 
 package org.apache.river.impl.util;
 
-import java.lang.ref.Reference;
 import java.util.Comparator;
 import java.util.Map.Entry;
 import java.util.NavigableSet;
@@ -49,9 +48,9 @@ extends ReferenceConcurrentMap<K,V> impl
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
             map.subMap(
-                wrapKey(fromKey, false), 
+                wrapKey(fromKey, false, true), 
                 fromInclusive, 
-                wrapKey(toKey, false),
+                wrapKey(toKey, false, true),
                 toInclusive
             ), 
             getKeyRQF(),
@@ -62,7 +61,7 @@ extends ReferenceConcurrentMap<K,V> impl
     public ConcurrentNavigableMap<K, V> headMap(K toKey, boolean inclusive) {
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
-            map.headMap(wrapKey(toKey, false), inclusive),
+            map.headMap(wrapKey(toKey, false, true), inclusive),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -71,7 +70,7 @@ extends ReferenceConcurrentMap<K,V> impl
     public ConcurrentNavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
-            map.tailMap(wrapKey(fromKey, false), inclusive),
+            map.tailMap(wrapKey(fromKey, false, true), inclusive),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -80,7 +79,7 @@ extends ReferenceConcurrentMap<K,V> impl
     public ConcurrentNavigableMap<K, V> subMap(K fromKey, K toKey) {
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
-            map.subMap(wrapKey(fromKey, false), wrapKey(toKey, false)),
+            map.subMap(wrapKey(fromKey, false, true), wrapKey(toKey, false, true)),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -89,7 +88,7 @@ extends ReferenceConcurrentMap<K,V> impl
     public ConcurrentNavigableMap<K, V> headMap(K toKey) {
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
-            map.headMap(wrapKey(toKey, false)),
+            map.headMap(wrapKey(toKey, false, true)),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -98,7 +97,7 @@ extends ReferenceConcurrentMap<K,V> impl
     public ConcurrentNavigableMap<K, V> tailMap(K fromKey) {
         processQueue();
         return new ReferenceConcurrentNavigableMap<K,V>(
-            map.tailMap(wrapKey(fromKey, false)),
+            map.tailMap(wrapKey(fromKey, false, true)),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -131,14 +130,14 @@ extends ReferenceConcurrentMap<K,V> impl
     public Entry<K, V> lowerEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.lowerEntry(wrapKey(key, false)),
+            map.lowerEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K lowerKey(K key) {
         processQueue();
-        Referrer<K> k = map.lowerKey(wrapKey(key, false));
+        Referrer<K> k = map.lowerKey(wrapKey(key, false, true));
         if ( k != null ) return k.get();
         return null;
     }
@@ -146,14 +145,14 @@ extends ReferenceConcurrentMap<K,V> impl
     public Entry<K, V> floorEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.floorEntry(wrapKey(key, false)),
+            map.floorEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K floorKey(K key) {
         processQueue();
-        Referrer<K> k = map.floorKey(wrapKey(key, false));
+        Referrer<K> k = map.floorKey(wrapKey(key, false, true));
         if ( k != null ) return k.get();
         return null;
     }
@@ -161,14 +160,14 @@ extends ReferenceConcurrentMap<K,V> impl
     public Entry<K, V> ceilingEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.ceilingEntry(wrapKey(key, false)),
+            map.ceilingEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K ceilingKey(K key) {
         processQueue();
-        Referrer<K> k = map.ceilingKey(wrapKey(key, false));
+        Referrer<K> k = map.ceilingKey(wrapKey(key, false, true));
         if ( k != null ) return k.get();
         return null;
     }
@@ -176,14 +175,14 @@ extends ReferenceConcurrentMap<K,V> impl
     public Entry<K, V> higherEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.higherEntry(wrapKey(key, false)),
+            map.higherEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K higherKey(K key) {
         processQueue();
-        Referrer<K> k = map.higherKey(wrapKey(key, false));
+        Referrer<K> k = map.higherKey(wrapKey(key, false, true));
         if ( k != null ) return k.get();
         return null;
     }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceDeque.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceDeque.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceDeque.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceDeque.java Wed Oct 12 06:11:47 2011
@@ -42,25 +42,25 @@ class ReferenceDeque<T> extends Referenc
     
     public void addFirst(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.addFirst(r);
     }
 
     public void addLast(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.addLast(r);
     }
 
     public boolean offerFirst(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return deque.offerFirst(r);
     }
 
     public boolean offerLast(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return deque.offerLast(r);
     }
 
@@ -123,20 +123,20 @@ class ReferenceDeque<T> extends Referenc
     public boolean removeFirstOccurrence(Object o) {
         processQueue();
         @SuppressWarnings("unchecked")
-        Referrer<T> r = wrapObj((T) o, false);
+        Referrer<T> r = wrapObj((T) o, false, true);
         return deque.removeFirstOccurrence(r);
     }
 
     public boolean removeLastOccurrence(Object o) {
         processQueue();
         @SuppressWarnings("unchecked")
-        Referrer<T> r = wrapObj((T) o, false);
+        Referrer<T> r = wrapObj((T) o, false, true);
         return deque.removeLastOccurrence(r);
     }
 
     public void push(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         deque.push(r);
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceEntryFacade.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceEntryFacade.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceEntryFacade.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceEntryFacade.java Wed Oct 12 06:11:47 2011
@@ -80,7 +80,7 @@ class ReferenceEntryFacade<K, V> impleme
     }
     
     private Referrer<V> wrapVal(V val, boolean enque) {
-        return rqf.referenced(val, enque);
+        return rqf.referenced(val, enque, false);
 }
 
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceFactory.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceFactory.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceFactory.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceFactory.java Wed Oct 12 06:11:47 2011
@@ -59,4 +59,40 @@ class ReferenceFactory<T> {
         }
     }
     
+    /**
+     * This doesn't create a genuine reference, only a simple wrapper object
+     * that will be used once then discarded.  The Referrer will be allocated
+     * to the stack by the jvm and not the heap.  There is no queue, no
+     * reference, this is simply a wrapper class that provides the correct
+     * equals, hashcode and comparator semantics.
+     * 
+     * This object must not be added to any collection classes, it is not
+     * serialisable, it's sole intended purpose is to improve read performance
+     * by being allocated to the stack, not the heap space and avoiding a
+     * cache miss.  To achieve this goal, it must not be shared with other
+     * Threads either.
+     * 
+     * @param <T>
+     * @param t
+     * @param type
+     * @return 
+     */
+    static <T> Referrer<T> singleUseForLookup(T t, Ref type){
+        switch (type){
+            case WEAK_IDENTITY: 
+                return new TempIdentityReferrer<T>(t);
+            case SOFT_IDENTITY: 
+                return new TempIdentityReferrer<T>(t);
+            case WEAK: 
+                if (t instanceof Comparable) return new TempComparableReferrer<T>(t);
+                return new TempEqualReferrer<T>(t);
+            case SOFT: 
+                if (t instanceof Comparable) return new TempComparableReferrer<T>(t);
+                return new TempEqualReferrer<T>(t);
+            default: 
+                if (t instanceof Comparable) return new TempComparableReferrer<T>(t);
+                return new TempEqualReferrer<T>(t);
+        }
+    }
+    
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceList.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceList.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceList.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceList.java Wed Oct 12 06:11:47 2011
@@ -108,7 +108,7 @@ class ReferenceList<T> extends Reference
     @SuppressWarnings("unchecked")
     public boolean addAll(int index, Collection<? extends T> c) {
         processQueue();
-        return list.addAll(index, new CollectionWrapper<T>((Collection<T>) c, getRQF(), true));
+        return list.addAll(index, new CollectionWrapper<T>((Collection<T>) c, getRQF(), true, false));
     }
 
     public T get(int index) {
@@ -120,14 +120,14 @@ class ReferenceList<T> extends Reference
 
     public T set(int index, T element) {
         processQueue();
-        Referrer<T> r = list.set(index, wrapObj(element, true));
+        Referrer<T> r = list.set(index, wrapObj(element, true, false));
         if (r != null) return r.get();
         return null;
     }
 
     public void add(int index, T element) {
         processQueue();
-        list.add(index, wrapObj(element, true));
+        list.add(index, wrapObj(element, true, false));
     }
 
     public T remove(int index) {
@@ -140,13 +140,13 @@ class ReferenceList<T> extends Reference
     @SuppressWarnings("unchecked")
     public int indexOf(Object o) {
         processQueue();
-        return list.indexOf(wrapObj((T) o, false));
+        return list.indexOf(wrapObj((T) o, false, true));
     }
 
     @SuppressWarnings("unchecked")
     public int lastIndexOf(Object o) {
         processQueue();
-        return list.lastIndexOf(wrapObj((T)o, false));
+        return list.lastIndexOf(wrapObj((T)o, false, true));
     }
 
     public ListIterator<T> listIterator() {
@@ -208,11 +208,11 @@ class ReferenceList<T> extends Reference
         }
 
         public void set(T e) {
-            iterator.set(rqf.referenced(e, true));
+            iterator.set(rqf.referenced(e, true, false));
         }
 
         public void add(T e) {
-            iterator.add(rqf.referenced( e, true));
+            iterator.add(rqf.referenced( e, true, false));
         }       
     }
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMap.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMap.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceMap.java Wed Oct 12 06:11:47 2011
@@ -117,13 +117,13 @@ class ReferenceMap<K, V> extends Abstrac
     @SuppressWarnings(value = "unchecked")
     public boolean containsKey(Object key) {
         processQueue();
-        return map.containsKey(wrapKey((K)key, false));
+        return map.containsKey(wrapKey((K)key, false, true));
         }
 
     @SuppressWarnings("unchecked")
     public boolean containsValue(Object value) {
         processQueue();
-        return map.containsValue(wrapVal((V) value, false));
+        return map.containsValue(wrapVal((V) value, false, true));
     }
 
     /**
@@ -148,7 +148,7 @@ class ReferenceMap<K, V> extends Abstrac
     public V get(Object key) {
         processQueue();
         @SuppressWarnings(value = "unchecked")
-        Referrer<V> refVal = map.get(wrapKey((K) key, false));
+        Referrer<V> refVal = map.get(wrapKey((K) key, false, true));
         if (refVal != null) return refVal.get();
         return null;
     }
@@ -190,7 +190,7 @@ class ReferenceMap<K, V> extends Abstrac
      */
     public V put(K key, V value) {
         processQueue();
-        Referrer<V> val = map.put(wrapKey(key, false),wrapVal(value, false));
+        Referrer<V> val = map.put(wrapKey(key, true, false),wrapVal(value, true, false));
         if (val != null) return val.get();
             return null;
         }
@@ -202,7 +202,7 @@ class ReferenceMap<K, V> extends Abstrac
     public V remove(Object key) {
         processQueue();
         @SuppressWarnings(value = "unchecked")
-        Referrer<V> val = map.remove(wrapKey((K) key, false));
+        Referrer<V> val = map.remove(wrapKey((K) key, false, true));
         if (val != null) return val.get();
         return null;
     }
@@ -220,12 +220,12 @@ class ReferenceMap<K, V> extends Abstrac
         return values;
     }
 
-    Referrer<V> wrapVal(V val, boolean enque) {
-        return vrqf.referenced(val, enque);
+    Referrer<V> wrapVal(V val, boolean enque, boolean temporary) {
+        return vrqf.referenced(val, enque, temporary);
     }
 
-    Referrer<K> wrapKey(K key, boolean enque) {
-        return krqf.referenced(key, enque);
+    Referrer<K> wrapKey(K key, boolean enque, boolean temporary) {
+        return krqf.referenced(key, enque, temporary);
     }
     
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableMap.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableMap.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableMap.java Wed Oct 12 06:11:47 2011
@@ -45,14 +45,14 @@ class ReferenceNavigableMap<K,V> extends
     public Entry<K, V> lowerEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.lowerEntry(wrapKey(key, false)),
+            map.lowerEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K lowerKey(K key) {
         processQueue();
-        Referrer<K> k = map.lowerKey(wrapKey(key, false));
+        Referrer<K> k = map.lowerKey(wrapKey(key, false, true));
         if (k != null) return k.get();
         return null;
     }
@@ -60,14 +60,14 @@ class ReferenceNavigableMap<K,V> extends
     public Entry<K, V> floorEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.floorEntry(wrapKey(key, false)),
+            map.floorEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K floorKey(K key) {
         processQueue();
-        Referrer<K> k = map.floorKey(wrapKey(key, false));
+        Referrer<K> k = map.floorKey(wrapKey(key, false, true));
         if (k != null) return k.get();
         return null;
     }
@@ -75,14 +75,14 @@ class ReferenceNavigableMap<K,V> extends
     public Entry<K, V> ceilingEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.ceilingEntry(wrapKey(key, false)),
+            map.ceilingEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K ceilingKey(K key) {
         processQueue();
-        Referrer<K> k = map.ceilingKey(wrapKey(key, false));
+        Referrer<K> k = map.ceilingKey(wrapKey(key, false, true));
         if (k != null) return k.get();
         return null;
     }
@@ -90,14 +90,14 @@ class ReferenceNavigableMap<K,V> extends
     public Entry<K, V> higherEntry(K key) {
         processQueue();
         return new ReferenceEntryFacade<K,V>(
-            map.higherEntry(wrapKey(key, false)),
+            map.higherEntry(wrapKey(key, false, true)),
             getValRQF()
         );
     }
 
     public K higherKey(K key) {
         processQueue();
-        Referrer<K> k = map.higherKey(wrapKey(key, false));
+        Referrer<K> k = map.higherKey(wrapKey(key, false, true));
         if (k != null) return k.get();
         return null;
     }
@@ -157,9 +157,9 @@ class ReferenceNavigableMap<K,V> extends
         processQueue();
         return new ReferenceNavigableMap<K,V>(
             map.subMap(
-                wrapKey(fromKey, false),
+                wrapKey(fromKey, false, true),
                 fromInclusive, 
-                wrapKey(toKey, false), 
+                wrapKey(toKey, false, true), 
                 toInclusive
             ),
             getKeyRQF(),
@@ -171,7 +171,7 @@ class ReferenceNavigableMap<K,V> extends
     public NavigableMap<K, V> headMap(K toKey, boolean inclusive) {
         processQueue();
         return new ReferenceNavigableMap<K,V>(
-            map.headMap(wrapKey(toKey, false),inclusive),
+            map.headMap(wrapKey(toKey, false, true),inclusive),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );
@@ -180,7 +180,7 @@ class ReferenceNavigableMap<K,V> extends
     public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive) {
         processQueue();
         return new ReferenceNavigableMap<K,V>(
-            map.tailMap(wrapKey(fromKey, false),inclusive),
+            map.tailMap(wrapKey(fromKey, false, true),inclusive),
             getKeyRQF(),
             getValRQF(), keyRef(), valRef()
         );

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableSet.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableSet.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableSet.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceNavigableSet.java Wed Oct 12 06:11:47 2011
@@ -50,28 +50,28 @@ public class ReferenceNavigableSet<T> 
 
     public T lower(T e) {
         processQueue();
-        Referrer<T> t = set.lower(wrapObj(e, false));
+        Referrer<T> t = set.lower(wrapObj(e, false, true));
         if ( t != null ) return t.get();
         return null;
     }
 
     public T floor(T e) {
         processQueue();
-        Referrer<T> t = set.floor(wrapObj(e, false));
+        Referrer<T> t = set.floor(wrapObj(e, false, true));
         if ( t != null ) return t.get();
         return null;
     }
 
     public T ceiling(T e) {
         processQueue();
-        Referrer<T> t = set.ceiling(wrapObj(e, false));
+        Referrer<T> t = set.ceiling(wrapObj(e, false, true));
         if ( t != null ) return t.get();
         return null;
     }
 
     public T higher(T e) {
         processQueue();
-        Referrer<T> t = set.higher(wrapObj(e, false));
+        Referrer<T> t = set.higher(wrapObj(e, false, true));
         if ( t != null ) return t.get();
         return null;
     }
@@ -104,9 +104,9 @@ public class ReferenceNavigableSet<T> 
         processQueue();
         return new ReferenceNavigableSet<T>(
             set.subSet(
-                wrapObj(fromElement, false), 
+                wrapObj(fromElement, false, true), 
                 fromInclusive, 
-                wrapObj(toElement, false), 
+                wrapObj(toElement, false, true), 
                 toInclusive
             ), getRQF(), getRef());
     }
@@ -114,13 +114,22 @@ public class ReferenceNavigableSet<T> 
     public NavigableSet<T> headSet(T toElement, boolean inclusive) {
         processQueue();
         return new ReferenceNavigableSet<T>(
-                set.headSet(wrapObj(toElement, false), inclusive), getRQF(), getRef());
+                set.headSet(
+                    wrapObj(toElement, false, true), inclusive),
+                    getRQF(), 
+                    getRef()
+                );
     }
 
     public NavigableSet<T> tailSet(T fromElement, boolean inclusive) {
         processQueue();
         return new ReferenceNavigableSet<T>(
-                set.tailSet(wrapObj(fromElement, false), inclusive), getRQF(), getRef());
+                set.tailSet(
+                    wrapObj(fromElement, false, true),
+                    inclusive), 
+                    getRQF(), 
+                    getRef()
+                );
     }
     
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceProcessor.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceProcessor.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceProcessor.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceProcessor.java Wed Oct 12 06:11:47 2011
@@ -51,8 +51,9 @@ class ReferenceProcessor<T> implements R
     }
 
     @Override
-    public Referrer<T> referenced(T w, boolean enque) {
+    public Referrer<T> referenced(T w, boolean enque, boolean temporary) {
         if (w == null) return null;
+        if (temporary) return ReferenceFactory.singleUseForLookup(w, type);
         return ReferenceFactory.create(w, enque == true ? queue : null, type);
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceQueuingFactory.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceQueuingFactory.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceQueuingFactory.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceQueuingFactory.java Wed Oct 12 06:11:47 2011
@@ -28,7 +28,7 @@ interface ReferenceQueuingFactory<O, R> 
 
     O pseudoReferent(R u);
 
-    R referenced(O w, boolean enque);
+    R referenced(O w, boolean enque, boolean temporary);
 
     void processQueue();
      

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializationFactory.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializationFactory.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializationFactory.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializationFactory.java Wed Oct 12 06:11:47 2011
@@ -20,11 +20,14 @@ package org.apache.river.impl.util;
 
 /**
  *
- * @author peter
+ * @author Peter Firmstone.
  */
-abstract class ReferenceSerializationFactory<T> implements Referrer<T> {
+class ReferenceSerializationFactory<T> {
     
-    static <T> ReferenceSerializationFactory<T> create(T t) {
+    // Not instantiable.
+    private ReferenceSerializationFactory(){}
+    
+    static <T> Referrer<T> create(T t) {
         return new ReferenceSerializedForm<T>(t);
     }
     

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializedForm.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializedForm.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializedForm.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSerializedForm.java Wed Oct 12 06:11:47 2011
@@ -24,10 +24,13 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
 /**
- *
+ * A temporary but functional replacement for ReferenceKey's.  No attempt is
+ * made to use readResolve to replace the original, that responsibility is left
+ * up to the collection implementation during de-serialisation.
+ * 
  * @author peter
  */
-class ReferenceSerializedForm<T> extends ReferenceSerializationFactory<T> implements Serializable{
+class ReferenceSerializedForm<T> implements Referrer<T>, Serializable{
     private static final long serialVersionUID = 1L;
     
     private T obj;

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedMap.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedMap.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedMap.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedMap.java Wed Oct 12 06:11:47 2011
@@ -56,7 +56,7 @@ class ReferenceSortedMap<K,V> extends Re
     public SortedMap<K, V> subMap(K fromKey, K toKey) {
         processQueue();
         return new ReferenceSortedMap<K,V>(
-                map.subMap(wrapKey(fromKey, false), wrapKey(toKey, false)),
+                map.subMap(wrapKey(fromKey, false, true), wrapKey(toKey, false, true)),
                 getKeyRQF(),
                 getValRQF(), keyRef(), valRef()
                 );
@@ -66,7 +66,7 @@ class ReferenceSortedMap<K,V> extends Re
     public SortedMap<K, V> headMap(K toKey) {
         processQueue();
         return new ReferenceSortedMap<K,V>(
-                map.headMap(wrapKey(toKey, false)),
+                map.headMap(wrapKey(toKey, false, true)),
                 getKeyRQF(),
                 getValRQF(), keyRef(), valRef()
                 );
@@ -76,7 +76,7 @@ class ReferenceSortedMap<K,V> extends Re
     public SortedMap<K, V> tailMap(K fromKey) {
         processQueue();
         return new ReferenceSortedMap<K,V>(
-                map.tailMap(wrapKey(fromKey, false)),
+                map.tailMap(wrapKey(fromKey, false, true)),
                 getKeyRQF(),
                 getValRQF(), keyRef(), valRef()
                 );

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedSet.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedSet.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedSet.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferenceSortedSet.java Wed Oct 12 06:11:47 2011
@@ -63,20 +63,20 @@ class ReferenceSortedSet<T> extends Refe
 
     public SortedSet<T> subSet(T fromElement, T toElement) {
         processQueue();
-        Referrer<T> from = wrapObj(fromElement, false);
-        Referrer<T> to = wrapObj(toElement, false);
+        Referrer<T> from = wrapObj(fromElement, false, true);
+        Referrer<T> to = wrapObj(toElement, false, true);
         return new ReferenceSortedSet<T>( set.subSet(from, to), getRQF(), getRef());
     }
 
     public SortedSet<T> headSet(T toElement) {
         processQueue();
-        Referrer<T> to = wrapObj(toElement, false);
+        Referrer<T> to = wrapObj(toElement, false, true);
         return new ReferenceSortedSet<T>(set.headSet(to), getRQF(), getRef());
     }
 
     public SortedSet<T> tailSet(T fromElement) {
         processQueue();
-        Referrer<T> from = wrapObj(fromElement, false);
+        Referrer<T> from = wrapObj(fromElement, false, true);
         return new ReferenceSortedSet<T>(set.tailSet(from), getRQF(), getRef());
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferencedQueue.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferencedQueue.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferencedQueue.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferencedQueue.java Wed Oct 12 06:11:47 2011
@@ -43,7 +43,7 @@ public class ReferencedQueue<T> extends 
     
     public boolean offer(T e) {
         processQueue();
-        Referrer<T> r = wrapObj(e, true);
+        Referrer<T> r = wrapObj(e, true, false);
         return queue.offer(r);
     }
 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Referrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Referrer.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Referrer.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/Referrer.java Wed Oct 12 06:11:47 2011
@@ -21,7 +21,20 @@ package org.apache.river.impl.util;
 import java.lang.ref.Reference;
 
 /**
- * An interface for Reference wrappers, for use in collections.
+ * An interface for References used in collections, it defines the equals
+ * and hashCode contracts as well as methods identical to Reference.
+ * 
+ * A client may wish to implement this interface to replace a standard Referrer
+ * during serialisation with custom implementations to deconstruct and
+ * reconstruct non serialisable objects, or to perform integrity checks.
+ * 
+ * This must be implemented in a Collection provided by the client.
+ * 
+ * After de-serialisation is complete, the client Referrer will be replaced
+ * with a standard Referrer.
+ * 
+ * @see Reference
+ * @see Ref
  * @param <T> 
  * @author Peter Firmstone
  */

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferrerWrapper.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferrerWrapper.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferrerWrapper.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/ReferrerWrapper.java Wed Oct 12 06:11:47 2011
@@ -24,10 +24,18 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
 /**
- *
+ * I've thought about refactoring so the equals and comparator behaviour is
+ * implemented by the wrapper classes and only accepting References in
+ * constructors as this would allow the use of standard java Reference classes
+ * without extension, reducing the number of classes created, 
+ * however that would create serial form lock in.  The current arrangement 
+ * allows for 
+ * 
+ * 
+ * 
  * @author peter
  */
-class ReferrerWrapper<T> implements Referrer<T>, Serializable{
+class ReferrerWrapper<T> extends AbstractReferrerWrapper<T> implements  Serializable{
     private static final long serialVersionUID = 1L;
     
     /**
@@ -40,56 +48,30 @@ class ReferrerWrapper<T> implements Refe
         reference = ref;
     }
     
-    final void refresh(ReferenceQueuingFactory<T, Referrer<T>> rqf){
-        T object = get();
-        if (object != null){
-            Referrer<T> newRef = rqf.referenced(object, true);
-            synchronized (this){
-                reference = newRef;
-            }
+    private void readObject(ObjectInputStream in)
+        throws IOException, ClassNotFoundException {
+        synchronized (this){
+            in.defaultReadObject();
         }
+        if (getReference() == null) throw new IOException("Attempt to write null Referrer");
     }
     
-    @Override
-    public boolean equals(Object o) {
-        if (this == o)  return true; // Same reference.
-        if (!(o instanceof Referrer))  return false;
-        return reference.equals(o);
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
     }
 
     @Override
-    public int hashCode() {
-        return reference.hashCode();
-    }
-    
-    public String toString() {
-        return reference.toString();
-    }
-
-    public final T get() {
-        return reference.get();
-    }
-
-    public void clear() {
-        reference.clear();
-    }
-
-    public boolean isEnqueued() {
-        return reference.isEnqueued();
+    public void refresh(Referrer<T> r) {
+        synchronized (this){
+                reference = r;
+        }
     }
 
-    public boolean enqueue() {
-        return reference.enqueue();
-    }
-    
-    private void readObject(ObjectInputStream in)
-        throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        if (reference == null) throw new IOException("Attempt to write null Referrer");
-    }
-    
-    private void writeObject(ObjectOutputStream out) throws IOException {
-        out.defaultWriteObject();
+    /**
+     * @return the reference
+     */
+    public Referrer<T> getReference() {
+        return reference;
     }
     
 }

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceCollection.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceCollection.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceCollection.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/SerializationOfReferenceCollection.java Wed Oct 12 06:11:47 2011
@@ -32,7 +32,7 @@ abstract class SerializationOfReferenceC
             Class clazz,
             Collection<Referrer<T>> refCol,
             Ref type) throws InstantiationException, IllegalAccessException{
-        return new SerialDataReferenceCollection<T>(clazz, refCol, type);
+        return new ReferenceCollectionSerialData<T>(clazz, refCol, type);
     }
     
     abstract Collection<T> build() throws InstantiationException, 

Modified: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java?rev=1182211&r1=1182210&r2=1182211&view=diff
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java (original)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/StrongReferenceKey.java Wed Oct 12 06:11:47 2011
@@ -31,7 +31,7 @@ import java.lang.ref.WeakReference;
  * @see Ref#STRONG
  * @author Peter Firmstone
  */
-class StrongReferenceKey<T> extends WeakReference<T> implements Referrer<T>, Serializable{
+class StrongReferenceKey<T> implements Referrer<T>, Serializable{
     private static final long serialVersionUID = 1L;
     private T referent;
     private final int hash;
@@ -43,7 +43,6 @@ class StrongReferenceKey<T> extends Weak
      * @param referent object the new weak reference will refer to
      */
     StrongReferenceKey(T referent){
-        super(referent);
         this.referent = referent ;
         int hash = 7;
         hash = 29 * hash + System.identityHashCode(referent);
@@ -87,7 +86,6 @@ class StrongReferenceKey<T> extends Weak
     @Override
     public void clear() {
 	this.referent = null;
-        super.clear();
     }
     
     final Object writeReplace() throws ObjectStreamException {
@@ -98,4 +96,19 @@ class StrongReferenceKey<T> extends Weak
             throws InvalidObjectException{
         throw new InvalidObjectException("Builder required");
     }
+
+    @Override
+    public T get() {
+        return referent;
+    }
+
+    @Override
+    public boolean isEnqueued() {
+        return false;
+    }
+
+    @Override
+    public boolean enqueue() {
+        return false;
+    }
 }

Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java?rev=1182211&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java Wed Oct 12 06:11:47 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.impl.util;
+
+/**
+ *
+ * @author peter
+ */
+public class TempComparableReferrer<T> extends TempEqualReferrer<T> 
+                                        implements Comparable<Referrer<T>>{
+    
+    TempComparableReferrer(T t){
+        super(t);
+    }
+
+    public int compareTo(Referrer<T> o) {
+        T t = get();
+        T r = o.get();
+        if ( t != null && r != null) {
+            if ( t instanceof Comparable){
+                return ((Comparable) t).compareTo(r);
+            }
+        }
+        if ( hashCode() < o.hashCode()) return -1;
+        if ( hashCode() == o.hashCode()) return 0;
+        return 1;
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempComparableReferrer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java?rev=1182211&view=auto
==============================================================================
--- river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java (added)
+++ river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java Wed Oct 12 06:11:47 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.impl.util;
+
+/**
+ *
+ * @param <T> 
+ * @author peter
+ */
+class TempEqualReferrer<T> extends TempIdentityReferrer<T> {
+    
+    TempEqualReferrer(T t){
+        super(t);
+    }
+    
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        } else if (!(o instanceof Referrer)) {
+            return false;
+        }
+        Object t2 = ((Referrer) o).get();
+        return ( get().equals(t2) );
+    }
+    
+    public int hashCode(){
+        return get().hashCode();
+    }
+}

Propchange: river/jtsk/skunk/peterConcurrentPolicy/src/org/apache/river/impl/util/TempEqualReferrer.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message