source: src/main/java/genius/core/events/SessionFailedEvent.java

Last change on this file was 1, checked in by Wouter Pasman, 7 years ago

Initial import : Genius 9.0.0

File size: 2.9 KB
Line 
1package genius.core.events;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import genius.core.logging.XmlLogger;
9import genius.core.misc.ExceptionTool;
10import genius.core.session.Participant;
11import genius.core.session.Session;
12import genius.core.session.SessionConfiguration;
13import genius.gui.progress.DataKey;
14import genius.gui.progress.DataKeyTableModel;
15
16/**
17 * Indicates that a session failed in abnormal way, typically due to an
18 * exception, timeout etc.
19 *
20 * @author W.Pasman 15jul15
21 *
22 */
23public class SessionFailedEvent implements SessionEndedEvent {
24
25 private final BrokenPartyException exception;
26
27 /**
28 * @param e
29 * the exception that caused the problem.
30 */
31 public SessionFailedEvent(BrokenPartyException e) {
32 if (e == null)
33 throw new NullPointerException("SessionFailed without cause");
34 exception = e;
35 }
36
37 public BrokenPartyException getException() {
38 return exception;
39 }
40
41 public String toString() {
42 return "Session " + exception.getSession() + " failed: " + new ExceptionTool(exception).getFullMessage() + ":"
43 + exception.getConfiguration().getParticipantNames();
44 }
45
46 /**
47 * Convert the agreement into a hashmap of < {@link DataKey}, {@link Object}
48 * > pairs. Object will usually be a {@link String}, {@link Number} or
49 * {@link List}. This data can be inserted directly into a
50 * {@link DataKeyTableModel}. This is similar to code in {@link XmlLogger}.
51 *
52 * @return {@link Map} of agreement evaluations.
53 */
54 public Map<DataKey, Object> getValues() {
55 Map<DataKey, Object> values = new HashMap<DataKey, Object>();
56 Session session = exception.getSession();
57 SessionConfiguration configuration = exception.getConfiguration();
58
59 try {
60 values.put(DataKey.EXCEPTION, toString());
61 values.put(DataKey.ROUND, "" + (session.getRoundNumber() + 1));
62 values.put(DataKey.DEADLINE, session.getDeadlines().valueString());
63
64 // discounted and agreement
65 boolean isDiscounted = false;
66 // for (Participant party : configuration.getParties()) {
67 values.put(DataKey.IS_AGREEMENT, "No");
68
69 // number of agreeing parties
70 values.put(DataKey.NUM_AGREE, 0);
71
72 // utils=reservation values.
73 List<Double> utils = new ArrayList<>();
74 List<String> agts = new ArrayList<String>();
75 List<String> files = new ArrayList<String>();
76 for (Participant party : configuration.getParties()) {
77 agts.add(party.getStrategy().getUniqueName());
78 Double utility = 0d;
79 try {
80 utility = party.getProfile().create().getReservationValue();
81 } catch (Exception e) {
82 System.out.println("Failed to read profile of " + party + ". using 0");
83 }
84
85 utils.add(utility);
86 files.add(party.getProfile().getName());
87
88 }
89
90 values.put(DataKey.AGENTS, agts);
91 values.put(DataKey.FILES, files);
92
93 values.put(DataKey.UTILS, utils);
94 values.put(DataKey.DISCOUNTED_UTILS, utils);
95
96 } catch (Exception e) {
97 e.printStackTrace();
98 }
99 return values;
100
101 }
102
103}
Note: See TracBrowser for help on using the repository browser.