Class BotClassifier
java.lang.Object
org.frontcache.bots.BotClassifier
Decides a request's client type -
bot or guest - from conf/bots.conf.
Evaluation order, first match wins:
- built-in
no-user-agent(a request with no User-Agent is a bot); - rules from conf/bots.conf, in file order;
- bare User-Agent keywords from the same file, in file order - so an explicit rule always wins over a keyword, whichever way round the file is written;
- built-in
default(guest), which always matches.
<fc:include client="..."> fragment is resolved. Guard rules read it back through
client-type:, but that is one consumer among several.
This is a process-wide singleton rather than a member of FrontCacheEngine, for the same reason
ClientIpResolver is: the management API and FCConfig both need to read it, and neither
may boot an engine by asking.
Runs on the request thread for every request, so classify() allocates nothing on the common path
and never throws: a predicate that blows up is logged once and treated as "did not match", which
degrades to the client type the next rule decides rather than to a 500.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionclassify(RequestContext context) Classifies one request.static BotClassifierBare User-Agent keywords from the file, in file order.getRules()The rules this node is running, in evaluation order, each carrying its hit count.static voidinstall(BotClassifier classifier) for tests - installs a classifier without going through FCConfigstatic BotClassifierfor tests - builds a classifier over an explicit rule liststatic voidreload()Re-reads conf/bots.conf.Dry-parses a candidate bots.conf without touching anything live, for theset-configmanagement action.
-
Field Details
-
BOTS_CONFIG_FILE
- See Also:
-
RULE_NO_USER_AGENT
built-in, evaluated first: no User-Agent header at all- See Also:
-
RULE_DEFAULT
built-in, evaluated last: always matches, so classify() always has an answer- See Also:
-
RULES_ENABLED_PROPERTY
- See Also:
-
EMPTY_USER_AGENT_IS_BOT_PROPERTY
- See Also:
-
-
Method Details
-
getInstance
- Returns:
- the classifier built from the current configuration, created on first use
-
reload
public static void reload()Re-reads conf/bots.conf. Called by the reload-bots management action, and by the engine's reload - adding a crawler to the list used to mean restarting the node. Hit counters start from zero again, because the rules they belong to are new objects. -
install
for tests - installs a classifier without going through FCConfig -
of
for tests - builds a classifier over an explicit rule list -
getRules
-
getKeywords
-
classify
Classifies one request. Never throws. Only the DECIDING rule counts a hit - a rule below it is never evaluated - so the console's Hits column reads as "share of traffic decided here", and a rule shadowed by a broader one above it sits at zero, which is the most useful thing that column says. A dry-run rule counts and evaluation continues past it: measuring a rule before it acts is the whole point of dry-run.- Parameters:
context- current request; may carry a null or recycled servlet request- Returns:
- the rule that decided, never null - ask it for
BotRule.getClientType()
-
validate
Dry-parses a candidate bots.conf without touching anything live, for theset-configmanagement action. The line-kind decision is the same onereadConfigFile(List, List, Set, boolean)makes - a line with no|outside a group is a bare keyword, anything else is a rule - because a validator that classified lines differently from the loader would pass files the loader then refuses, which is worse than no validator.- Returns:
- one message per unusable line,
"line N: ...", in file order; empty when the whole file parses
-