Ejemplo n.º 1
0
  /**
   * @param args 1. rddl description file name (can be directory), in RDDL format, with complete
   *     path 2. (optional) port number 3. (optional) random seed
   */
  public static void main(String[] args) {

    // StateViz state_viz = new GenericScreenDisplay(true);
    StateViz state_viz = new NullScreenDisplay(false);

    ArrayList<RDDL> rddls = new ArrayList<RDDL>();
    int port = PORT_NUMBER;
    if (args.length < 1) {
      System.out.println(
          "usage: rddlfilename (optional) portnumber random-seed state-viz-class-name");
      System.out.println("\nexample 1: Server rddlfilename");
      System.out.println("example 2: Server rddlfilename 2323");
      System.out.println("example 3: Server rddlfilename 2323 0 rddl.viz.GenericScreenDisplay");
      System.exit(1);
    }

    try {
      // Load RDDL files
      RDDL rddl = new RDDL();
      File f = new File(args[0]);
      if (f.isDirectory()) {
        for (File f2 : f.listFiles())
          if (f2.getName().endsWith(".rddl")) {
            System.out.println("Loading: " + f2);
            rddl.addOtherRDDL(parser.parse(f2));
          }
      } else rddl.addOtherRDDL(parser.parse(f));

      if (args.length > 1) {
        port = Integer.valueOf(args[1]);
      }
      ServerSocket socket1 = new ServerSocket(port);
      if (args.length > 2) {
        Server.rand = new Random(Integer.valueOf(args[2]));
      } else {
        Server.rand = new Random(DEFAULT_SEED);
      }
      if (args.length > 3) {
        state_viz = (StateViz) Class.forName(args[3]).newInstance();
      }
      System.out.println("RDDL Server Initialized");
      while (true) {
        Socket connection = socket1.accept();
        Runnable runnable = new Server(connection, ++ID, rddl, state_viz);
        Thread thread = new Thread(runnable);
        thread.start();
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      System.out.println(e);
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
 static ArrayList<PVAR_INST_DEF> processXMLAction(DOMParser p, InputSource isrc, State state)
     throws Exception {
   try {
     // showInputSource(isrc); System.exit(1); // TODO
     p.parse(isrc);
     Element e = p.getDocument().getDocumentElement();
     if (SHOW_XML) {
       System.out.println("Received action msg:");
       printXMLNode(e);
     }
     if (!e.getNodeName().equals(ACTIONS)) {
       System.out.println("ERROR: NO ACTIONS NODE");
       System.exit(1);
       return null;
     }
     NodeList nl = e.getElementsByTagName(ACTION);
     //			System.out.println(nl);
     if (nl != null) { // && nl.getLength() > 0) { // TODO: Scott
       ArrayList<PVAR_INST_DEF> ds = new ArrayList<PVAR_INST_DEF>();
       for (int i = 0; i < nl.getLength(); i++) {
         Element el = (Element) nl.item(i);
         String name = getTextValue(el, ACTION_NAME).get(0);
         ArrayList<String> args = getTextValue(el, ACTION_ARG);
         ArrayList<LCONST> lcArgs = new ArrayList<LCONST>();
         for (String arg : args) {
           if (arg.startsWith("@")) lcArgs.add(new RDDL.ENUM_VAL(arg));
           else lcArgs.add(new RDDL.OBJECT_VAL(arg));
         }
         String pvalue = getTextValue(el, ACTION_VALUE).get(0);
         Object value = getValue(name, pvalue, state);
         PVAR_INST_DEF d = new PVAR_INST_DEF(name, value, lcArgs);
         ds.add(d);
       }
       return ds;
     } else return new ArrayList<PVAR_INST_DEF>(); // FYI: May be unreachable. -Scott
     // } else { // TODO: Removed by Scott, NOOP should not be handled differently
     //	nl = e.getElementsByTagName(NOOP);
     //	if ( nl != null && nl.getLength() > 0) {
     //		ArrayList<PVAR_INST_DEF> ds = new ArrayList<PVAR_INST_DEF>();
     //		return ds;
     //	}
     // }
   } catch (Exception e) {
     // TODO Auto-generated catch block
     System.out.println("FATAL SERVER ERROR:\n" + e);
     // t.printStackTrace();
     throw e;
     // System.exit(1);
   }
 }