/** * Start the verticle.<p> * This is called by Vert.x when the verticle instance is deployed. Don't call it yourself.<p> * If your verticle does things in its startup which take some time then you can override this method * and call the startFuture some time later when start up is complete. * @param startFuture a future which should be called when verticle start-up is complete. * @throws Exception */ @Override public void start(Future<Void> startFuture) throws Exception { start(); startFuture.complete(); }
/** * Stop the verticle.<p> * This is called by Vert.x when the verticle instance is un-deployed. Don't call it yourself.<p> * If your verticle does things in its shut-down which take some time then you can override this method * and call the stopFuture some time later when clean-up is complete. * @param stopFuture a future which should be called when verticle clean-up is complete. * @throws Exception */ @Override public void stop(Future<Void> stopFuture) throws Exception { stop(); stopFuture.complete(); }
@Override public void init(Vertx vertx, Context context) { super.init(vertx, context); this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY); this.endpointObject = (URIEndpointObject) this.endpoint.getAddress(); }
@Override public String deploymentID() { // In Gentics Mesh we use shortened UUIDs instead of the full Uuids. return UUIDUtil.toShortUuid(super.deploymentID()); }
/** * Initialize a Spring Context for given Verticle instance. A Verticle MUST be annotated with {@link SpringVerticle} * @param verticle The Verticle Instance where to start the Spring Context */ public static void initSpring(AbstractVerticle verticle) { final Class<?> currentVerticleClass = verticle.getClass(); final Vertx vertx = verticle.getVertx(); if(!currentVerticleClass.isAnnotationPresent(SpringVerticle.class)) { throw new InvalidParameterException("no @SpringVerticle annotation found"); } final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class); final Class<?> springConfigClass = annotation.springConfig(); // Create the parent context final GenericApplicationContext genericApplicationContext = getGenericApplicationContext( vertx.getClass().getClassLoader()); // 1. Create a new context for each verticle and use the specified spring configuration class if possible AnnotationConfigApplicationContext annotationConfigApplicationContext = getAnnotationConfigApplicationContext( springConfigClass, genericApplicationContext); // 2. Register the Vertx instance as a singleton in spring context annotationConfigApplicationContext.getBeanFactory().registerSingleton(vertx.getClass().getSimpleName(), vertx); // 3. Register a bean definition for this verticle annotationConfigApplicationContext.getBeanFactory().registerSingleton(verticle.getClass().getSimpleName(), verticle); // 4. Add a bean factory post processor to avoid configuration issues addPostprocessorAndUpdateContext(currentVerticleClass, annotationConfigApplicationContext); // 5. perform autowiring annotationConfigApplicationContext.getAutowireCapableBeanFactory().autowireBean(verticle); }
@Override public void init(Vertx vertx, Context context) { super.init(vertx, context); this.endpoint = (Endpoint) context.config().getValue(AbstractTransport.ENDPOINT_KEY); this.endpointObject = (URIEndpointObject) endpoint.getAddress(); }
protected void undeployVerticle(TestContext context, AbstractVerticle verticle) { LOGGER.debug("undeploying verticle " + verticle.deploymentID()); Async async = context.async(); vertx.undeploy(verticle.deploymentID(), result -> { if (result.failed()) { LOGGER.error(result.cause()); context.fail(result.cause()); async.complete(); } else { LOGGER.debug("succeeded undeploying verticle " + verticle.deploymentID()); async.complete(); } }); async.awaitSuccess(); LOGGER.debug("finished undeploying verticle " + verticle.deploymentID()); }
public static void init(final Future<Void> startFuture, AbstractVerticle registrationObject, VxmsRoutes... routes) { // TODO to be used for build in REST and others final Vertx vertx = registrationObject.getVertx(); final JsonObject config = vertx.getOrCreateContext().config(); vertx.eventBus() .consumer(ConfigurationUtil.getServiceName(config, registrationObject.getClass()) + "-info", VxmsEndpoint::info); initEndpoint(startFuture, registrationObject, new VxmsShared(vertx, new LocalData(vertx)), routes); }
@Override public void init(Vertx vertx, Context context) { super.init(vertx, context); this.vertx = new io.vertx.rxjava.core.Vertx(vertx); }
@Override public void start() throws Exception { super.start(); vertx.eventBus().<String>consumer(ALL_PRODUCTS_ADDRESS).handler(allProductsHandler(service)); } }
@Override public void stop(Future<Void> stopFuture) throws Exception { super.stop(stopFuture); } };
protected void undeployVerticle(TestContext context, AbstractVerticle verticle) { LOGGER.debug("undeploying verticle " + verticle.deploymentID()); Async async = context.async(); vertx.undeploy(verticle.deploymentID(), result -> { if (result.failed()) { LOGGER.error(result.cause()); context.fail(result.cause()); async.complete(); } else { LOGGER.debug("succeeded undeploying verticle " + verticle.deploymentID()); async.complete(); } }); async.awaitSuccess(); LOGGER.debug("finished undeploying verticle " + verticle.deploymentID()); }
/** * Initialize an existing Vert.x instance as a Vxms endpoint so you can use an Verticle (Extending * AbstractVerticle) as a fully functional Vxms Endpoint). Caution: this start methods completes * the start future when it's ready, so it must be the last initialisation (order and callback * wise) * * @param startFuture the Start Future from Vert.x * @param registrationObject the AbstractVerticle to register (mostly this) */ public static void start(final Future<Void> startFuture, AbstractVerticle registrationObject) { final Vertx vertx = registrationObject.getVertx(); final JsonObject config = vertx.getOrCreateContext().config(); vertx.eventBus() .consumer(ConfigurationUtil.getServiceName(config, registrationObject.getClass()) + "-info", VxmsEndpoint::info); initEndpoint(startFuture, registrationObject, new VxmsShared(vertx, new LocalData(vertx))); }
@Override public void init(Vertx vertx, Context context) { super.init(vertx, context); this.vertx = new io.vertx.rxjava.core.Vertx(vertx); }
@Override public void start() throws Exception { super.start(); HttpServer server = vertx.createHttpServer(); server.requestHandler(req -> { if (req.method() == HttpMethod.GET) { req.response().setChunked(true); if (req.path().equals("/products")) { vertx.eventBus().<String>send(SpringDemoVerticle.ALL_PRODUCTS_ADDRESS, "", result -> { if (result.succeeded()) { req.response().setStatusCode(200).write(result.result().body()).end(); } else { req.response().setStatusCode(500).write(result.cause().toString()).end(); } }); } else { req.response().setStatusCode(200).write("Hello from vert.x").end(); } } else { // We only support GET for now req.response().setStatusCode(405).end(); } }); server.listen(8080); } }
/** * Stop the verticle.<p> * This is called by Vert.x when the verticle instance is un-deployed. Don't call it yourself.<p> * If your verticle does things in its shut-down which take some time then you can override this method * and call the stopFuture some time later when clean-up is complete. * @param stopFuture a future which should be called when verticle clean-up is complete. * @throws Exception */ @Override public void stop(Future<Void> stopFuture) throws Exception { stop(); stopFuture.complete(); }
@Override public void init(Vertx vertx, Context context) { super.init(vertx, context); this.address = config().getString("address"); }
/** * Start the verticle.<p> * This is called by Vert.x when the verticle instance is deployed. Don't call it yourself.<p> * If your verticle does things in its startup which take some time then you can override this method * and call the startFuture some time later when start up is complete. * @param startFuture a future which should be called when verticle start-up is complete. * @throws Exception */ @Override public void start(Future<Void> startFuture) throws Exception { start(); startFuture.complete(); }
@Override public void stop(Future<Void> stopFuture) throws Exception { super.stop(stopFuture); } };