vert-x3 / vertx-service-proxy

EventBus Proxy generation
Apache License 2.0
66 stars 58 forks source link

Allow inheritance when registering service binder #144

Open victorpasqualino opened 1 year ago

victorpasqualino commented 1 year ago

Motivation:

Example:

public class Example {

    public static interface Repository<Key, Value> {}

    @ProxyGen
    public static interface UserRepository extends Repository<String, User> {}

    public static class User {}

    public static abstract class AbstractRepositoryVerticle<Key, Value> extends AbstractVerticle implements Repository<Key, Value> {

        private final String address;
        private final Class<? extends Repository<Key, Value>> clazz;

        public AbstractRepositoryVerticle(String address, Class<? extends Repository<Key, Value>> clazz) {
            this.address = address;
            this.clazz = clazz;
        }

        @Override
        public void start() throws Exception {
            new ServiceBinder(vertx).setAddress(address).register(clazz, this);
        }
    }

    public static class UserRepositoryVerticle extends AbstractRepositoryVerticle<String, User> implements UserRepository {
        public UserRepositoryVerticle() {
            super("user-repository", UserRepository.class);
        }
    }

}