Class ServerCache


  • public class ServerCache
    extends java.lang.Object
    Maintains a set of known servers backed up in a file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static @NotNull java.lang.CharSequence DEFAULT_ENTRY_LOCALHOST
      The default entry for the "localhost" server.
    • Constructor Summary

      Constructors 
      Constructor Description
      ServerCache​(@Nullable java.nio.file.Path file)
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void expire​(long timestamp)
      Expires entries older than a given timestamp from the cache.
      @NotNull java.util.Map<java.lang.String,​MetaserverEntry> getAll()
      Returns all cached entries.
      static @NotNull java.lang.String makeKey​(@NotNull MetaserverEntry metaserverEntry)
      Returns the key for a metaserver entry.
      void put​(@NotNull MetaserverEntry metaserverEntry)
      Adds an entry to the cache.
      void save()
      Saves 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 @NotNull java.lang.CharSequence DEFAULT_ENTRY_LOCALHOST
        The default entry for the "localhost" server.
    • Constructor Detail

      • ServerCache

        public ServerCache​(@Nullable
                           @Nullable java.nio.file.Path file)
        Creates a new instance.
        Parameters:
        file - the backing file or null to not cache on disk
    • Method Detail

      • put

        public void put​(@NotNull
                        @NotNull MetaserverEntry metaserverEntry)
        Adds an entry to the cache. Overwrites old entries for the same hostname.
        Parameters:
        metaserverEntry - the entry to add
      • expire

        public void expire​(long timestamp)
        Expires entries older than a given timestamp from the cache.
        Parameters:
        timestamp - the timestamp
      • getAll

        @NotNull
        public @NotNull java.util.Map<java.lang.String,​MetaserverEntry> getAll()
        Returns all cached entries. The returned set may be modified by the caller.
        Returns:
        the cached entries; maps key to metaserver entry
      • makeKey

        @NotNull
        public static @NotNull java.lang.String makeKey​(@NotNull
                                                        @NotNull MetaserverEntry metaserverEntry)
        Returns the key for a metaserver entry.
        Parameters:
        metaserverEntry - the metaserver entry
        Returns:
        the key
      • save

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