Class UnboundedEventsCollector<T>

  • Type Parameters:
    T - The data type representing the different categories. Must be suitable for hash structure keys! Thread safe.
    All Implemented Interfaces:
    JsonMonitorable

    public class UnboundedEventsCollector<T>
    extends Object
    implements JsonMonitorable
    Collects counts on an unbounded set of categories. Unlike EventsCollector, which works with a closed set defined by an enum, here we allow values that aren't known in advance. This may results in bigger memory consumption, so this utility should be used with caution. This collector also supports an atomic reset operation for a given category
    Author:
    Eyal Schneider
    • Constructor Detail

      • UnboundedEventsCollector

        public UnboundedEventsCollector()
    • Method Detail

      • getCategories

        public Set<T> getCategories()
        Returns:
        The set of categories currently maintained by this collector. Read only.
      • countEvent

        public void countEvent​(T category,
                               long multiplicity)
        Increments an event counter
        Parameters:
        category - The event category
        multiplicity - The amount to increment by
      • reset

        public long reset​(T category)
        Resets a counter.
        Parameters:
        category - The counter category
        Returns:
        The last value seen before the counter was reset. The retrieval of last value and the reseting are performed as a single atomic operation.
      • getCount

        public long getCount​(T category)
        Parameters:
        category - An event category
        Returns:
        The current count in the given category
      • getAll

        public EventStatsMap<T> getAll()
        Returns:
        A snapshot of the event counts map. Not necessarily consistent.
      • getOwnMetrics

        public net.minidev.json.JSONObject getOwnMetrics()
        Specified by:
        getOwnMetrics in interface JsonMonitorable
        Returns:
        The json string describing the entity, not including the child entities.
      • getChildren

        public Map<String,​? extends JsonMonitorable> getChildren()
        Specified by:
        getChildren in interface JsonMonitorable
        Returns:
        The monitorable children of this entity, as [id, JsonExportable] pairs. Using this method, the framework can manage a complete tree to be monitored, where every entity has a unique path.