javax.jmdns.impl

Class DNSCache


public class DNSCache
extends java.lang.Object

A table of DNS entries. This is a hash table which can handle multiple entries with the same name.

Storing multiple entries with the same name is implemented using a linked list of CacheNode's.

The current implementation of the API of DNSCache does expose the cache nodes to clients. Clients must explicitly deal with the nodes when iterating over entries in the cache. Here's how to iterate over all entries in the cache:

 for (Iterator i=dnscache.iterator(); i.hasNext(); ) {
    for (DNSCache.CacheNode n = (DNSCache.CacheNode) i.next(); n != null; n.next()) {
       DNSEntry entry = n.getValue();
       ...do something with entry...
    }
 }
 

And here's how to iterate over all entries having a given name:

 for (DNSCache.CacheNode n = (DNSCache.CacheNode) dnscache.find(name); n != null; n.next()) {
     DNSEntry entry = n.getValue();
     ...do something with entry...
 }
 

Nested Class Summary

static class
DNSCache.CacheNode
Cache nodes are used to implement storage of multiple DNSEntry's of the same name in the cache.

Constructor Summary

DNSCache(int size)
Create a table with a given initial size.

Method Summary

void
add(DNSEntry entry)
Adds an entry to the table.
void
clear()
Clears the cache.
DNSCache.CacheNode
find(String name)
Iterate only over items with matching name.
DNSEntry
get(String name, int type, int clazz)
Get a matching DNS entry from the table.
DNSEntry
get(DNSEntry entry)
Get a matching DNS entry from the table (using equals).
Iterator
iterator()
Iterates over all cache nodes.
void
print()
List all entries for debugging.
boolean
remove(DNSEntry entry)
Remove a specific entry from the table.
String
toString()

Constructor Details

DNSCache

public DNSCache(int size)
Create a table with a given initial size.

Method Details

add

public void add(DNSEntry entry)
Adds an entry to the table.

clear

public void clear()
Clears the cache.

find

public DNSCache.CacheNode find(String name)
Iterate only over items with matching name. Returns an instance of DNSCache.CacheNode or null. If an instance is returned, it is the first node of a linked list. To retrieve all entries, one must iterate over this linked list.

get

public DNSEntry get(String name,
                    int type,
                    int clazz)
Get a matching DNS entry from the table.

get

public DNSEntry get(DNSEntry entry)
Get a matching DNS entry from the table (using equals). Returns the entry that was found.

iterator

public Iterator iterator()
Iterates over all cache nodes. The iterator returns instances of DNSCache.CacheNode. Each instance returned is the first node of a linked list. To retrieve all entries, one must iterate over this linked list. See code snippets in the header of the class.

print

public void print()
List all entries for debugging.

remove

public boolean remove(DNSEntry entry)
Remove a specific entry from the table. Returns true if the entry was found.

toString

public String toString()