Class ApplicationBadgeCounter

java.lang.Object
io.meeds.appcenter.service.ApplicationBadgeCounter

@Component public class ApplicationBadgeCounter extends Object
Calls a contributing plugin's countBadge under a bounded time budget, and stops calling one that keeps failing.

Badges are read from the topbar, which renders on every page: a source that hangs — a third-party system behind an unresponsive HTTP call, typically — must degrade to "no badge" rather than hold the request. The call therefore runs on a separate thread and the caller waits at most appcenter.badge.count.timeout milliseconds for it.

The timeout alone is not enough: under load, a hung source would still tie up one thread per read. After appcenter.badge.count.breaker.failureThreshold consecutive failures a plugin's breaker opens, and its count is served as 0 without calling it at all for appcenter.badge.count.breaker.openSeconds. A single success closes it again.

This is the only protection left for a self-cached plugin, whose cold-cache read App Center does not otherwise mediate. A degraded 0 obtained on the generic path is cached like any other value, so it is served until the cache TTL expires or an event evicts it.

  • Constructor Details

    • ApplicationBadgeCounter

      public ApplicationBadgeCounter()
  • Method Details

    • stop

      @PreDestroy public void stop()
    • count

      public long count(ApplicationBadgePlugin plugin, String username)
      Counts a badge for one user, degrading to 0 when the plugin is too slow, fails, or has its breaker open.
      Parameters:
      plugin - the contributing plugin
      username - the user the count is computed for
      Returns:
      the count, 0 when it could not be obtained within the time budget