Package org.vertx.java.platform

Examples of org.vertx.java.platform.PlatformManager


    log.info("Attempting to uninstall module " + modName);
    createPM().uninstallModule(modName, this.<Void>createLoggingHandler("Successfully uninstalled module"));
  }

  private PlatformManager createPM() {
    PlatformManager pm = PlatformLocator.factory.createPlatformManager();
    registerExitHandler(pm);
    return pm;
  }
View Full Code Here


    registerExitHandler(pm);
    return pm;
  }

  private PlatformManager createPM(int port, String host) {
    PlatformManager pm =  PlatformLocator.factory.createPlatformManager(port, host);
    registerExitHandler(pm);
    return pm;
  }
View Full Code Here

    });
  }

  private void runVerticle(boolean zip, boolean module, String main, Args args) {
    boolean clustered = args.map.get("-cluster") != null;
    PlatformManager mgr;
    if (clustered) {
      log.info("Starting clustering...");
      int clusterPort = args.getInt("-cluster-port");
      if (clusterPort == -1) {
        // Default to zero - this means choose an ephemeral port
        clusterPort = 0;
      }
      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);
        }
      }
      mgr = createPM(clusterPort, clusterHost);
    } else {
      mgr = createPM();
    }

    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 (Scanner scanner = new Scanner(new File(configFile)).useDelimiter("\\A")){
        String sconf = scanner.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<AsyncResult<String>> doneHandler = new Handler<AsyncResult<String>>() {
      public void handle(AsyncResult<String> res) {
        if (res.failed()) {
          // Failed to deploy
          unblock();
        }
      }
    };
    if (zip) {
      mgr.deployModuleFromZip(main, conf, instances, createLoggingHandler("Successfully deployed module from zip", doneHandler));
    } else if (module) {
      mgr.deployModule(main, conf, instances, createLoggingHandler("Successfully deployed module", doneHandler));
    } else {
      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 includes = args.map.get("-includes");
      if (worker) {
        mgr.deployWorkerVerticle(false, main, conf, urls, instances, includes,
                                 createLoggingHandler("Successfully deployed worker verticle", doneHandler));
      } else {
        mgr.deployVerticle(main, conf, urls, instances, includes, createLoggingHandler("Successfully deployed verticle", doneHandler));
      }
    }

    addShutdownHook(mgr);
    block();
View Full Code Here

TOP

Related Classes of org.vertx.java.platform.PlatformManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.