Java Code Examples for io.vertx.core.AbstractVerticle#getVertx()

The following examples show how to use io.vertx.core.AbstractVerticle#getVertx() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VxmsEndpoint.java    From vxms with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: VxmsDiscoveryK8SImpl.java    From vxms with Apache License 2.0 5 votes vote down vote up
@Override
public void initDiscovery(AbstractVerticle service) {
  final JsonObject config = service.config();
  final Vertx vertx = service.getVertx();
  if (!service.getClass().isAnnotationPresent(K8SDiscovery.class))
    return;
  final K8SDiscovery annotation = service.getClass().getAnnotation(K8SDiscovery.class);
  final String customClientClassName =
      ConfigurationUtil.getStringConfiguration(
          config,
          CUSTOM_CLIENT_CONFIGURATION,
          annotation.customClientConfiguration().getCanonicalName());
  final CustomClientConfig custConf = getCustomConfiguration(customClientClassName);
  final Config customConfiguration = custConf.createCustomConfiguration(vertx);
  if (customConfiguration == null) {
    final String master_url =
        ConfigurationUtil.getStringConfiguration(config, MASTER_URL, annotation.master_url());
    final String namespace =
        ConfigurationUtil.getStringConfiguration(config, NAMESPACE, annotation.namespace());
    final Config kubeConfig =
        new ConfigBuilder().withMasterUrl(master_url).withNamespace(namespace).build();

    updateKubeConfig(kubeConfig, config, annotation);
    // 1.) Check from K8SDiscovery Annotation
    // 1.1) read properties and from Annotation or from configuration
    // 2.) init KubernetesClient
    KubeDiscovery.resolveBeanAnnotations(service, kubeConfig);
  } else {
    updateKubeConfig(customConfiguration, config, annotation);
    KubeDiscovery.resolveBeanAnnotations(service, customConfiguration);
  }
}
 
Example 3
Source File: SpringVerticleFactory.java    From spring-vertx-ext with Apache License 2.0 5 votes vote down vote up
/**
 * 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);

}
 
Example 4
Source File: VxmsEndpoint.java    From vxms with Apache License 2.0 3 votes vote down vote up
/**
 * 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)));
}