Attempting to make the remote query "cancelable".
authorJan Lahoda <jlahoda@netbeans.org>
Wed, 20 Jul 2011 11:36:24 +0200
changeset 6426a401241382f
parent 641 83b713bc8b36
child 643 25d9818aabce
Attempting to make the remote query "cancelable".
remoting/ide/api/manifest.mf
remoting/ide/api/src/org/netbeans/modules/jackpot30/remoting/api/WebUtilities.java
remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/CustomizeRemoteIndex.java
remoting/ide/jumpto/nbproject/genfiles.properties
remoting/ide/jumpto/nbproject/project.properties
remoting/ide/jumpto/nbproject/project.xml
remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToSymbol.java
remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToType.java
remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteQuery.java
remoting/ide/usages/manifest.mf
remoting/ide/usages/nbproject/genfiles.properties
remoting/ide/usages/nbproject/project.xml
remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java
     1.1 --- a/remoting/ide/api/manifest.mf	Tue Jul 19 15:04:59 2011 +0200
     1.2 +++ b/remoting/ide/api/manifest.mf	Wed Jul 20 11:36:24 2011 +0200
     1.3 @@ -2,5 +2,5 @@
     1.4  AutoUpdate-Show-In-Client: false
     1.5  OpenIDE-Module: org.netbeans.modules.jackpot30.remoting.api
     1.6  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/remotingapi/Bundle.properties
     1.7 -OpenIDE-Module-Specification-Version: 1.2
     1.8 +OpenIDE-Module-Specification-Version: 1.3
     1.9  
     2.1 --- a/remoting/ide/api/src/org/netbeans/modules/jackpot30/remoting/api/WebUtilities.java	Tue Jul 19 15:04:59 2011 +0200
     2.2 +++ b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remoting/api/WebUtilities.java	Wed Jul 20 11:36:24 2011 +0200
     2.3 @@ -47,12 +47,16 @@
     2.4  import java.net.URISyntaxException;
     2.5  import java.net.URL;
     2.6  import java.net.URLConnection;
     2.7 +import java.util.Arrays;
     2.8  import java.util.Collection;
     2.9 -import java.util.LinkedList;
    2.10 -import java.util.List;
    2.11 +import java.util.concurrent.atomic.AtomicBoolean;
    2.12 +import java.util.logging.Level;
    2.13 +import java.util.logging.Logger;
    2.14  import java.util.regex.Matcher;
    2.15  import java.util.regex.Pattern;
    2.16  import org.netbeans.api.annotations.common.CheckForNull;
    2.17 +import org.openide.util.RequestProcessor;
    2.18 +import org.openide.util.RequestProcessor.Task;
    2.19  
    2.20  /**
    2.21   *
    2.22 @@ -62,7 +66,13 @@
    2.23      private WebUtilities() {
    2.24      }
    2.25  
    2.26 -    public static @CheckForNull String requestStringResponse (URI uri) {
    2.27 +    private static final RequestProcessor LOADER = new RequestProcessor(WebUtilities.class.getName(), 100, true, false);
    2.28 +
    2.29 +    public static @CheckForNull String requestStringResponse (final URI uri, AtomicBoolean cancel) {
    2.30 +        final String[] result = new String[1];
    2.31 +        Task task = LOADER.create(new Runnable() {
    2.32 +            @Override
    2.33 +            public void run() {
    2.34          final StringBuffer sb = new StringBuffer ();
    2.35          final URL url;
    2.36          try {
    2.37 @@ -70,8 +80,6 @@
    2.38              final URLConnection urlConnection = url.openConnection ();
    2.39              urlConnection.connect ();
    2.40              final Object content = urlConnection.getContent ();
    2.41 -//            System.out.println (content);
    2.42 -//            System.out.println (content.getClass ());
    2.43              final InputStream inputStream = (InputStream) content;
    2.44              final BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream, "ASCII"));
    2.45              try {
    2.46 @@ -84,39 +92,31 @@
    2.47              } finally {
    2.48                  reader.close ();
    2.49              }
    2.50 -        } catch (IOException e) {
    2.51 -            e.printStackTrace ();  // TODO
    2.52 -            return null;
    2.53 -        }
    2.54 -        return sb.toString ();
    2.55 -    }
    2.56 -    
    2.57 -    public static Collection<? extends String> requestStringArrayResponse (URI uri) {
    2.58 -        final List<String> result = new LinkedList<String> ();
    2.59 -        final URL url;
    2.60 -        try {
    2.61 -            url = uri.toURL();
    2.62 -            final URLConnection urlConnection = url.openConnection ();
    2.63 -            urlConnection.connect ();
    2.64 -            final Object content = urlConnection.getContent ();
    2.65 -//            System.out.println (content);
    2.66 -//            System.out.println (content.getClass ());
    2.67 -            final InputStream inputStream = (InputStream) content;
    2.68 -            final BufferedReader reader = new BufferedReader (new InputStreamReader (inputStream, "ASCII"));
    2.69 -            try {
    2.70 -                for (;;) {
    2.71 -                    String line = reader.readLine ();
    2.72 -                    if (line == null)
    2.73 -                        break;
    2.74 -                    result.add (line);
    2.75 -                }
    2.76 -            } finally {
    2.77 -                reader.close ();
    2.78 -            }
    2.79 +            result[0] = sb.toString();
    2.80          } catch (IOException e) {
    2.81              e.printStackTrace ();  // TODO
    2.82          }
    2.83 -        return result;
    2.84 +            }
    2.85 +        });
    2.86 +
    2.87 +        task.schedule(0);
    2.88 +        
    2.89 +        while (!cancel.get()) {
    2.90 +            try {
    2.91 +                if (task.waitFinished(1000)) return result[0];
    2.92 +            } catch (InterruptedException ex) {
    2.93 +                Logger.getLogger(WebUtilities.class.getName()).log(Level.FINE, null, ex);
    2.94 +            }
    2.95 +        }
    2.96 +        return null;
    2.97 +    }
    2.98 +
    2.99 +    public static Collection<? extends String> requestStringArrayResponse (URI uri, AtomicBoolean cancel) {
   2.100 +        String content = requestStringResponse(uri, cancel);
   2.101 +        
   2.102 +        if (content == null) return null;
   2.103 +        
   2.104 +        return Arrays.asList(content.split("\n"));
   2.105      }
   2.106  
   2.107      private static String[] c = new String[] {"&", "<", ">", "\n", "\""}; // NOI18N
     3.1 --- a/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/CustomizeRemoteIndex.java	Tue Jul 19 15:04:59 2011 +0200
     3.2 +++ b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/CustomizeRemoteIndex.java	Wed Jul 20 11:36:24 2011 +0200
     3.3 @@ -349,7 +349,7 @@
     3.4                  if (!url.getPath().endsWith("/"))
     3.5                      url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + "/" + (url.getQuery() != null ? "?" + url.getQuery() : ""));
     3.6                  
     3.7 -                subindices = WebUtilities.requestStringArrayResponse(url.toURI().resolve("list"));
     3.8 +                subindices = WebUtilities.requestStringArrayResponse(url.toURI().resolve("list"), new AtomicBoolean());
     3.9  
    3.10                  if (subindices.isEmpty()) {
    3.11                     checkingIndexURLError.set("Not an index.");
     4.1 --- a/remoting/ide/jumpto/nbproject/genfiles.properties	Tue Jul 19 15:04:59 2011 +0200
     4.2 +++ b/remoting/ide/jumpto/nbproject/genfiles.properties	Wed Jul 20 11:36:24 2011 +0200
     4.3 @@ -3,6 +3,6 @@
     4.4  build.xml.stylesheet.CRC32=a56c6a5b@1.45
     4.5  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
     4.6  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
     4.7 -nbproject/build-impl.xml.data.CRC32=a2186361
     4.8 +nbproject/build-impl.xml.data.CRC32=51be11d3
     4.9  nbproject/build-impl.xml.script.CRC32=3404573f
    4.10 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.47
    4.11 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.45
     5.1 --- a/remoting/ide/jumpto/nbproject/project.properties	Tue Jul 19 15:04:59 2011 +0200
     5.2 +++ b/remoting/ide/jumpto/nbproject/project.properties	Wed Jul 20 11:36:24 2011 +0200
     5.3 @@ -1,3 +1,3 @@
     5.4  javac.source=1.6
     5.5  javac.compilerargs=-Xlint -Xlint:-serial
     5.6 -spec.version.base=1.1
     5.7 +spec.version.base=1.2
     6.1 --- a/remoting/ide/jumpto/nbproject/project.xml	Tue Jul 19 15:04:59 2011 +0200
     6.2 +++ b/remoting/ide/jumpto/nbproject/project.xml	Wed Jul 20 11:36:24 2011 +0200
     6.3 @@ -28,7 +28,7 @@
     6.4                      <build-prerequisite/>
     6.5                      <compile-dependency/>
     6.6                      <run-dependency>
     6.7 -                        <specification-version>1.0</specification-version>
     6.8 +                        <specification-version>1.3</specification-version>
     6.9                      </run-dependency>
    6.10                  </dependency>
    6.11                  <dependency>
     7.1 --- a/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToSymbol.java	Tue Jul 19 15:04:59 2011 +0200
     7.2 +++ b/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToSymbol.java	Wed Jul 20 11:36:24 2011 +0200
     7.3 @@ -42,6 +42,8 @@
     7.4  package org.netbeans.modules.jackpot30.jumpto;
     7.5  
     7.6  import java.io.File;
     7.7 +import java.io.IOException;
     7.8 +import java.io.Reader;
     7.9  import java.net.URI;
    7.10  import java.net.URISyntaxException;
    7.11  import java.util.ArrayList;
    7.12 @@ -104,30 +106,29 @@
    7.13      }
    7.14  
    7.15      @Override
    7.16 -    protected void compute(String text, SearchType searchType) {
    7.17 -        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
    7.18 -            try {
    7.19 -                URI resolved = new URI(ri.remote.toExternalForm() + "/symbol/search?path=" + WebUtilities.escapeForQuery(ri.remoteSegment) + "&prefix=" + WebUtilities.escapeForQuery(text) + "&querykind=" + WebUtilities.escapeForQuery(searchType.name()));
    7.20 -                String response = WebUtilities.requestStringResponse(resolved);
    7.21 +    protected URI computeURL(RemoteIndex idx, String text, SearchType searchType) {
    7.22 +        try {
    7.23 +            return new URI(idx.remote.toExternalForm() + "/symbol/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&prefix=" + WebUtilities.escapeForQuery(text) + "&querykind=" + WebUtilities.escapeForQuery(searchType.name()));
    7.24 +        } catch (URISyntaxException ex) {
    7.25 +            Exceptions.printStackTrace(ex);
    7.26 +            return null;
    7.27 +        }
    7.28 +    }
    7.29  
    7.30 -                if (response == null) continue;
    7.31 -                
    7.32 -                @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
    7.33 -                Map<String, Iterable<Map<String, Object>>> types = Pojson.load(LinkedHashMap.class, response);
    7.34 +    @Override
    7.35 +    protected Collection<? extends RemoteSymbolDescriptor> decode(RemoteIndex idx, Reader received) throws IOException {
    7.36 +        @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
    7.37 +        Map<String, Iterable<Map<String, Object>>> types = Pojson.load(LinkedHashMap.class, received);
    7.38  
    7.39 -                List<RemoteSymbolDescriptor> result = new ArrayList<RemoteSymbolDescriptor>();
    7.40 +        List<RemoteSymbolDescriptor> result = new ArrayList<RemoteSymbolDescriptor>();
    7.41  
    7.42 -                for (Entry<String, Iterable<Map<String, Object>>> e : types.entrySet()) {
    7.43 -                    for (Map<String, Object> properties : e.getValue()) {
    7.44 -                        result.add(new RemoteSymbolDescriptor(ri, properties));
    7.45 -                    }
    7.46 -                }
    7.47 -
    7.48 -                addResults(result);
    7.49 -            } catch (URISyntaxException ex) {
    7.50 -                Exceptions.printStackTrace(ex);
    7.51 +        for (Entry<String, Iterable<Map<String, Object>>> e : types.entrySet()) {
    7.52 +            for (Map<String, Object> properties : e.getValue()) {
    7.53 +                result.add(new RemoteSymbolDescriptor(idx, properties));
    7.54              }
    7.55          }
    7.56 +
    7.57 +        return result;
    7.58      }
    7.59  
    7.60      static final class RemoteSymbolDescriptor extends SymbolDescriptor implements SimpleNameable {
     8.1 --- a/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToType.java	Tue Jul 19 15:04:59 2011 +0200
     8.2 +++ b/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteGoToType.java	Wed Jul 20 11:36:24 2011 +0200
     8.3 @@ -42,9 +42,12 @@
     8.4  package org.netbeans.modules.jackpot30.jumpto;
     8.5  
     8.6  import java.io.File;
     8.7 +import java.io.IOException;
     8.8 +import java.io.Reader;
     8.9  import java.net.URI;
    8.10  import java.net.URISyntaxException;
    8.11  import java.util.ArrayList;
    8.12 +import java.util.Collection;
    8.13  import java.util.EnumSet;
    8.14  import java.util.LinkedHashMap;
    8.15  import java.util.List;
    8.16 @@ -101,31 +104,29 @@
    8.17      }
    8.18  
    8.19      @Override
    8.20 -    protected void compute(String text, SearchType searchType) {
    8.21 -        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
    8.22 -            try {
    8.23 -                //XXX: should send exact search type:
    8.24 -                URI resolved = new URI(ri.remote.toExternalForm() + "/type/search?path=" + WebUtilities.escapeForQuery(ri.remoteSegment) + "&prefix=" + WebUtilities.escapeForQuery(text));
    8.25 -                String response = WebUtilities.requestStringResponse(resolved);
    8.26 +    protected URI computeURL(RemoteIndex idx, String text, SearchType searchType) {
    8.27 +        try {
    8.28 +            return new URI(idx.remote.toExternalForm() + "/type/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&prefix=" + WebUtilities.escapeForQuery(text));
    8.29 +        } catch (URISyntaxException ex) {
    8.30 +            Exceptions.printStackTrace(ex);
    8.31 +            return null;
    8.32 +        }
    8.33 +    }
    8.34  
    8.35 -                if (response == null) continue;
    8.36 -                
    8.37 -                @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
    8.38 -                Map<String, List<String>> types = Pojson.load(LinkedHashMap.class, response);
    8.39 +    @Override
    8.40 +    protected Collection<? extends RemoteTypeDescriptor> decode(RemoteIndex idx, Reader received) throws IOException {
    8.41 +        @SuppressWarnings("unchecked") //XXX: should not trust something got from the network!
    8.42 +        Map<String, List<String>> types = Pojson.load(LinkedHashMap.class, received);
    8.43  
    8.44 -                List<RemoteTypeDescriptor> result = new ArrayList<RemoteTypeDescriptor>();
    8.45 +        List<RemoteTypeDescriptor> result = new ArrayList<RemoteTypeDescriptor>();
    8.46  
    8.47 -                for (Entry<String, List<String>> e : types.entrySet()) {
    8.48 -                    for (String binaryName : e.getValue()) {
    8.49 -                        result.add(new RemoteTypeDescriptor(ri, e.getKey(), binaryName));
    8.50 -                    }
    8.51 -                }
    8.52 -
    8.53 -                addResults(result);
    8.54 -            } catch (URISyntaxException ex) {
    8.55 -                Exceptions.printStackTrace(ex);
    8.56 +        for (Entry<String, List<String>> e : types.entrySet()) {
    8.57 +            for (String binaryName : e.getValue()) {
    8.58 +                result.add(new RemoteTypeDescriptor(idx, e.getKey(), binaryName));
    8.59              }
    8.60          }
    8.61 +
    8.62 +        return result;
    8.63      }
    8.64  
    8.65      static final class RemoteTypeDescriptor extends TypeDescriptor implements SimpleNameable {
     9.1 --- a/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteQuery.java	Tue Jul 19 15:04:59 2011 +0200
     9.2 +++ b/remoting/ide/jumpto/src/org/netbeans/modules/jackpot30/jumpto/RemoteQuery.java	Wed Jul 20 11:36:24 2011 +0200
     9.3 @@ -41,16 +41,24 @@
     9.4   */
     9.5  package org.netbeans.modules.jackpot30.jumpto;
     9.6  
     9.7 +import java.io.IOException;
     9.8 +import java.io.Reader;
     9.9 +import java.io.StringReader;
    9.10 +import java.net.URI;
    9.11  import java.util.ArrayList;
    9.12  import java.util.Collection;
    9.13  import java.util.List;
    9.14 +import java.util.concurrent.atomic.AtomicBoolean;
    9.15  import java.util.logging.Level;
    9.16  import java.util.logging.Logger;
    9.17  import org.netbeans.modules.jackpot30.jumpto.RemoteQuery.SimpleNameable;
    9.18  import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex;
    9.19 +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities;
    9.20  import org.netbeans.spi.jumpto.support.NameMatcher;
    9.21  import org.netbeans.spi.jumpto.support.NameMatcherFactory;
    9.22  import org.netbeans.spi.jumpto.type.SearchType;
    9.23 +import org.openide.util.Cancellable;
    9.24 +import org.openide.util.Exceptions;
    9.25  import org.openide.util.RequestProcessor;
    9.26  import org.openide.util.RequestProcessor.Task;
    9.27  
    9.28 @@ -64,6 +72,7 @@
    9.29  
    9.30      private String mostGenericQueryText;
    9.31      private List<R> results;
    9.32 +    private AtomicBoolean cancel;
    9.33      private Task currentWorker;
    9.34  
    9.35      protected final void performQuery(final String text, final SearchType searchType, ResultWrapper<R> result) {
    9.36 @@ -71,15 +80,14 @@
    9.37  
    9.38          synchronized (this) {
    9.39              if (mostGenericQueryText == null || !text.startsWith(mostGenericQueryText)) {
    9.40 -                if (currentWorker != null) currentWorker.cancel();
    9.41 +                if (currentWorker != null) {
    9.42 +                    cancel.set(true);
    9.43 +                    currentWorker.cancel();
    9.44 +                }
    9.45  
    9.46                  mostGenericQueryText = text;
    9.47  
    9.48 -                currentWorker = WORKER.create(new Runnable() {
    9.49 -                    @Override public void run() {
    9.50 -                        compute(text, searchType == SearchType.EXACT_NAME ? SearchType.PREFIX : searchType);
    9.51 -                    }
    9.52 -                });
    9.53 +                currentWorker = WORKER.create(new ComputeResult(text, searchType, cancel = new AtomicBoolean()));
    9.54  
    9.55                  currentWorker.schedule(0);
    9.56                  results = new ArrayList<R>();
    9.57 @@ -107,18 +115,54 @@
    9.58          }
    9.59      }
    9.60  
    9.61 -    protected abstract void compute(String text, SearchType searchType);
    9.62 +    protected abstract URI computeURL(RemoteIndex idx, String text, SearchType searchType);
    9.63 +    protected abstract Collection<? extends R> decode(RemoteIndex idx, Reader received) throws IOException;
    9.64  
    9.65 -    protected final synchronized void addResults(Collection<? extends R> r) {
    9.66 -        results.addAll(r);
    9.67 +    private void compute(String text, SearchType searchType, AtomicBoolean cancel) {
    9.68 +        for (RemoteIndex ri : RemoteIndex.loadIndices()) {
    9.69 +            URI url = computeURL(ri, text, searchType);
    9.70 +
    9.71 +            if (url == null) continue;
    9.72 +            
    9.73 +            String response = WebUtilities.requestStringResponse(url, cancel);
    9.74 +
    9.75 +            if (cancel.get()) return;
    9.76 +            if (response == null) continue;
    9.77 +
    9.78 +            Reader r = new StringReader(response);
    9.79 +            Collection<? extends R> decoded;
    9.80 +
    9.81 +            try {
    9.82 +                decoded = decode(ri, r);
    9.83 +            } catch (IOException ex) {
    9.84 +                Exceptions.printStackTrace(ex);
    9.85 +                continue;
    9.86 +            } finally {
    9.87 +                try {
    9.88 +                    r.close();
    9.89 +                } catch (IOException ex) {
    9.90 +                    Exceptions.printStackTrace(ex);
    9.91 +                }
    9.92 +            }
    9.93 +
    9.94 +            synchronized (this) {
    9.95 +                if (cancel.get()) return;
    9.96 +                results.addAll(decoded);
    9.97 +            }
    9.98 +        }
    9.99      }
   9.100  
   9.101      public void cancel() {
   9.102      }
   9.103  
   9.104 -    public void cleanup() {
   9.105 +    public synchronized void cleanup() {
   9.106 +        if (currentWorker != null) {
   9.107 +            cancel.set(true);
   9.108 +            currentWorker.cancel();
   9.109 +        }
   9.110          mostGenericQueryText = null;
   9.111          results = null;
   9.112 +        cancel = null;
   9.113          currentWorker = null;
   9.114      }
   9.115  
   9.116 @@ -133,4 +177,27 @@
   9.117          public String getSimpleName();
   9.118      }
   9.119  
   9.120 +    private class ComputeResult implements Runnable, Cancellable {
   9.121 +
   9.122 +        private final String text;
   9.123 +        private final SearchType searchType;
   9.124 +        private final AtomicBoolean cancel;
   9.125 +
   9.126 +        public ComputeResult(String text, SearchType searchType, AtomicBoolean cancel) {
   9.127 +            this.text = text;
   9.128 +            this.searchType = searchType;
   9.129 +            this.cancel = cancel;
   9.130 +        }
   9.131 +
   9.132 +        @Override public void run() {
   9.133 +            compute(text, searchType == SearchType.EXACT_NAME ? SearchType.PREFIX : searchType, cancel);
   9.134 +        }
   9.135 +
   9.136 +        @Override
   9.137 +        public boolean cancel() {
   9.138 +            cancel.set(true);
   9.139 +            return true;
   9.140 +        }
   9.141 +    }
   9.142 +
   9.143  }
    10.1 --- a/remoting/ide/usages/manifest.mf	Tue Jul 19 15:04:59 2011 +0200
    10.2 +++ b/remoting/ide/usages/manifest.mf	Wed Jul 20 11:36:24 2011 +0200
    10.3 @@ -3,5 +3,5 @@
    10.4  OpenIDE-Module: org.netbeans.modules.jackpot30.ide.usages
    10.5  OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/ide/usages/Bundle.properties
    10.6  OpenIDE-Module-Requires: org.openide.windows.WindowManager
    10.7 -OpenIDE-Module-Specification-Version: 1.1
    10.8 +OpenIDE-Module-Specification-Version: 1.2
    10.9  
    11.1 --- a/remoting/ide/usages/nbproject/genfiles.properties	Tue Jul 19 15:04:59 2011 +0200
    11.2 +++ b/remoting/ide/usages/nbproject/genfiles.properties	Wed Jul 20 11:36:24 2011 +0200
    11.3 @@ -1,8 +1,8 @@
    11.4 -build.xml.data.CRC32=6f03c856
    11.5 +build.xml.data.CRC32=7a1f3ac0
    11.6  build.xml.script.CRC32=58a6b47a
    11.7 -build.xml.stylesheet.CRC32=a56c6a5b@1.47
    11.8 +build.xml.stylesheet.CRC32=a56c6a5b@2.45
    11.9  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
   11.10  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   11.11 -nbproject/build-impl.xml.data.CRC32=6f03c856
   11.12 +nbproject/build-impl.xml.data.CRC32=7a1f3ac0
   11.13  nbproject/build-impl.xml.script.CRC32=583fd407
   11.14 -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.47
   11.15 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.45
    12.1 --- a/remoting/ide/usages/nbproject/project.xml	Tue Jul 19 15:04:59 2011 +0200
    12.2 +++ b/remoting/ide/usages/nbproject/project.xml	Wed Jul 20 11:36:24 2011 +0200
    12.3 @@ -46,7 +46,7 @@
    12.4                      <build-prerequisite/>
    12.5                      <compile-dependency/>
    12.6                      <run-dependency>
    12.7 -                        <specification-version>1.0</specification-version>
    12.8 +                        <specification-version>1.3</specification-version>
    12.9                      </run-dependency>
   12.10                  </dependency>
   12.11                  <dependency>
    13.1 --- a/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Tue Jul 19 15:04:59 2011 +0200
    13.2 +++ b/remoting/ide/usages/src/org/netbeans/modules/jackpot30/ide/usages/RemoteUsages.java	Wed Jul 20 11:36:24 2011 +0200
    13.3 @@ -51,7 +51,9 @@
    13.4  import java.net.URI;
    13.5  import java.net.URISyntaxException;
    13.6  import java.util.ArrayList;
    13.7 +import java.util.Collection;
    13.8  import java.util.List;
    13.9 +import java.util.concurrent.atomic.AtomicBoolean;
   13.10  import javax.lang.model.element.Element;
   13.11  import javax.swing.SwingUtilities;
   13.12  import javax.swing.text.JTextComponent;
   13.13 @@ -74,6 +76,7 @@
   13.14  import org.openide.filesystems.FileObject;
   13.15  import org.openide.filesystems.FileUtil;
   13.16  import org.openide.nodes.Node;
   13.17 +import org.openide.util.Cancellable;
   13.18  import org.openide.util.Exceptions;
   13.19  import org.openide.util.NbBundle.Messages;
   13.20  import org.openide.util.RequestProcessor;
   13.21 @@ -100,59 +103,7 @@
   13.22          DialogDescriptor dd = new DialogDescriptor("Querying remote server(s), please wait", "Please Wait", true, new Object[0], null, DialogDescriptor.DEFAULT_ALIGN, null, null);
   13.23          final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
   13.24  
   13.25 -        WORKER.post(new Runnable() {
   13.26 -            @Override public void run() {
   13.27 -                try {
   13.28 -                    final ElementHandle<?>[] handle = new ElementHandle<?>[1];
   13.29 -                    final String[] serialized = new String[1];
   13.30 -
   13.31 -                    JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
   13.32 -                        @Override public void run(CompilationController parameter) throws Exception {
   13.33 -                            parameter.toPhase(JavaSource.Phase.RESOLVED);
   13.34 -
   13.35 -                            TreePath tp = parameter.getTreeUtilities().pathFor(pos);
   13.36 -                            Element el = parameter.getTrees().getElement(tp);
   13.37 -
   13.38 -                            if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
   13.39 -                                serialized[0] = serialize(handle[0] = ElementHandle.create(el));
   13.40 -                            }
   13.41 -                        }
   13.42 -                    }, true);
   13.43 -
   13.44 -                    if (serialized[0] == null) return ; //XXX: warn user!
   13.45 -
   13.46 -                    List<FileObject> result = new ArrayList<FileObject>();
   13.47 -
   13.48 -                    for (RemoteIndex idx : RemoteIndex.loadIndices()) {
   13.49 -                        URI resolved = new URI(idx.remote.toExternalForm() + "/usages/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&signatures=" + WebUtilities.escapeForQuery(serialized[0]));
   13.50 -
   13.51 -                        for (String path : WebUtilities.requestStringArrayResponse(resolved)) {
   13.52 -                            File f = new File(idx.folder, path);
   13.53 -
   13.54 -                            result.add(FileUtil.toFileObject(f));
   13.55 -                        }
   13.56 -                    }
   13.57 -
   13.58 -                    final Node view = Nodes.constructSemiLogicalView(result, handle[0]);
   13.59 -
   13.60 -                    SwingUtilities.invokeLater(new Runnable() {
   13.61 -                        @Override public void run() {
   13.62 -                            RemoteUsagesWindowTopComponent.openFor(view);
   13.63 -                        }
   13.64 -                    });
   13.65 -                } catch (URISyntaxException ex) {
   13.66 -                    Exceptions.printStackTrace(ex);
   13.67 -                } catch (IOException ex) {
   13.68 -                    Exceptions.printStackTrace(ex);
   13.69 -                } finally {
   13.70 -                    SwingUtilities.invokeLater(new Runnable() {
   13.71 -                        @Override public void run() {
   13.72 -                            d.setVisible(false);
   13.73 -                        }
   13.74 -                    });
   13.75 -                }
   13.76 -            }
   13.77 -        });
   13.78 +        WORKER.post(new FindUsagesWorker(file, pos, d));
   13.79  
   13.80          d.setVisible(true);
   13.81      }
   13.82 @@ -186,4 +137,81 @@
   13.83  
   13.84          return result.toString();
   13.85      }
   13.86 +
   13.87 +    private static class FindUsagesWorker implements Runnable, Cancellable {
   13.88 +
   13.89 +        private final FileObject file;
   13.90 +        private final int pos;
   13.91 +        private final Dialog d;
   13.92 +        private final AtomicBoolean cancel;
   13.93 +
   13.94 +        public FindUsagesWorker(FileObject file, int pos, Dialog d) {
   13.95 +            this.file = file;
   13.96 +            this.pos = pos;
   13.97 +            this.d = d;
   13.98 +            this.cancel = new AtomicBoolean();
   13.99 +        }
  13.100 +
  13.101 +        @Override public void run() {
  13.102 +            try {
  13.103 +                final ElementHandle<?>[] handle = new ElementHandle<?>[1];
  13.104 +                final String[] serialized = new String[1];
  13.105 +
  13.106 +                JavaSource.forFileObject(file).runUserActionTask(new Task<CompilationController>() {
  13.107 +                    @Override public void run(CompilationController parameter) throws Exception {
  13.108 +                        parameter.toPhase(JavaSource.Phase.RESOLVED);
  13.109 +
  13.110 +                        TreePath tp = parameter.getTreeUtilities().pathFor(pos);
  13.111 +                        Element el = parameter.getTrees().getElement(tp);
  13.112 +
  13.113 +                        if (el != null && Common.SUPPORTED_KINDS.contains(el.getKind())) {
  13.114 +                            serialized[0] = serialize(handle[0] = ElementHandle.create(el));
  13.115 +                        }
  13.116 +                    }
  13.117 +                }, true);
  13.118 +
  13.119 +                if (serialized[0] == null) return ; //XXX: warn user!
  13.120 +
  13.121 +                List<FileObject> result = new ArrayList<FileObject>();
  13.122 +
  13.123 +                for (RemoteIndex idx : RemoteIndex.loadIndices()) {
  13.124 +                    URI resolved = new URI(idx.remote.toExternalForm() + "/usages/search?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&signatures=" + WebUtilities.escapeForQuery(serialized[0]));
  13.125 +                    Collection<? extends String> response = WebUtilities.requestStringArrayResponse(resolved, cancel);
  13.126 +
  13.127 +                    if (cancel.get()) return;
  13.128 +                    if (response == null) continue;
  13.129 +                    
  13.130 +                    for (String path : response) {
  13.131 +                        File f = new File(idx.folder, path);
  13.132 +
  13.133 +                        result.add(FileUtil.toFileObject(f));
  13.134 +                    }
  13.135 +                }
  13.136 +
  13.137 +                final Node view = Nodes.constructSemiLogicalView(result, handle[0]);
  13.138 +
  13.139 +                SwingUtilities.invokeLater(new Runnable() {
  13.140 +                    @Override public void run() {
  13.141 +                        RemoteUsagesWindowTopComponent.openFor(view);
  13.142 +                    }
  13.143 +                });
  13.144 +            } catch (URISyntaxException ex) {
  13.145 +                Exceptions.printStackTrace(ex);
  13.146 +            } catch (IOException ex) {
  13.147 +                Exceptions.printStackTrace(ex);
  13.148 +            } finally {
  13.149 +                cancel.set(true);
  13.150 +                SwingUtilities.invokeLater(new Runnable() {
  13.151 +                    @Override public void run() {
  13.152 +                        d.setVisible(false);
  13.153 +                    }
  13.154 +                });
  13.155 +            }
  13.156 +        }
  13.157 +
  13.158 +        @Override public boolean cancel() {
  13.159 +            cancel.set(true);
  13.160 +            return true;
  13.161 +        }
  13.162 +    }
  13.163  }