Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
NotNullInvocationListener.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector.invocation;
2 
3 import com.griddynamics.jagger.engine.e1.Provider;
4 import com.griddynamics.jagger.engine.e1.collector.MetricDescription;
5 import com.griddynamics.jagger.engine.e1.collector.SumMetricAggregatorProvider;
6 import com.griddynamics.jagger.engine.e1.services.ServicesAware;
7 import com.griddynamics.jagger.invoker.InvocationException;
8 
17 /* begin: following section is used for docu generation - example of the invocation listener with metric service */
18 public class NotNullInvocationListener extends ServicesAware implements Provider<InvocationListener> {
19 
20  private final String metricName = "not-null-responses";
21 
22  @Override
23  protected void init() {
24  getMetricService().createMetric(new MetricDescription(metricName).
25  displayName("Number of not null responses").
26  showSummary(true).
27  plotData(false).
28  addAggregator(new SumMetricAggregatorProvider()));
29  }
30 
31  @Override
32  public InvocationListener provide() {
33  return new InvocationListener() {
34  @Override
35  public void onStart(InvocationInfo invocationInfo) {
36  }
37 
38  @Override
39  public void onSuccess(InvocationInfo invocationInfo) {
40  if (invocationInfo.getResult() != null){
41  getMetricService().saveValue(metricName, 1);
42  }
43  }
44 
45  @Override
46  public void onFail(InvocationInfo invocationInfo, InvocationException e) {
47  }
48 
49  @Override
50  public void onError(InvocationInfo invocationInfo, Throwable error) {
51  }
52  };
53  }
54 }
55 /* end: following section is used for docu generation - example of the invocation listener with metric service */