/*
 * (c) 2009, 2010 ThoughtWorks Ltd
 * All rights reserved.
 *
 * The software in this package is published under the terms of the BSD
 * style license a copy of which has been included with this distribution in
 * the LICENSE.txt file.
 * 
 * Created on 13-Oct-2009
 */
package proxytoys.examples.overview;

import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.proxy.factory.CglibProxyFactory;
import com.thoughtworks.proxy.toys.future.Future;


/**
 * @author Paul Hammant
 */
public class FutureToyExample {

    //TODO: Fails
    public static void packageOverviewExample1() throws InterruptedException {
        List<?> slowList = new SlowArrayList();
        List<?> fasterList = Future.proxy(List.class).with(slowList)
                          .build(new CglibProxyFactory());
        System.out.println("Items in list: " + fasterList.size());
        Thread.sleep(100);
        System.out.println("Items in list: " + fasterList.size());
    }


    public static void main(String[] args) throws InterruptedException {
        System.out.println();
        System.out.println();
        System.out.println("Running Future Toy Example");
        System.out.println();
        System.out.println("Example 1 of Package Overview:");
        packageOverviewExample1();
    }

    @SuppressWarnings("serial")
    private static class SlowArrayList extends ArrayList<Object> {
        @Override
        public boolean add(final Object o) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                    }
                    SlowArrayList.super.add(o);
                }
            });

            return true;
        }
    }
}
@@ -320,45 +320,221 @@
 ava.
-util.ArrayList;%0Aimport java.util.List
+io.IOException;%0Aimport java.io.Reader;%0Aimport java.io.StringReader;%0A%0Aimport javax.xml.parsers.DocumentBuilder;%0Aimport javax.xml.parsers.DocumentBuilderFactory;%0Aimport javax.xml.parsers.ParserConfigurationException
 ;%0A%0Ai
@@ -640,16 +640,111 @@
 uture;%0A%0A
+import org.w3c.dom.Document;%0Aimport org.xml.sax.InputSource;%0Aimport org.xml.sax.SAXException;%0A%0A
 %0A/**%0A * 
@@ -764,16 +764,42 @@
 Hammant%0A
+ * @author Joerg Schaible%0A
  */%0Apubl
@@ -831,26 +831,8 @@
  %7B%0A%0A
-    //TODO: Fails%0A
     
@@ -907,248 +907,461 @@
 tion
- %7B%0A        List%3C?%3E slowList = new SlowArrayList();%0A        List%3C?%3E fasterList = Future.proxy(List.class).with(slowList)%0A                          .build(new CglibProxyFactory());%0A        System.out.println(%22Items in list: %22 + fasterList.siz
+, ParserConfigurationException, SAXException, IOException %7B%0A        DocumentBuilder documentBuilder = Future.proxy(DocumentBuilder.class)%0A            .with(DocumentBuilderFactory.newInstance().newDocumentBuilder())%0A            .build(new CglibProxyFactory());%0A        Document document = documentBuilder.parse(new SlowInputSource(new StringReader(%22%3Croot/%3E%22)));%0A        System.out.println(%22Root document name: %22 + document.getDocumentElement().getNodeNam
 e())
@@ -1375,33 +1375,33 @@
    Thread.sleep(
-1
+2
 00);%0A        Sys
@@ -1421,41 +1421,72 @@
 ln(%22
-Items in list: %22 + fasterList.siz
+Root document name: %22 + document.getDocumentElement().getNodeNam
 e())
@@ -1557,32 +1557,89 @@
 rruptedException
+, ParserConfigurationException, SAXException, IOException
  %7B%0A        Syste
@@ -1880,40 +1880,12 @@
   %7D%0A
-%0A
     
-@SuppressWarnings(%22serial%22)
 %0A   
@@ -1914,180 +1914,212 @@
 Slow
-ArrayList extends ArrayList%3CObject%3E %7B%0A        @Override%0A        public boolean add(final Object o) %7B%0A            new Thread(new Runnable() %7B%0A                public void run
+InputSource extends InputSource %7B%0A        public SlowInputSource(Reader characterStream)%0A        %7B%0A            super(characterStream);%0A        %7D%0A%0A        @Override%0A        public Reader getCharacterStream
 () %7B
@@ -2135,30 +2135,14 @@
     
-    
-    
 try %7B%0A
-        
     
@@ -2184,24 +2184,16 @@
         
- 
-       
 %7D catch 
@@ -2227,32 +2227,24 @@
             
-        
 %7D%0A          
@@ -2249,55 +2249,51 @@
     
-        SlowArrayList.super.add(o);%0A   
+return super.getCharacterStream();%0A
         
     
@@ -2284,29 +2284,24 @@
 ();%0A        
-     
 %7D%0A          
@@ -2302,51 +2302,8 @@
     
-    %7D);%0A%0A            return true;%0A        %7D
 %0A   

Use proper example for FutureToy.