#108 Early addServiceListener ignored

open
nobody
None
5
2013-01-24
2011-11-01
Anonymous
No

I am seeing an odd behavior when using JmmDNS. If I add a ServiceListener too soon after initially getting the JmmDNS object from the factory, that listener never receives any updates. The required delay seems to be substantial, 1-3 seconds. I have gotten around this by creating a wrapper that delays the addition of any listeners that come in before the delay has elapsed.

Can't understand why this should be the case, but I've tested it by creating a series of listeners with sequential IDs that simply print out their own IDs whenever they receive any kind of notification, which are added sequentially after incremental delays. It is always the case that some subset of the listeners, 1 to n, don't receive updates, while the remainder, n+1 to N, all receive them. I assume that the delay is associated with initializing the network, but don't understand why listeners added before the initialization completes seem to be ignored.

Discussion


  • Anonymous
    2011-11-09

    I recently had the same issue - the listeners get added to the currently detected interfaces, but if they're not detected yet, they don't get added at all.

    Rather than using a fairly random delay - I hooked up jmmdns with a NetworkTopologyListener and added/removed my listeners whenever the network topology is detected to have changed.

    Perhaps it would be good to do this internally though? i.e. if someone has called addServiceTypeListener or addServiceListener, it performs like a standing request, rather than an instantaneous one. i.e. jmmdns remembers the call to add a listener of the specified type, and whenever the topology changes, it automatically adds/removes the appropriate listeners on that interface.