mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Make resolver-dnsjava, -minidns initializer
and OSGi components. There is really no need to treat them different then resolver-javax. This also allows the removal of the DNSUtil.init() method.
This commit is contained in:
parent
a5eebf3840
commit
0c0737942c
10 changed files with 55 additions and 50 deletions
|
@ -19,6 +19,8 @@ package org.jivesoftware.smack.util.dns.minidns;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.initializer.SmackAndOsgiInitializer;
|
||||
import org.jivesoftware.smack.util.DNSUtil;
|
||||
import org.jivesoftware.smack.util.dns.DNSResolver;
|
||||
import org.jivesoftware.smack.util.dns.SRVRecord;
|
||||
import org.jxmpp.util.cache.ExpirationCache;
|
||||
|
@ -37,14 +39,14 @@ import de.measite.minidns.record.SRV;
|
|||
* This implementation uses the <a href="https://github.com/rtreffer/minidns/">minidns</a> implementation for
|
||||
* resolving DNS addresses.
|
||||
*/
|
||||
public class MiniDnsResolver implements DNSResolver {
|
||||
public class MiniDnsResolver extends SmackAndOsgiInitializer implements DNSResolver {
|
||||
|
||||
private static final long ONE_DAY = 24*60*60*1000;
|
||||
private static final MiniDnsResolver instance = new MiniDnsResolver();
|
||||
private static final ExpirationCache<Question, DNSMessage> cache = new ExpirationCache<Question, DNSMessage>(10, ONE_DAY);
|
||||
private final Client client;
|
||||
|
||||
private MiniDnsResolver() {
|
||||
public MiniDnsResolver() {
|
||||
client = new Client(new DNSCache() {
|
||||
|
||||
@Override
|
||||
|
@ -81,4 +83,15 @@ public class MiniDnsResolver implements DNSResolver {
|
|||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
DNSUtil.setDNSResolver(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> initialize() {
|
||||
setup();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0"
|
||||
enabled="true" immediate="true" name="Smack Resolver JavaX API">
|
||||
<implementation
|
||||
class="org.jivesoftware.smack.util.dns.minidns.MiniDnsResolver" />
|
||||
</scr:component>
|
Loading…
Add table
Add a link
Reference in a new issue