Class VisitorTypes

java.lang.Object
org.frontcache.bots.VisitorTypes

public final class VisitorTypes extends Object
The visitor types a node knows: the two roots, bot and guest, and the types bots.conf declares with @type <name> like <bot|guest> - at most 16, each based on a root. A declared type IS its base everywhere it is not named. A request has one visitor type (the leaf, customer) and so one client type (its root, guest); RequestContext.getClientType() keeps returning the root, so every consumer that does not know about declared types sees exactly what it saw before they existed. What selects by type (client=, client-type:) selects by is-a - a type is itself and its base; what looks a type up (expireTimeMap) looks up the leaf, then the base - ttl(Map, String, String). Both need only the leaf and the root the request carries, never this object, so a reload-bots that removes a type cannot leave a request in flight without an answer. A declaration may end with no-store (@type customer like guest no-store): a request of that type never writes an entry, whatever the page's maxage says - it still reads one per its resolved TTL (isNoStore(String)). One cached copy serves every type, so a type the origin renders differently for (a session or tracking cookie) would otherwise have its render stored and served to everyone; the flag closes that by configuration instead of by every page author remembering customer:0. It is decided when an entry would be written, from the running vocabulary - not carried on the request - so a reload that adds it protects the requests already in flight too. Immutable. One snapshot per BotClassifier; active() is the running classifier's.
  • Field Details

    • MAX_DECLARED

      public static final int MAX_DECLARED
      The most types a bots.conf may declare. It bounds every stored entry's expireTimeMap and the metric labels.
      See Also:
    • DIRECTIVE

      public static final String DIRECTIVE
      The directive's keyword.
      See Also:
    • NO_STORE

      public static final String NO_STORE
      The one flag a declaration may carry - see isNoStore(String).
      See Also:
    • ROOTS

      public static final VisitorTypes ROOTS
      No declarations - the two roots only. What a node without @type lines runs, and every node before.
  • Method Details

    • active

      public static VisitorTypes active()
      Returns:
      the vocabulary of the running BotClassifier, or ROOTS before one is loaded. Never loads one: FCConfig and its static initializer are not this method's to start
    • isRoot

      public static boolean isRoot(String name)
    • isKnown

      public boolean isKnown(String name)
      Returns:
      true for a root or a declared type
    • rootOf

      public String rootOf(String name)
      Returns:
      the root a known type is based on - a root is its own - or null for a name this node does not know
    • declared

      public Map<String,String> declared()
      Returns:
      the declared types (roots excluded), name -> base, in declaration order
    • isNoStore

      public boolean isNoStore(String name)
      Returns:
      true when name is a type declared no-store: a request of it never writes an entry - not on a miss, not by a soft refresh - and reads one per its resolved TTL. Never true of a root, nor of a name this node does not know
    • noStore

      public Set<String> noStore()
      Returns:
      the declared types flagged no-store, in declaration order
    • describeKnown

      public String describeKnown()
      Returns:
      the known names, roots first, for messages
    • isA

      public static boolean isA(String visitorType, String clientType, String name)
      is-a: a request whose visitor type is visitorType (root clientType) is name when name is the leaf or the root. Two compares, no lookup.
    • ttl

      public static Long ttl(Map<String,Long> expireTimeMap, String visitorType, String clientType)
      The expireTimeMap value that applies to a request: the leaf's if the entry names it, else the root's. The roots are always in a map WebResponse built, so for a well-formed entry the answer is never null; an absent declared type means inherit, an absent root is a bug the callers log.
      Returns:
      the stamp, or null when neither key is present
    • builder

      public static VisitorTypes.Builder builder()
    • of

      public static VisitorTypes of(String... declarations)
      for tests - a vocabulary from declaration lines, every one of which must be accepted
    • isDeclaration

      public static boolean isDeclaration(String trimmedLine)
      Returns:
      true when the trimmed line is a declaration. Recognised by prefix, before a rule is told from a bare keyword - no real User-Agent begins @type
    • toString

      public String toString()
      Overrides:
      toString in class Object