Class FcEventBus
java.lang.Object
org.frontcache.plugin.host.FcEventBus
The E1 event bus: where the node hands events to the plugins that observe it.
On the request path
An emit point askswants(long) - one volatile read of a bitmask, no allocation - and only when some
listener subscribed to that type does it build the event and publish(FcEvent) it, which offers it into
each subscriber's own bounded queue. A full queue drops the event and counts it; nothing here ever blocks
a request thread, and a listener that blocks only fills its own queue.
Delivery
One daemon thread per subscriber drains its queue and callsEventListener.onEvents(List) with whatever has
accumulated, up to 500 at a time: prompt when traffic is quiet, batched when it is not. A listener
that throws is logged (once a minute) and keeps receiving.
Sampled events
RequestCompleted is the one event that can come from every request, so each subscriber names the share
it wants (front-cache.plugins.<id>.request-sample). The emit point draws one number per request and
builds the event only when the draw is under the largest share wanted (requestSample()); each subscriber
then takes it when the same draw is under its own share - so a subscriber's sample is a subset of any larger one.
Subscribers are replaced wholesale on every engine start (FrontcachePlugins), and one plugin's on a
reload of its config (resubscribe(String, List, int, double, PluginCounters)); stopAll() on engine stop counts whatever is still queued as
dropped.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final longstatic final longstatic final longstatic final longstatic final intstatic final longstatic final longstatic final longstatic final longstatic final longstatic final longstatic final long -
Method Summary
Modifier and TypeMethodDescriptionstatic voidpublish(org.frontcache.plugin.event.FcEvent event) Offers the event to every subscriber of its type; never blocks.static voidpublish(org.frontcache.plugin.event.FcEvent event, double draw) Offers a sampled event to every subscriber of its type whose share is abovedraw; never blocks.static doubleThe largest share of requests a subscriber wants asRequestCompleted; 0 when none does.static booleanwants(long bit) Whether any listener subscribed to the event type with this bit - check it before building the event.
-
Field Details
-
GUARD_MATCHED
public static final long GUARD_MATCHED- See Also:
-
RATE_LIMIT_EXCEEDED
public static final long RATE_LIMIT_EXCEEDED- See Also:
-
GUARD_SUMMARY
public static final long GUARD_SUMMARY- See Also:
-
CIRCUIT_STATE_CHANGED
public static final long CIRCUIT_STATE_CHANGED- See Also:
-
CONFIG_RELOADED
public static final long CONFIG_RELOADED- See Also:
-
PLUGIN_STATE_CHANGED
public static final long PLUGIN_STATE_CHANGED- See Also:
-
FALLBACK_SERVED
public static final long FALLBACK_SERVED- See Also:
-
ORIGIN_ERROR
public static final long ORIGIN_ERROR- See Also:
-
CACHE_INVALIDATED
public static final long CACHE_INVALIDATED- See Also:
-
REQUEST_COMPLETED
public static final long REQUEST_COMPLETED- See Also:
-
CHALLENGE_ISSUED
public static final long CHALLENGE_ISSUED- See Also:
-
CHALLENGE_RESULT
public static final long CHALLENGE_RESULT- See Also:
-
DEFAULT_QUEUE_CAPACITY
public static final int DEFAULT_QUEUE_CAPACITY- See Also:
-
-
Method Details
-
wants
public static boolean wants(long bit) Whether any listener subscribed to the event type with this bit - check it before building the event. -
requestSample
public static double requestSample()The largest share of requests a subscriber wants asRequestCompleted; 0 when none does. -
publish
public static void publish(org.frontcache.plugin.event.FcEvent event) Offers the event to every subscriber of its type; never blocks. -
publish
public static void publish(org.frontcache.plugin.event.FcEvent event, double draw) Offers a sampled event to every subscriber of its type whose share is abovedraw; never blocks.- Parameters:
draw- the emit point's draw in [0, 1) - see "Sampled events"
-