com.realtime.crossfire.jxclient.metaserver
Class ServerCache

java.lang.Object
  extended by com.realtime.crossfire.jxclient.metaserver.ServerCache

public class ServerCache
extends java.lang.Object

Maintains a set of known servers backed up in a file.


Field Summary
static java.lang.CharSequence DEFAULT_ENTRY_LOCALHOST
          The default entry for the "localhost" server.
private  java.util.Map<java.lang.String,Info> entries
          The cached entries.
private  java.io.File file
          The backing file.
 
Constructor Summary
ServerCache(java.io.File file)
          Create a new instance.
 
Method Summary
private  boolean addEntry(java.lang.CharSequence metaserverEntryLine, long timestamp)
          Parses a metaserver entry line and adds the result to entries.
 void expire(long timestamp)
          Expire entries older than a given timestamp from the cache.
 java.util.Map<java.lang.String,MetaserverEntry> getAll()
          Return all cached entries.
private  void load()
          Load the entries from the backing file.
static java.lang.String makeKey(MetaserverEntry metaserverEntry)
          Return the key for a metaserver entry.
 void put(MetaserverEntry metaserverEntry)
          Add an entry to the cache.
 void save()
          Save all entries to the backing file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENTRY_LOCALHOST

@NotNull
public static final java.lang.CharSequence DEFAULT_ENTRY_LOCALHOST
The default entry for the "localhost" server.


entries

@NotNull
private final java.util.Map<java.lang.String,Info> entries
The cached entries. Maps key (see makeKey(MetaserverEntry)) to Info instance for the metaserver entry.


file

@NotNull
private final java.io.File file
The backing file.

Constructor Detail

ServerCache

public ServerCache(@NotNull
                   java.io.File file)
Create a new instance.

Parameters:
file - The backing file.
Method Detail

addEntry

private boolean addEntry(@NotNull
                         java.lang.CharSequence metaserverEntryLine,
                         long timestamp)
Parses a metaserver entry line and adds the result to entries.

Parameters:
metaserverEntryLine - the metaserver entry line to parse
timestamp - the query timestamp
Returns:
whether the line was parsed correctly

expire

public void expire(long timestamp)
Expire entries older than a given timestamp from the cache.

Parameters:
timestamp - The timestamp.

getAll

@NotNull
public java.util.Map<java.lang.String,MetaserverEntry> getAll()
Return all cached entries. The returned set may be modified by the caller.

Returns:
The cached entries; maps key to metaserver entry.

load

private void load()
Load the entries from the backing file.


makeKey

@NotNull
public static java.lang.String makeKey(@NotNull
                                               MetaserverEntry metaserverEntry)
Return the key for a metaserver entry.

Parameters:
metaserverEntry - The metaserver entry.
Returns:
The key.

put

public void put(@NotNull
                MetaserverEntry metaserverEntry)
Add an entry to the cache. Overwrites old entries for the same hostname.

Parameters:
metaserverEntry - The entry to add.

save

public void save()
Save all entries to the backing file.