]> git.saurik.com Git - apple/mdnsresponder.git/blobdiff - Clients/Java/BrowserApp.java
mDNSResponder-320.10.80.tar.gz
[apple/mdnsresponder.git] / Clients / Java / BrowserApp.java
index cbdd200713b7ef22808025840e82a712054eaddb..8f512151658b25e885d511bab5f967656619905a 100644 (file)
@@ -54,7 +54,7 @@ import javax.swing.event.*;
 import com.apple.dnssd.*;
 
 
-class  BrowserApp implements ListSelectionListener, ResolveListener
+class  BrowserApp implements ListSelectionListener, ResolveListener, Runnable
 {
        static BrowserApp       app;
        JFrame                          frame;
@@ -63,6 +63,8 @@ class BrowserApp implements ListSelectionListener, ResolveListener
        JList                           domainPane, servicesPane, servicePane;
        DNSSDService            servicesBrowser, serviceBrowser, domainBrowser;
        JLabel                          hostLabel, portLabel;
+       String                          hostNameForUpdate;
+       int                                     portForUpdate;
 
        public          BrowserApp()
        {
@@ -170,22 +172,43 @@ class     BrowserApp implements ListSelectionListener, ResolveListener
                                                                                serviceList.getNthServiceName( newSel), 
                                                                                serviceList.getNthRegType( newSel), 
                                                                                serviceList.getNthDomain( newSel), 
-                                                                               new SwingResolveListener( this));
+                                                                               this);
                                }
                        }
                }
                catch ( Exception ex) { terminateWithException( ex); }
        }
 
+       public void run()
+       {
+               hostLabel.setText( hostNameForUpdate);
+               portLabel.setText( String.valueOf( portForUpdate));             
+       }
+
        public void     serviceResolved( DNSSDService resolver, int flags, int ifIndex, String fullName, 
                                                                String hostName, int port, TXTRecord txtRecord)
        {
-               hostLabel.setText( hostName);
-               portLabel.setText( String.valueOf( port));
+               // We want to update GUI on the AWT event dispatching thread, but we can't stop
+               // the resolve from that thread, since stop() is synchronized with this callback.
+               // So, we stop the resolve on this thread, then invokeAndWait on the AWT event thread.
+
+               resolver.stop();
+
+               hostNameForUpdate = hostName;
+               portForUpdate = port;
+
+               try {
+                       SwingUtilities.invokeAndWait(this);
+               }
+               catch ( Exception e)
+               {
+                       e.printStackTrace();
+               }
        }
 
        public void     operationFailed( DNSSDService service, int errorCode)
        {
+               service.stop();
                // handle failure here
        }