예제 #1
0
 public void deployVerticle(
     String verticleName,
     DeploymentOptions options,
     Handler<AsyncResult<String>> completionHandler) {
   ContextImpl currentContext = vertx.getOrCreateContext();
   ClassLoader cl = getClassLoader(options.getIsolationGroup());
   int pos = verticleName.indexOf(':');
   if (pos == -1) {
     throw new IllegalArgumentException("verticleName must start with prefix");
   }
   String prefix = verticleName.substring(0, pos);
   if (pos + 1 >= verticleName.length()) {
     throw new IllegalArgumentException("Invalid name: " + verticleName);
   }
   String actualName = verticleName.substring(pos + 1);
   VerticleFactory verticleFactory = verticleFactories.get(prefix);
   if (verticleFactory == null) {
     // Use default Java verticle factory
     verticleFactory = DEFAULT_VERTICLE_FACTORY;
   }
   try {
     Verticle verticle = verticleFactory.createVerticle(actualName, cl);
     if (verticle == null) {
       reportFailure(
           new NullPointerException("VerticleFactory::createVerticle returned null"),
           currentContext,
           completionHandler);
     } else {
       doDeploy(verticle, options, currentContext, completionHandler);
     }
   } catch (Exception e) {
     reportFailure(e, currentContext, completionHandler);
   }
 }
예제 #2
0
 public void registerVerticleFactory(VerticleFactory factory) {
   if (factory.prefix() == null) {
     throw new IllegalArgumentException("factory.prefix() cannot be null");
   }
   if (verticleFactories.containsKey(factory.prefix())) {
     throw new IllegalArgumentException(
         "There is already a registered verticle factory with prefix " + factory.prefix());
   }
   verticleFactories.put(factory.prefix(), factory);
 }
예제 #3
0
 private void loadVerticleFactories() {
   ServiceLoader<VerticleFactory> factories = ServiceLoader.load(VerticleFactory.class);
   Iterator<VerticleFactory> iter = factories.iterator();
   while (iter.hasNext()) {
     VerticleFactory factory = iter.next();
     factory.init(vertx);
     String prefix = factory.prefix();
     if (verticleFactories.containsKey(prefix)) {
       log.warn(
           "Not loading verticle factory: "
               + factory
               + " as prefix "
               + prefix
               + " is already in use");
     } else {
       verticleFactories.put(prefix, factory);
     }
   }
 }
예제 #4
0
 public void unregisterVerticleFactory(VerticleFactory factory) {
   if (verticleFactories.remove(factory.prefix()) == null) {
     throw new IllegalArgumentException("Factory " + factory + " is not registered");
   }
 }