Crossfire JXClient, Trunk  R20561
com.realtime.crossfire.jxclient.metaserver.ServerCache Class Reference

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

+ Collaboration diagram for com.realtime.crossfire.jxclient.metaserver.ServerCache:

Public Member Functions

void expire (final long timestamp)
 Expires entries older than a given timestamp from the cache. More...
 
Map< String, MetaserverEntrygetAll ()
 Returns all cached entries. More...
 
void put (@NotNull final MetaserverEntry metaserverEntry)
 Adds an entry to the cache. More...
 
void save ()
 Saves all entries to the backing file. More...
 
 ServerCache (@Nullable final File file)
 Creates a new instance. More...
 

Static Public Member Functions

static String makeKey (@NotNull final MetaserverEntry metaserverEntry)
 Returns the key for a metaserver entry. More...
 

Static Public Attributes

static final CharSequence DEFAULT_ENTRY_LOCALHOST = "0|localhost|0|--|Local server. Start server before you try to connect.|0|0|0|||"
 The default entry for the "localhost" server. More...
 

Private Member Functions

boolean addEntry (@NotNull final CharSequence metaserverEntryLine, final long timestamp)
 Parses a metaserver entry line and adds the result to entries. More...
 
void load ()
 Loads the entries from the backing file. More...
 
void saveInternal (@NotNull final File file) throws IOException
 Saves all entries to the backing file. More...
 

Private Attributes

final Map< String, Infoentries = new HashMap<>()
 The cached entries. More...
 
final File file
 The backing file. More...
 

Detailed Description

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

Author
Andreas Kirschbaum

Definition at line 44 of file ServerCache.java.

Constructor & Destructor Documentation

◆ ServerCache()

com.realtime.crossfire.jxclient.metaserver.ServerCache.ServerCache ( @Nullable final File  file)

Creates a new instance.

Parameters
filethe backing file or
null
to not cache on disk

Definition at line 69 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.ServerCache.file, and com.realtime.crossfire.jxclient.metaserver.ServerCache.load().

+ Here is the call graph for this function:

Member Function Documentation

◆ addEntry()

boolean com.realtime.crossfire.jxclient.metaserver.ServerCache.addEntry ( @NotNull final CharSequence  metaserverEntryLine,
final long  timestamp 
)
private

Parses a metaserver entry line and adds the result to entries.

Parameters
metaserverEntryLinethe metaserver entry line to parse
timestampthe query timestamp
Returns
whether the line was parsed correctly

Definition at line 181 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.ServerCache.makeKey(), and com.realtime.crossfire.jxclient.metaserver.MetaserverEntryParser.parseEntry().

Referenced by com.realtime.crossfire.jxclient.metaserver.ServerCache.load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expire()

void com.realtime.crossfire.jxclient.metaserver.ServerCache.expire ( final long  timestamp)

Expires entries older than a given timestamp from the cache.

Parameters
timestampthe timestamp

Definition at line 88 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.Info.getTimestamp().

Referenced by com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAll()

Map<String, MetaserverEntry> com.realtime.crossfire.jxclient.metaserver.ServerCache.getAll ( )

Returns all cached entries.

The returned set may be modified by the caller.

Returns
the cached entries; maps key to metaserver entry

Definition at line 106 of file ServerCache.java.

Referenced by com.realtime.crossfire.jxclient.metaserver.Metaserver.Metaserver(), and com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

+ Here is the caller graph for this function:

◆ load()

void com.realtime.crossfire.jxclient.metaserver.ServerCache.load ( )
private

Loads the entries from the backing file.

Definition at line 127 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.ServerCache.addEntry().

Referenced by com.realtime.crossfire.jxclient.metaserver.ServerCache.ServerCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeKey()

static String com.realtime.crossfire.jxclient.metaserver.ServerCache.makeKey ( @NotNull final MetaserverEntry  metaserverEntry)
static

Returns the key for a metaserver entry.

Parameters
metaserverEntrythe metaserver entry
Returns
the key

Definition at line 120 of file ServerCache.java.

Referenced by com.realtime.crossfire.jxclient.metaserver.ServerCache.addEntry(), com.realtime.crossfire.jxclient.metaserver.ServerCache.put(), and com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

+ Here is the caller graph for this function:

◆ put()

void com.realtime.crossfire.jxclient.metaserver.ServerCache.put ( @NotNull final MetaserverEntry  metaserverEntry)

Adds an entry to the cache.

Overwrites old entries for the same hostname.

Parameters
metaserverEntrythe entry to add

Definition at line 80 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.ServerCache.makeKey().

Referenced by com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

void com.realtime.crossfire.jxclient.metaserver.ServerCache.save ( )

Saves all entries to the backing file.

Definition at line 194 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.ServerCache.saveInternal().

Referenced by com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveInternal()

void com.realtime.crossfire.jxclient.metaserver.ServerCache.saveInternal ( @NotNull final File  file) throws IOException
private

Saves all entries to the backing file.

Parameters
filethe file to write
Exceptions
IOExceptionif an I/O error occurs

Definition at line 211 of file ServerCache.java.

References com.realtime.crossfire.jxclient.metaserver.MetaserverEntryParser.format().

Referenced by com.realtime.crossfire.jxclient.metaserver.ServerCache.save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ DEFAULT_ENTRY_LOCALHOST

final CharSequence com.realtime.crossfire.jxclient.metaserver.ServerCache.DEFAULT_ENTRY_LOCALHOST = "0|localhost|0|--|Local server. Start server before you try to connect.|0|0|0|||"
static

The default entry for the "localhost" server.

Definition at line 50 of file ServerCache.java.

Referenced by com.realtime.crossfire.jxclient.metaserver.Metaserver.updateMetaList().

◆ entries

final Map<String, Info> com.realtime.crossfire.jxclient.metaserver.ServerCache.entries = new HashMap<>()
private

The cached entries.

Maps key (see makeKey(MetaserverEntry)) to Info instance for the metaserver entry.

Definition at line 57 of file ServerCache.java.

◆ file

final File com.realtime.crossfire.jxclient.metaserver.ServerCache.file
private

The backing file.

Definition at line 63 of file ServerCache.java.

Referenced by com.realtime.crossfire.jxclient.metaserver.ServerCache.ServerCache().


The documentation for this class was generated from the following file: