vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

VerticleGroup is a list of verticle that share the same context.

Open wang007 opened this issue 4 years ago • 6 comments

when you haved a list of verticle that hope to run on the same context to avoid data race, you can used VerticleGroup

Use cases

  public class CompositeVerticleGroup extends AbstractVerticleGroup {

    @Override
    public List<Verticle> verticles() {
      return Arrays.asList(new VerticleA(), new VerticleB(), new VerticleC());
    }


    static class VerticleA extends AbstractVerticle {}

    static class VerticleB extends AbstractVerticle {}

    static class VerticleC extends AbstractVerticle {}

  }
  
 vertx.deployVerticle(CompositeVerticleGroup)

VerticleA, VerticleB, VerticleC and CompositeVerticleGroup will run on the same context.

Contribution

yes, I haved create an pr

wang007 avatar Jun 04 '21 06:06 wang007

The Vert.x model is to design independent units of processing as verticles and exchange messages over the eventbus to avoid multithread programming issues.

If you need three components to be invoked on the same Vert.x context, why not deploying a single verticle and creating the components inside?

tsegismont avatar Jun 04 '21 08:06 tsegismont

As the title says, we want a group of Verticle to run on the same context. This is useful when you have a large number of Verticle. I've already discussed this feature with Vietj on Discord, and VietJ says it is an interesting approach.

wang007 avatar Jun 04 '21 09:06 wang007

For solving this issue, VerticleGroup is useful https://github.com/vert-x3/vertx-web/issues/1909

wang007 avatar Jun 04 '21 09:06 wang007

I think it would be simpler to allow a verticle to inherit the context of its parent when it is deployed, e.g new DeploymentOptions().setInheritParentContext(true)

This would be rejected when the number of instances is > 1

vietj avatar Jun 04 '21 16:06 vietj

@vietj I think they are different, and they can exist together. InheritParentContext has some restrictions, such as whether it is the same Work Pool and the configuration associated with the Work Pool. But the verticleGroup doesn't need to be concerned because these options must be the same.

wang007 avatar Jun 04 '21 17:06 wang007

VerticleGroup is just a functional class; it doesn't change anything. The user can choose to use it or not, but it works well

wang007 avatar Jun 04 '21 17:06 wang007