2009-03-10 20:00:19 UTC
Hey all, random question. I added a service listener and was having a load of trouble getting it to actually resolve a service. It would add services fine, but there seemed to be some blocking/threading/timing issues that made it randomly succeed/fail at resolving the service (the callback would either get called or not get called).
I started requesting the info in a new thread, and this seems to have totally fixed the problem, but I would really like to know what actually happened. In the examples, and in the browser, they do not seem to have to do this workaround.
This is all running on a local machine, with one client and one host on the same machine with different names
Thanks,
hamy
____________________________________
private class ServiceRequestor implements Runnable {
private ServiceEvent event_;
public ServiceRequestor(ServiceEvent e) { event_ = e; }
public void run() { jmdns_.requestServiceInfo(event_.getType(), event_.getName()); }
}
private class HostMonitorListener implements ServiceListener {
// TODO bad practice that I am accessing private parent members...
public void serviceAdded(ServiceEvent e) {
log("found service " + e.getName());
if (e.getName().equals(HostImpl.SERVICENAME)) {
SwingUtilities.invokeLater(new ServiceRequestor(e));
}
}
public void serviceRemoved(ServiceEvent e) {
log("service " + e.getName() + " removed");
}
public void serviceResolved(ServiceEvent e) {
log("service finally resolved");
if (e.getName().equals(HostImpl.SERVICENAME)) {
ServiceInfo info = e.getInfo();
if (info == null)
return;
String hostURI = "
rmi://" + info.getHostAddress() + ":"
+ info.getPort() + "/" + info.getName();
log("Found uri of " + hostURI);
Host h = (Host) RemotingUtils.lookupRMIService(hostURI,
Host.class);
hostList_.add(h);
}
}