Changeset 18 for simplerunner/src/main
- Timestamp:
- 06/11/20 16:34:40 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
simplerunner/src/main/java/geniusweb/simplerunner/NegoRunner.java
r10 r18 7 7 import java.util.logging.Level; 8 8 9 import com.fasterxml.jackson.core.JsonProcessingException; 9 10 import com.fasterxml.jackson.databind.ObjectMapper; 10 11 … … 13 14 import geniusweb.protocol.NegoProtocol; 14 15 import geniusweb.protocol.NegoSettings; 16 import geniusweb.protocol.NegoState; 15 17 import geniusweb.protocol.partyconnection.ProtocolToPartyConnFactory; 16 import tudelft.utilities.logging.ReportToLogger;17 18 import tudelft.utilities.logging.Reporter; 18 19 … … 27 28 private final NegoProtocol protocol; 28 29 private final ProtocolToPartyConnFactory connectionfactory; 29 pr ivatefinal Reporter log;30 protected final Reporter log; 30 31 private final static ObjectMapper jackson = new ObjectMapper(); 31 32 … … 55 56 56 57 protected void stop() { 57 if (protocol.getState().getError() != null) { 58 log.log(Level.WARNING, "protocol terminated abnormally", 59 protocol.getState().getError()); 60 } else { 61 log.log(Level.INFO, 62 "protocol ended normally: " + protocol.getState()); 58 Level level = protocol.getState().getError() == null ? Level.INFO 59 : Level.WARNING; 60 logFinal(level, protocol.getState()); 61 } 62 63 /** 64 * Separate so that we can intercept this when mocking, as this will crash 65 * on mocks 66 * 67 * @param level 68 * @param state 69 */ 70 protected void logFinal(Level level, NegoState state) { 71 try { 72 log.log(level, "protocol ended normally: " 73 + jackson.writeValueAsString(protocol.getState())); 74 } catch (JsonProcessingException e) { 75 e.printStackTrace(); 63 76 } 64 77 } … … 75 88 76 89 NegoRunner runner = new NegoRunner(settings, 77 new ClassPathConnectionFactory(), 78 new ReportToLogger("sessionrunner")); 90 new ClassPathConnectionFactory(), new StdOutReporter()); 79 91 runner.run(); 80 92 } … … 90 102 } 91 103 } 104 105 class StdOutReporter implements Reporter { 106 107 @Override 108 public void log(Level arg0, String arg1) { 109 System.out.println(arg0 + ":" + arg1); 110 } 111 112 @Override 113 public void log(Level arg0, String arg1, Throwable arg2) { 114 System.out.println(arg0 + ">" + arg1); 115 } 116 117 }
Note:
See TracChangeset
for help on using the changeset viewer.