Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.zeroconf.jmdns
Class DNSCache

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.zeroconf.jmdns.DNSCache

 class DNSCache
extends 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...
 }
 

Version:
%I%, %G%
Author:
Arthur van Hoff, Werner Randelshofer, Rick Blair

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(DNSEntry entry)
          Get a matching DNS entry from the table (using equals).
 DNSEntry get(String name, int type, int clazz)
          Get a matching DNS entry from the table.
 Iterator<DNSCache.CacheNode> 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DNSCache

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

Parameters:
size - initial size.
Method Detail

clear

public void clear()
Clears the cache.


add

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

Parameters:
entry - added to the table.

remove

public boolean remove(DNSEntry entry)
Remove a specific entry from the table.

Parameters:
entry - removed from table.
Returns:
Returns true if the entry was found.

get

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

Parameters:
entry - to be found in table.
Returns:
Returns the entry that was found.

get

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

Parameters:
name -
type -
clazz -
Returns:
Return the entry if found, null otherwise.

iterator

public Iterator<DNSCache.CacheNode> 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.

Returns:
Returns iterator with instances of DNSCache.CacheNode.

find

public DNSCache.CacheNode find(String name)
Iterate only over items with matching name. 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.

Parameters:
name - to be found.
Returns:
Returns an instance of DNSCache.CacheNode or null.

print

public void print()
List all entries for debugging.


toString

public String toString()
Overrides:
toString in class Object

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.