All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.charlemaznable.bunny.client.guice.BunnyEventBusModular Maven / Gradle / Ivy

Go to download

Bunny rabbits will skip hand-in-hand with baby lambs across sunny green meadows.

There is a newer version: 2023.0.4
Show newest version
package com.github.charlemaznable.bunny.client.guice;

import com.github.charlemaznable.bunny.client.config.BunnyClientConfig;
import com.github.charlemaznable.bunny.client.eventbus.BunnyEventBus;
import com.github.charlemaznable.core.codec.nonsense.NonsenseOptions;
import com.github.charlemaznable.core.codec.signature.SignatureOptions;
import com.github.charlemaznable.core.guice.Modulee;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.util.Modules;
import com.google.inject.util.Providers;
import io.vertx.core.Vertx;

import javax.annotation.Nullable;

import static com.github.charlemaznable.core.lang.Condition.nullThen;

public final class BunnyEventBusModular extends AbstractBunnyModular {

    private Module vertxModule;

    public BunnyEventBusModular() {
        super();
    }

    public BunnyEventBusModular(Class configClass) {
        super(configClass);
    }

    public BunnyEventBusModular(BunnyClientConfig configImpl) {
        super(configImpl);
    }

    public BunnyEventBusModular(Module configModule) {
        super(configModule);
    }

    public BunnyEventBusModular vertx(Vertx vertx) {
        return vertxModule(new AbstractModule() {
            @Override
            protected void configure() {
                bind(Vertx.class).toProvider(Providers.of(vertx));
            }
        });
    }

    public BunnyEventBusModular vertxModule(Module vertxModule) {
        this.vertxModule = vertxModule;
        return this;
    }

    public Module createModule() {
        return Modulee.combine(this.configModule, nullThen(vertxModule, () -> Modules.EMPTY_MODULE),
                new AbstractModule() {
                    @Provides
                    public BunnyEventBus bunnyEventBus(Vertx vertx,
                                                       @Nullable BunnyClientConfig bunnyClientConfig,
                                                       @Nullable NonsenseOptions nonsenseOptions,
                                                       @Nullable SignatureOptions signatureOptions) {
                        return new BunnyEventBus(vertx, bunnyClientConfig, nonsenseOptions, signatureOptions);
                    }
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy