package cz.senslog.analytics.module.api;

import cz.senslog.analytics.domain.ThresholdViolationNotification;
import cz.senslog.analytics.module.NotificationModule;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;

public abstract class SimpleModule extends AbstractVerticle implements ModuleDescriptor {

    protected abstract void configure();

    protected abstract void run() throws Exception;

    public final void reconfigure() {
        configure();
    }

    @Override
    public final String id() {
        return String.format("__module.%s", getClass().getSimpleName());
    }

    @Override
    public final void start() throws Exception {
        configure();
        run();
    }

    protected final EventBus eventBus() {
        return vertx.eventBus();
    }

    protected final void notify(ThresholdViolationNotification notification) {
        eventBus().publish(Module.of(NotificationModule.class).id(), notification);
    }
}