Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
TestGroupDecisionMakerListener.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector.testgroup;
2 
3 import com.griddynamics.jagger.util.Decision;
4 import com.griddynamics.jagger.engine.e1.sessioncomparation.WorstCaseDecisionMaker;
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7 
8 import java.util.ArrayList;
9 import java.util.List;
10 
26  Decision onDecisionMaking(TestGroupDecisionMakerInfo decisionMakerInfo);
27 
30  public static class Composer implements TestGroupDecisionMakerListener{
31  private static Logger log = LoggerFactory.getLogger(Composer.class);
32 
33  private List<TestGroupDecisionMakerListener> listenerList;
34 
35  private Composer(List<TestGroupDecisionMakerListener> listenerList){
36  this.listenerList = listenerList;
37  }
38 
39  @Override
40  public Decision onDecisionMaking(TestGroupDecisionMakerInfo decisionMakerInfo) {
41  List<Decision> decisions = new ArrayList<Decision>();
42 
43  WorstCaseDecisionMaker worstCaseDecisionMaker = new WorstCaseDecisionMaker();
44 
45  for (TestGroupDecisionMakerListener listener : listenerList){
46  try{
47  decisions.add(listener.onDecisionMaking(decisionMakerInfo));
48  }catch (RuntimeException ex){
49  log.error("Failed to call on decision making in {} test-group-decision-maker-listener", listener.toString(), ex);
50  }
51  }
52 
53  return worstCaseDecisionMaker.getDecision(decisions);
54  }
55  public static TestGroupDecisionMakerListener compose(List<TestGroupDecisionMakerListener> listeners){
56  return new Composer(listeners);
57  }
58  }
59 }