{"action":"created","issue":{"url":"https://api.github.com/repos/spotify/dns-java/issues/8","labels_url":"https://api.github.com/repos/spotify/dns-java/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/spotify/dns-java/issues/8/comments","events_url":"https://api.github.com/repos/spotify/dns-java/issues/8/events","html_url":"https://github.com/spotify/dns-java/issues/8","id":59692743,"number":8,"title":"Add support for polling SRV records and getting update notifications","user":{"login":"rouzwawi","id":655452,"avatar_url":"https://avatars.githubusercontent.com/u/655452?v=3","gravatar_id":"","url":"https://api.github.com/users/rouzwawi","html_url":"https://github.com/rouzwawi","followers_url":"https://api.github.com/users/rouzwawi/followers","following_url":"https://api.github.com/users/rouzwawi/following{/other_user}","gists_url":"https://api.github.com/users/rouzwawi/gists{/gist_id}","starred_url":"https://api.github.com/users/rouzwawi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rouzwawi/subscriptions","organizations_url":"https://api.github.com/users/rouzwawi/orgs","repos_url":"https://api.github.com/users/rouzwawi/repos","events_url":"https://api.github.com/users/rouzwawi/events{/privacy}","received_events_url":"https://api.github.com/users/rouzwawi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spotify/dns-java/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-03T19:32:45Z","updated_at":"2015-03-03T19:55:04Z","closed_at":null,"body":"I've started porting some code from another internal Spotify library that implements this functionality on top of `dns-java`. I figured I could open this issue to discuss different design options.\r\n\r\nSome things I want the feature to achieve:\r\n\r\n* Give a mechanism for getting notified when the set of SRV records for a fqdn change\r\n* Make it possible to use derivative values of `LookupResult` as the current set, with notifications only happening if that derived set changes\r\n\r\n### Suggested API\r\n\r\n```java\r\ninterface PollingDnsSrvResolver<T> {\r\n  EndpointProvider<T> poll(String fqdn, long refreshInterval, TimeUnit refreshIntervalUnit);\r\n}\r\n\r\ninterface EndpointProvider<T> {\r\n  Set<T> getEndpoints(); // gets the last seen set of endpoints\r\n  void setListener(Listener<T> listener, boolean fire);\r\n\r\n  interface Listener<T> {\r\n    void endpointsChanged(Set<T> current, Set<T> previous);\r\n  }\r\n```\r\n\r\nAnd the construction API would simply be:\r\n\r\n```java\r\nDnsSrvResolver resolver = DnsSrvResolvers.newBuilder()\r\n    // configure\r\n    .build();\r\n\r\nPollingDnsSrvResolver<LookupResult> poller =\r\n    DnsSrvResolvers.pollingResolver(resolver);\r\n```\r\n\r\nor\r\n\r\n```java\r\nDnsSrvResolver resolver = DnsSrvResolvers.newBuilder()\r\n    // configure\r\n    .build();\r\n\r\nPollingDnsSrvResolver<String> poller =\r\n    DnsSrvResolvers.pollingResolver(resolver, (lookup) -> lookupToString(lookup));\r\n```\r\n\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/spotify/dns-java/issues/comments/77021351","html_url":"https://github.com/spotify/dns-java/issues/8#issuecomment-77021351","issue_url":"https://api.github.com/repos/spotify/dns-java/issues/8","id":77021351,"user":{"login":"rouzwawi","id":655452,"avatar_url":"https://avatars.githubusercontent.com/u/655452?v=3","gravatar_id":"","url":"https://api.github.com/users/rouzwawi","html_url":"https://github.com/rouzwawi","followers_url":"https://api.github.com/users/rouzwawi/followers","following_url":"https://api.github.com/users/rouzwawi/following{/other_user}","gists_url":"https://api.github.com/users/rouzwawi/gists{/gist_id}","starred_url":"https://api.github.com/users/rouzwawi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rouzwawi/subscriptions","organizations_url":"https://api.github.com/users/rouzwawi/orgs","repos_url":"https://api.github.com/users/rouzwawi/repos","events_url":"https://api.github.com/users/rouzwawi/events{/privacy}","received_events_url":"https://api.github.com/users/rouzwawi/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T19:55:04Z","updated_at":"2015-03-03T19:55:04Z","body":"@spkrka good points.\r\n\r\nProviding a `ScheduledExecutorService` when creating the poller makes sense, will add that.\r\n\r\nI think having a way to cancel individual lookups would be useful too. Actually the `EndpointProvider` interface has a `close()` method that somehow got lost in the description. And a close method on `PollingDnsSrvResolver` would then cancel all `EndpointProvider`s created from that resolver.\r\n\r\nOn a side note; I'm not sure if I like the `EndpointProvider` name. Can you think of something more descriptive?"}}