Class Aggregator<A extends Aggregation>

  • Type Parameters:
    A - The type of Aggregation

    public abstract class Aggregator<A extends Aggregation>
    extends Object
    An Aggregator consumes a JVMEvent, extracts data from the event, and calls on an Aggregation which collates the data. An Aggregators uses the @Aggregates annotation to declare the EventSource(s) of the JVMEvents it handles. The constructor of an Aggregator must call register(Class, Consumer) to register the consumer methods of JVMEvents the Aggregator consumes.

    This example Aggregator aggregates events from the G1GC event source. It consumes and processes four different events. The Consumer method for each event extracts the cause of the collection and calls the GCCauseAggregation record method.

    
    
     @Collates(GCCauseAggregator)
     public interface GCCauseAggregation extends Aggregation {
         publish(GarbageCollectionType type, GCCause cause);
     }
    
     @Aggregates(EventSource.G1GC)
     public class GCCauseAggregator extends Aggregator<GCCauseAggregation> {
    
         public GCCauseAggregator(GCCauseAggregation aggregation) {
             super(aggregation);
             register(G1Young.class, this::process);
             register(G1Mixed.class, this::process);
             register(G1YoungInitialMark.class, this::process);
             register(G1FullGC.class, this::process);
         }
    
         private void process(G1Young collection) {
             aggregation().publish(GarbageCollectionTypes.Young, collection.getGCCause());
         }
    
         private void process(G1Mixed collection) {
             aggregation().publish(GarbageCollectionTypes.Mixed, collection.getGCCause());
         }
    
         private void process(G1YoungInitialMark collection) {
             aggregation().publish(GarbageCollectionTypes.G1GCYoungInitialMark, collection.getGCCause());
         }
    
         private void process(G1FullGC collection) {
             aggregation().publish(GarbageCollectionTypes.FullGC, collection.getGCCause());
         }
     }
     
    • Constructor Detail

      • Aggregator

        protected Aggregator​(A aggregation)
        Subclass only.
        Parameters:
        aggregation - The Aggregation that @Collates this Aggregator
        See Also:
        Collates, Aggregation
    • Method Detail

      • aggregation

        public A aggregation()
        This method returns the Aggregation that collates the data which is collected by this Aggregator.
        Returns:
        The Aggregator's corresponding Aggregation
      • register

        protected <E extends JVMEvent> void register​(Class<E> eventClass,
                                                     Consumer<? super E> process)
        Register a JVMEvent class and the method in the Aggregator sub-class that handles it. If the JVMEvent class is a super-class of other event types, then the Consumer is called for all sub-classes of that JVMEvent class, unless a Consumer for a more specific event class is registered.

        The typical pattern is to call this method from the constructor of the Aggregator sub-class.

        
             register(G1Young.class, this::process);
         
        The Consumer for this example would be coded as:
        
             private void process(G1Young collection) {...}
         
        Where the body of the method would pull the relevant data from the event and pass the data on to the Aggregation.
        Type Parameters:
        E - the type of JVMEvent
        Parameters:
        eventClass - the Class of the JVMEvent type to register.
        process - the handler which processes the event
      • onCompletion

        public void onCompletion​(Runnable task)
        Call back to be run when the JVMTermination event has been
        Parameters:
        task - to be executed
      • receive

        public void receive​(JVMEvent event)
        This method consumes a JVMEvent and dispatches it to the registered consumer.
        Parameters:
        event - an event to be processed
      • aggregates

        public boolean aggregates​(EventSource eventSource)
        Calculates if this Aggregator aggregates the given event source
        Parameters:
        eventSource - to be checked.
        Returns:
        true is the aggregator aggregates the event source