source: simplerunner/src/main/java/geniusweb/simplerunner/NegoRunner.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.6 KB
Line 
1package geniusweb.simplerunner;
2
3import java.io.IOException;
4import java.nio.charset.StandardCharsets;
5import java.nio.file.Files;
6import java.nio.file.Paths;
7import java.util.logging.Level;
8
9import com.fasterxml.jackson.databind.ObjectMapper;
10
11import geniusweb.protocol.NegoSettings;
12import geniusweb.simplerunner.gui.GUI;
13import tudelft.utilities.logging.Reporter;
14
15/**
16 * A simple tool to run a negotiation stand-alone, without starting the servers.
17 * All referred files and classes need to be stored locally (or be in the
18 * dependency list if you use maven).
19 * <p>
20 * <em>IMPORTANT</em> SimpleRunner has a number of restrictions, compared to a
21 * run using a runserver and partyserver
22 * <ul>
23 * <li>With stand-alone runner, your parties are run together in a single
24 * classloader. The main implication is that there may arise version conflicts
25 * between parties.
26 * <li>Stand-alone runner does NOT enforce the time deadline. Parties may
27 * continue running indefinitely and thus bog down the JVM and stalling
28 * tournaments.
29 * </ul>
30 */
31public class NegoRunner {
32 private final static ObjectMapper jackson = new ObjectMapper();
33
34 /**
35 * The main runner
36 *
37 * @param args should have 0 or 1 argument. If 0 arguments, the {@link GUI}
38 * is started. If one argoment, it should be a filename
39 * containing a settings.json file. That session is then run.
40 * @throws IOException if problem occurs
41 */
42 public static void main(String[] args) throws IOException {
43 if (args.length == 0) {
44 GUI.main(args);
45 return;
46 }
47 if (args.length != 1) {
48 showusage();
49 return;
50 }
51 String serialized = new String(Files.readAllBytes(Paths.get(args[0])),
52 StandardCharsets.UTF_8);
53 NegoSettings settings = jackson.readValue(serialized,
54 NegoSettings.class);
55
56 Runner runner = new Runner(settings, new ClassPathConnectionFactory(),
57 new StdOutReporter(), 0);
58 runner.run();
59 }
60
61 private static void showusage() {
62 System.err.println("GeniusWeb stand-alone runner.");
63 System.err.println("first argument should be <settings.json>.");
64 System.err.println(
65 "The settings.json file should contain the NegoSettings.");
66 System.err.println(
67 "See the settings.json example file and the GeniusWeb wiki pages. ");
68
69 }
70
71}
72
73class StdOutReporter implements Reporter {
74 @Override
75 public void log(Level level, String msg) {
76 if (level == Level.WARNING || level == Level.SEVERE)
77 System.err.println(level + ":" + msg);
78 else
79 System.out.println(level + ":" + msg);
80 }
81
82 @Override
83 public void log(Level arg0, String msg, Throwable arg2) {
84 log(arg0, msg);
85 }
86
87}
Note: See TracBrowser for help on using the repository browser.