Module com.microsoft.gctoolkit.api
Class Aggregator<A extends Aggregation>
- java.lang.Object
-
- com.microsoft.gctoolkit.aggregator.Aggregator<A>
-
- 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@Aggregatesannotation to declare the EventSource(s) of the JVMEvents it handles. The constructor of an Aggregator must callregister(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
Consumermethod for each event extracts the cause of the collection and calls the GCCauseAggregationrecordmethod.@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 Summary
Constructors Modifier Constructor Description protectedAggregator(A aggregation)Subclass only.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaggregates(EventSource eventSource)Calculates if this Aggregator aggregates the given event sourceAaggregation()This method returns theAggregationthat collates the data which is collected by thisAggregator.voidonCompletion(Runnable task)Call back to be run when the JVMTermination event has beenvoidreceive(JVMEvent event)This method consumes a JVMEvent and dispatches it to theregistered consumer.protected <E extends JVMEvent>
voidregister(Class<E> eventClass, Consumer<? super E> process)Register a JVMEvent class and the method in the Aggregator sub-class that handles it.
-
-
-
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 theAggregationthat collates the data which is collected by thisAggregator.- 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.
Theregister(G1Young.class, this::process);Consumerfor this example would be coded as:
Where the body of the method would pull the relevant data from the event and pass the data on to the Aggregation.private void process(G1Young collection) {...}- 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 theregistered 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
-
-