Class HostTrackingService

java.lang.Object
edu.ucsb.cs156.diningcachingproxy.services.HostTrackingService
Direct Known Subclasses:
HostTrackingServiceImpl

public abstract class HostTrackingService extends Object
Tracks which hosts have sent requests through the proxy, and how many times each has done so. Abstracted behind this base class so the storage mechanism (in-memory today) can later be swapped for a persisted one (Mongo/SQL) without changing callers.

Every address is tracked under its own raw form (e.g. an IP address) until a hostname is resolved for it - resolution happens out-of-band (see ResolveHostnameJob), since it can be asynchronous.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract List<HostCount>
    Every host seen so far with its request count, sorted by host (hostname, or IP if unresolved).
    abstract boolean
    recordRequest(String remoteAddress)
    Records a single request from the given remote address (the caller's true IP, already resolved from X-Forwarded-For where applicable).
    abstract void
    resolveHostname(String remoteAddress, String hostname)
    Updates the display name shown for a previously-seen address - called once a hostname resolution attempt for it completes (successfully or not).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HostTrackingService

      public HostTrackingService()
  • Method Details

    • recordRequest

      public abstract boolean recordRequest(String remoteAddress)
      Records a single request from the given remote address (the caller's true IP, already resolved from X-Forwarded-For where applicable).
      Returns:
      true if this is the first time this exact address has been seen
    • resolveHostname

      public abstract void resolveHostname(String remoteAddress, String hostname)
      Updates the display name shown for a previously-seen address - called once a hostname resolution attempt for it completes (successfully or not).
    • getHostCounts

      public abstract List<HostCount> getHostCounts()
      Every host seen so far with its request count, sorted by host (hostname, or IP if unresolved).