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

com.yammer.dropwizard.config.Bootstrap Maven / Gradle / Ivy

package com.yammer.dropwizard.config;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.yammer.dropwizard.Bundle;
import com.yammer.dropwizard.ConfiguredBundle;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.cli.Command;
import com.yammer.dropwizard.cli.ConfiguredCommand;
import com.yammer.dropwizard.json.ObjectMapperFactory;

import java.util.List;

public class Bootstrap {
    private String name;
    private final ObjectMapperFactory objectMapperFactory;
    private final List bundles;
    private final List> configuredBundles;
    private final List commands;

    public Bootstrap(Service service) {
        this.name = service.getClass().getSimpleName();
        this.objectMapperFactory = new ObjectMapperFactory();
        this.bundles = Lists.newArrayList();
        this.configuredBundles = Lists.newArrayList();
        this.commands = Lists.newArrayList();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addBundle(Bundle bundle) {
        bundle.initialize(this);
        bundles.add(bundle);
    }

    public void addBundle(ConfiguredBundle bundle) {
        configuredBundles.add(bundle);
    }

    public void addCommand(Command command) {
        commands.add(command);
    }

    public void addCommand(ConfiguredCommand command) {
        commands.add(command);
    }

    public ObjectMapperFactory getObjectMapperFactory() {
        return objectMapperFactory;
    }

    public void runWithBundles(T configuration, Environment environment) throws Exception {
        for (Bundle bundle : bundles) {
            bundle.run(environment);
        }
        for (ConfiguredBundle bundle : configuredBundles) {
            bundle.run(configuration, environment);
        }
    }

    public ImmutableList getCommands() {
        return ImmutableList.copyOf(commands);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy