-/*
+/* -*- Mode: Java; tab-width: 4 -*-
+ *
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
import com.apple.dnssd.*;
-class BrowserApp implements ListSelectionListener, ResolveListener
+class BrowserApp implements ListSelectionListener, ResolveListener, Runnable
{
static BrowserApp app;
JFrame frame;
JList domainPane, servicesPane, servicePane;
DNSSDService servicesBrowser, serviceBrowser, domainBrowser;
JLabel hostLabel, portLabel;
+ String hostNameForUpdate;
+ int portForUpdate;
public BrowserApp()
{
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
}