2..27 – noch nicht angekommen

So, nun bin ich in der zweiten Woche meiner Auszeit. Einige Leute fragen schon, wie es läuft und wie es geht und was ich so mache…

Meine Antwort derzeit ist, dass ich noch nicht angekommen bin. Es fällt mir zum Beispiel schwer 2 Stunden am Stück an einem Buch zu lesen. Mich überkommt immer noch so eine Unruhe.

Aber ich habe schon ein paar Erfahrungen gemacht, die ich ohne diese Pause nicht gemacht hätte. Da ist dieses Projekt vert.x . Ich lese jeden Eintrag in der Google Group, jeden Twitter Pieps von @TimFox und jedes Ticket was aufgemacht wird und bekomme so sehr viel von dem Projekt mit. Auch andere kämpfen mit Git und nicht jeder Schalter  ist sofort klar. Warum ist die vorgeschlagen Verzeichnisstruktur von Maven so nett und warum sollte man nicht grössere Codeänderungen ankündigen und dann lange nicht machen. Alle warten darauf und sie kommen nicht…

Und mir geht der Code von dieser einen Klasse nicht aus dem Kopf. Da ist dieser Code in org.vertx.java.deploy.impl.cli.Starter :

    private Starter(String[] sargs) {
	String vertxVersion = String.format("vert.x %s", System.getProperty("vertx.version", "0.0.0-UNKNOWN!"));
    if (sargs.length < 1) {
      displaySyntax();
    } else {
      String command = sargs[0].toLowerCase();
      Args args = new Args(sargs);
      if ("version".equals(command)) {
        log.info(vertxVersion);
      } else {
        if (sargs.length < 2) {
          displaySyntax();
        } else {
          String operand = sargs[1];
          switch (command) {
            case "version":
              log.info(vertxVersion);
              break;
            case "run":
              runVerticle(false, operand, args);
              break;
            case "runmod":
              runVerticle(true, operand, args);
              break;
            case "install":
              installModule(operand, args);
              break;
            case "uninstall":
              uninstallModule(operand);
              break;
            default:
              displaySyntax();
          }
        }
      }
    }
  }
...

  private void runVerticle(boolean module, String main, Args args) {
    boolean clustered = args.map.get("-cluster") != null;
    if (clustered) {
      log.info("Starting clustering...");
      int clusterPort = args.getInt("-cluster-port");
      if (clusterPort == -1) {
        clusterPort = 25500;
      }
      String clusterHost = args.map.get("-cluster-host");
      if (clusterHost == null) {
        clusterHost = getDefaultAddress();
        if (clusterHost == null) {
          log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host");
          return;
        } else {
          log.info("No cluster-host specified so using address " + clusterHost);
        }
      }
      vertx = new DefaultVertx(clusterPort, clusterHost);
    }
    String repo = args.map.get("-repo");
    mgr = new VerticleManager(vertx, repo);

    boolean worker = args.map.get("-worker") != null;

    String cp = args.map.get("-cp");
    if (cp == null) {
      cp = ".";
    }

    // Convert to URL[]

    String[] parts;

    if (cp.contains(CP_SEPARATOR)) {
      parts = cp.split(CP_SEPARATOR);
    } else {
      parts = new String[] { cp };
    }
    int index = 0;
    final URL[] urls = new URL[parts.length];
    for (String part: parts) {
      try {
        URL url = new File(part).toURI().toURL();
        urls[index++] = url;
      } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Invalid path " + part + " in cp " + cp) ;
      }
    }

    String sinstances = args.map.get("-instances");
    int instances;
    if (sinstances != null) {
      try {
        instances = Integer.parseInt(sinstances);

        if (instances != -1 && instances < 1) {
          log.error("Invalid number of instances");
          displaySyntax();
          return;
        }
      } catch (NumberFormatException e) {
        displaySyntax();
        return;
      }
    } else {
      instances = 1;
    }

    String configFile = args.map.get("-conf");
    JsonObject conf;

    if (configFile != null) {
      try {
        String sconf = new Scanner(new File(configFile)).useDelimiter("\A").next();
        try {
          conf = new JsonObject(sconf);
        } catch (DecodeException e) {
          log.error("Configuration file does not contain a valid JSON object");
          return;
        }
      } catch (FileNotFoundException e) {
        log.error("Config file " + configFile + " does not exist");
        return;
      }
    } else {
      conf = null;
    }

    Handler doneHandler = new Handler() {
      public void handle(String id) {
        if (id == null) {
          // Failed to deploy
          mgr.unblock();
        }
      }
    };
    if (module) {
      mgr.deployMod(main, conf, instances, null, doneHandler);
    } else {
      mgr.deploy(worker, main, conf, urls, instances, null, doneHandler);
    }

    addShutdownHook();
    mgr.block();
  }

Ich habe in der letzen Woche so viel über diesen Zeilen nachgedacht. Meine erste Reaktion war: “Das muss umgebaut werden.” Der Boolean “module” ist nicht gut: lieber zwei Methoden runVertical und runModule – ja und dann muss das Auslesen von den Konfigurationsparametern an anderer Stelle gemacht werden… und überhaupt lässt sich das Ding derzeit mit ”

vertx version version version version

aufrufen. Kein Fehler – komisch. Ich werde das umschreiben … macht das Sinn? Dies sind keine funktionalen Erweiterungen – und bekomme ich es so hin, dass es verständlicher sein wird? Unsicherheit!

 

One thought on “2..27 – noch nicht angekommen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s