package geniusweb.simplerunner; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.logging.Level; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.protocol.NegoSettings; import geniusweb.simplerunner.gui.GUI; import tudelft.utilities.logging.Reporter; /** * A simple tool to run a negotiation stand-alone, without starting the servers. * All referred files and classes need to be stored locally (or be in the * dependency list if you use maven). *

* IMPORTANT SimpleRunner has a number of restrictions, compared to a * run using a runserver and partyserver *

*/ public class NegoRunner { private final static ObjectMapper jackson = new ObjectMapper(); /** * The main runner * * @param args should have 0 or 1 argument. If 0 arguments, the {@link GUI} * is started. If one argoment, it should be a filename * containing a settings.json file. That session is then run. * @throws IOException if problem occurs */ public static void main(String[] args) throws IOException { if (args.length == 0) { GUI.main(args); return; } if (args.length != 1) { showusage(); return; } String serialized = new String(Files.readAllBytes(Paths.get(args[0])), StandardCharsets.UTF_8); NegoSettings settings = jackson.readValue(serialized, NegoSettings.class); Runner runner = new Runner(settings, new ClassPathConnectionFactory(), new StdOutReporter(), 0); runner.run(); } private static void showusage() { System.err.println("GeniusWeb stand-alone runner."); System.err.println("first argument should be ."); System.err.println( "The settings.json file should contain the NegoSettings."); System.err.println( "See the settings.json example file and the GeniusWeb wiki pages. "); } } class StdOutReporter implements Reporter { @Override public void log(Level level, String msg) { if (level == Level.WARNING || level == Level.SEVERE) System.err.println(level + ":" + msg); else System.out.println(level + ":" + msg); } @Override public void log(Level arg0, String msg, Throwable arg2) { log(arg0, msg); } }