Class FcEventBus

java.lang.Object
org.frontcache.plugin.host.FcEventBus

public final class FcEventBus extends Object
The E1 event bus: where the node hands events to the plugins that observe it.

On the request path

An emit point asks wants(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 calls EventListener.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 Details

  • 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 as RequestCompleted; 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 above draw; never blocks.
      Parameters:
      draw - the emit point's draw in [0, 1) - see "Sampled events"