Very interesting; I would love it if you made this the default for the  
accepts visitor method :-)

I am wondering about the variably in your test results; is it just  
overhead introduced by the blocking queue?  Is there any way to start  
off without prefetching  - and switch over to it if the delays get too  
long?

Jody

On 09/09/2009, at 1:46 AM, Andrea Aime wrote:

> More in general, how do people feel about this?
> Good for a configuration knob in the StreamingRenderer?
> Or just the new default?
>
> Cheers
> Andrea
>
> -- 
> Andrea Aime
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
> package org.geotools.renderer.lite;
>
> import java.util.Iterator;
> import java.util.NoSuchElementException;
> import java.util.concurrent.ArrayBlockingQueue;
> import java.util.concurrent.BlockingQueue;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
>
> import org.geotools.feature.FeatureCollection;
>
> public class PrefetchingIterator implements Iterator {
>    static final ExecutorService pool = Executors.newCachedThreadPool 
> ();
>    BlockingQueue<ValueWrapper> queue;
>    FeatureCollection collection;
>    ValueWrapper current;
>    boolean end = false;
>
>    public PrefetchingIterator(FeatureCollection collection) {
>        this.collection = collection;
>        queue = new ArrayBlockingQueue<ValueWrapper>(100);
>        pool.execute(new Prefetcher());
>    }
>
>    public boolean hasNext() {
>        if(end)
>            return false;
>
>        if(current == null) {
>            try {
>                current = queue.take();
>            } catch(InterruptedException e) {
>                // nothing to do
>            }
>
>            if(current.end) {
>                end = true;
>                return false;
>            } else if(current.exception != null) {
>                end = true;
>                throw new RuntimeException("Error occurred during  
> feature prefetching", current.exception);
>            } else {
>                return true;
>            }
>        } else {
>            return true;
>        }
>    }
>
>    public Object next() {
>        if(!hasNext())
>            throw new NoSuchElementException();
>
>        Object result = current.value;
>        current = null;
>        return result;
>    }
>
>    public void close() {
>        end = true;
>        queue = null;
>    }
>
>    public void remove() {
>        throw new UnsupportedOperationException();
>    }
>
>    final class Prefetcher implements Runnable {
>
>        public void run() {
>            Iterator iterator = null;
>            try {
>                iterator = collection.iterator();
>                while(iterator.hasNext()) {
>                    if(end)
>                        return;
>                    putInQueue(new ValueWrapper(iterator.next()));
>                }
>            } catch(Exception e) {
>                putInQueue(new ValueWrapper(e));
>            } finally {
>                collection.close(iterator);
>            }
>            putInQueue(new ValueWrapper());
>        }
>
>        void putInQueue(ValueWrapper o) {
>            try {
>                queue.put(o);
>            } catch(InterruptedException e) {
>                // nothing to do
>            }
>        }
>
>    }
>
>    final class ValueWrapper {
>        Object value;
>        Exception exception;
>        boolean end;
>
>        public ValueWrapper(Exception e) {
>            this.exception = e;
>        }
>
>        public ValueWrapper(Object value) {
>            this.value = value;
>        }
>
>        public ValueWrapper() {
>            this.end = true;
>        }
>    }
>
> }
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008  
> 30-Day
> trial. Simplify your report design, integration and deployment - and  
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  
> http://p.sf.net/sfu/bobj-july_______________________________________________
> Geotools-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to