io.dropwizard.ConfiguredBundle Java Examples

The following examples show how to use io.dropwizard.ConfiguredBundle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AirpalApplication.java    From airpal with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<ConfiguredBundle<AirpalConfiguration>> getConfiguredBundles()
{
    Iterable<ConfiguredBundle<AirpalConfiguration>> bundles = super.getConfiguredBundles();
    ImmutableList.Builder<ConfiguredBundle<AirpalConfiguration>> builder = ImmutableList.builder();

    for (ConfiguredBundle<AirpalConfiguration> bundle : bundles) {
        builder.add(bundle);
    }
    builder.add(new ShiroBundle<AirpalConfiguration>() {
        @Override
        protected ShiroConfiguration narrow(AirpalConfiguration configuration)
        {
            return configuration.getShiro();
        }
    });
    return builder.build();
}
 
Example #2
Source File: BootstrapProxyFactory.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
/**
 * @param bootstrap dropwizard bootstrap object
 * @param context   guicey configuration context
 * @return dropwizard bootstrap proxy object
 */
@SuppressWarnings("unchecked")
public static Bootstrap create(final Bootstrap bootstrap, final ConfigurationContext context) {
    try {
        final ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass(Bootstrap.class);
        final Class proxy = factory.createClass();

        final Bootstrap res = (Bootstrap) proxy.getConstructor(Application.class).newInstance(new Object[]{null});
        ((Proxy) res).setHandler((self, thisMethod, proceed, args) -> {
            // intercept only bundle addition
            if (thisMethod.getName().equals("addBundle")) {
                context.registerDropwizardBundles((ConfiguredBundle) args[0]);
                return null;
            }
            // other methods called as is
            return thisMethod.invoke(bootstrap, args);
        });
        return res;
    } catch (Exception e) {
        throw new IllegalStateException("Failed to create Bootstrap proxy", e);
    }
}
 
Example #3
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
/**
 * @param bootstrap dropwizard bootstrap instance
 */
public void initPhaseStarted(final Bootstrap bootstrap) {
    this.bootstrap = bootstrap;
    // register in shared state just in case
    this.sharedState.put(Bootstrap.class, bootstrap);
    this.sharedState.assignTo(bootstrap.getApplication());
    // delayed init of registered dropwizard bundles
    final Stopwatch time = stat().timer(BundleTime);
    final Stopwatch dwtime = stat().timer(DropwizardBundleInitTime);
    for (ConfiguredBundle bundle : getEnabledDropwizardBundles()) {
        registerDropwizardBundle(bundle);
    }
    lifecycle().initializationStarted(bootstrap, getEnabledDropwizardBundles(),
            getDisabledDropwizardBundles(), getIgnoredItems(ConfigItem.DropwizardBundle));
    dwtime.stop();
    time.stop();
}
 
Example #4
Source File: LifecycleSupport.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
public void initializationStarted(final Bootstrap bootstrap,
                                  final List<ConfiguredBundle> bundles,
                                  final List<ConfiguredBundle> disabled,
                                  final List<ConfiguredBundle> ignored) {
    this.context.setBootstrap(bootstrap);
    if (!bundles.isEmpty()) {
        broadcast(new DropwizardBundlesInitializedEvent(context, bundles, disabled, ignored));
    }
}
 
Example #5
Source File: DropwizardBundlesInitializedEvent.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
public DropwizardBundlesInitializedEvent(final EventsContext context,
                                         final List<ConfiguredBundle> bundles,
                                         final List<ConfiguredBundle> disabled,
                                         final List<ConfiguredBundle> ignored) {
    super(GuiceyLifecycle.DropwizardBundlesInitialized, context);
    this.bundles = bundles;
    this.disabled = disabled;
    this.ignored = ignored;
}
 
Example #6
Source File: AirpalApplicationBase.java    From airpal with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Bootstrap<T> bootstrap)
{
    for (ConfiguredBundle<T> configuredBundle : getConfiguredBundles()) {
        bootstrap.addBundle(configuredBundle);
    }
    for (Bundle bundle : getBundles()) {
        bootstrap.addBundle(bundle);
    }
}
 
Example #7
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
/**
 * Direct dropwizard bundle registration from
 * {@link ru.vyarus.dropwizard.guice.GuiceBundle.Builder#dropwizardBundles(ConfiguredBundle...)}
 * or {@link ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap#dropwizardBundles(
 * ConfiguredBundle[])}.
 * Context class is set to currently processed bundle.
 *
 * @param bundles dropwizard bundles
 */
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition")
public void registerDropwizardBundles(final ConfiguredBundle... bundles) {
    for (ConfiguredBundle bundle : bundles) {
        final DropwizardBundleItemInfo info = register(ConfigItem.DropwizardBundle, bundle);
        // register only non duplicate bundles
        // bundles, registered in root GuiceBundle will be registered as soon as bootstrap would be available
        if (info.getRegistrationAttempts() == 1 && bootstrap != null) {
            registerDropwizardBundle(bundle);
        }
    }
}
 
Example #8
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
/**
 * Guicey bundle manual disable registration from
 * {@link ru.vyarus.dropwizard.guice.GuiceBundle.Builder#disableBundles(Class[])}.
 *
 * @param bundles modules to disable
 */
@SuppressWarnings("PMD.UseVarargs")
public void disableDropwizardBundle(final Class<? extends ConfiguredBundle>[] bundles) {
    for (Class<? extends ConfiguredBundle> bundle : bundles) {
        registerDisable(ConfigItem.DropwizardBundle, ItemId.from(bundle));
    }
}
 
Example #9
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void registerDropwizardBundle(final ConfiguredBundle bundle) {
    // register decorated dropwizard bundle to track transitive bundles
    // or bundle directly if tracking disabled
    bootstrap.addBundle(option(GuiceyOptions.TrackDropwizardBundles)
            ? new DropwizardBundleTracker(bundle, this) : bundle);
}
 
Example #10
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
/**
 * @return all disabled dropwizard bundles
 */
public List<ConfiguredBundle> getDisabledDropwizardBundles() {
    return getDisabledItems(ConfigItem.DropwizardBundle);
}
 
Example #11
Source File: SingularityService.java    From Singularity with Apache License 2.0 4 votes vote down vote up
public Iterable<? extends ConfiguredBundle<T>> getDropwizardConfiguredBundles(
  Bootstrap<T> bootstrap
) {
  return ImmutableList.of();
}
 
Example #12
Source File: SingularityService.java    From Singularity with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(final Bootstrap<T> bootstrap) {
  if (
    !Strings.isNullOrEmpty(
      System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY)
    )
  ) {
    bootstrap.setConfigurationSourceProvider(
      new MergingSourceProvider(
        bootstrap.getConfigurationSourceProvider(),
        System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY),
        bootstrap.getObjectMapper(),
        new YAMLFactory()
      )
    );
  }

  final Iterable<? extends Module> additionalModules = checkNotNull(
    getGuiceModules(bootstrap),
    "getGuiceModules() returned null"
  );
  final Iterable<? extends Bundle> additionalBundles = checkNotNull(
    getDropwizardBundles(bootstrap),
    "getDropwizardBundles() returned null"
  );
  final Iterable<? extends ConfiguredBundle<T>> additionalConfiguredBundles = checkNotNull(
    getDropwizardConfiguredBundles(bootstrap),
    "getDropwizardConfiguredBundles() returned null"
  );

  guiceBundle =
    GuiceBundle
      .defaultBuilder(SingularityConfiguration.class)
      .modules(getServiceModule(), getObjectMapperModule(), new SingularityAuthModule())
      .modules(additionalModules)
      .enableGuiceEnforcer(false)
      .stage(getGuiceStage())
      .build();
  bootstrap.addBundle(guiceBundle);

  bootstrap.addBundle(new CorsBundle());
  bootstrap.addBundle(new ViewBundle<>());
  bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
  bootstrap.addBundle(
    new MigrationsBundle<SingularityConfiguration>() {

      @Override
      public DataSourceFactory getDataSourceFactory(
        final SingularityConfiguration configuration
      ) {
        return configuration.getDatabaseConfiguration().get();
      }
    }
  );

  for (Bundle bundle : additionalBundles) {
    bootstrap.addBundle(bundle);
  }

  for (ConfiguredBundle<T> configuredBundle : additionalConfiguredBundles) {
    bootstrap.addBundle(configuredBundle);
  }

  bootstrap.getObjectMapper().registerModule(new ProtobufModule());
  bootstrap.getObjectMapper().registerModule(new GuavaModule());
  bootstrap.getObjectMapper().registerModule(new Jdk8Module());
  bootstrap.getObjectMapper().setSerializationInclusion(Include.NON_ABSENT);
  bootstrap
    .getObjectMapper()
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
 
Example #13
Source File: EmbeddedSingularityExample.java    From Singularity with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<? extends ConfiguredBundle<SingularityConfiguration>> getDropwizardConfiguredBundles(
  final Bootstrap<SingularityConfiguration> bootstrap
) {
  return ImmutableSet.of();
}
 
Example #14
Source File: AirpalApplicationBase.java    From airpal with Apache License 2.0 4 votes vote down vote up
public Iterable<ConfiguredBundle<T>> getConfiguredBundles()
{
    return Arrays.asList(new ViewBundle());
}
 
Example #15
Source File: DropwizardBundleTracker.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
public DropwizardBundleTracker(final ConfiguredBundle<? super T> bundle, final ConfigurationContext context) {
    this.bundle = bundle;
    this.context = context;
}
 
Example #16
Source File: BundleSpec.java    From soabase with Apache License 2.0 4 votes vote down vote up
public BundleSpec(ConfiguredBundle<T> configuredBundle, Phase phase)
{
    this.bundle = null;
    this.configuredBundle = configuredBundle;
    this.phase = phase;
}
 
Example #17
Source File: ConfigurationContext.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
/**
 * @return all configured dropwizard bundles (without duplicates)
 */
public List<ConfiguredBundle> getEnabledDropwizardBundles() {
    return getEnabledItems(ConfigItem.DropwizardBundle);
}
 
Example #18
Source File: DropwizardBundleItemInfoImpl.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
public DropwizardBundleItemInfoImpl(final ConfiguredBundle bundle) {
    super(ConfigItem.DropwizardBundle, bundle);
}
 
Example #19
Source File: DropwizardBundleItemInfoImpl.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
public DropwizardBundleItemInfoImpl(final Class<? extends ConfiguredBundle> type) {
    super(ConfigItem.DropwizardBundle, type);
}
 
Example #20
Source File: DropwizardBundlesInitializedEvent.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
/**
 * @return ignored dropwizard bundles (duplicates) or empty list
 */
public List<ConfiguredBundle> getIgnored() {
    return ignored;
}
 
Example #21
Source File: DropwizardBundlesInitializedEvent.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
/**
 * @return disabled dropwizard bundles or empty list
 */
public List<ConfiguredBundle> getDisabled() {
    return disabled;
}
 
Example #22
Source File: BundleSpec.java    From soabase with Apache License 2.0 4 votes vote down vote up
public ConfiguredBundle<T> getConfiguredBundle()
{
    return configuredBundle;
}
 
Example #23
Source File: GuiceyBootstrap.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Shortcut for dropwizard bundles registration (instead of {@code bootstrap().addBundle()}), but with
 * duplicates detection and tracking in diagnostic reporting. Dropwizard bundle is immediately initialized.
 *
 * @param bundles dropwizard bundles to register
 * @return bootstrap instance for chained calls
 * @see ru.vyarus.dropwizard.guice.GuiceBundle.Builder#dropwizardBundles(ConfiguredBundle...)
 */
public GuiceyBootstrap dropwizardBundles(final ConfiguredBundle... bundles) {
    context.registerDropwizardBundles(bundles);
    return this;
}
 
Example #24
Source File: GuiceBundle.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Dropwizard bundles registration. There is no difference with direct bundles registration (with
 * {@link Bootstrap#addBundle(ConfiguredBundle)}, which is actually called almost immediately),
 * except guicey tracking (registered bundles are showed in diagnostic report), ability to disable bundle and
 * automatic duplicates detection (see {@link #duplicateConfigDetector(DuplicateConfigDetector)}).
 * <p>
 * Only bundles registered with guicey api are checked! For example, if you register one instance of the same
 * bundle directly into bootstrap and another one with guicey api - guicey will not be able to track duplicate
 * registration. So it's better to register all bundles through guicey api.
 * <p>
 * By default, guicey will also track transitive bundles registrations (when registered bundle register
 * other bundles) so disable and deduplication logic will apply to them too. Tracking could be disabled
 * with {@link GuiceyOptions#TrackDropwizardBundles} option.
 *
 * @param bundles guicey bundles
 * @return builder instance for chained calls
 */
public Builder dropwizardBundles(final ConfiguredBundle... bundles) {
    bundle.context.registerDropwizardBundles(bundles);
    return this;
}
 
Example #25
Source File: GuiceBundle.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Dropwizard bundles disable is mostly useful for testing. Note that it can disable only bundles directly
 * registered through guicey api or bundles registered by them (if dropwizard bundles tracking
 * not disabled with {@link GuiceyOptions#TrackDropwizardBundles}).
 *
 * @param bundles guicey bundles to disable
 * @return builder instance for chained calls
 */
@SafeVarargs
public final Builder disableDropwizardBundles(final Class<? extends ConfiguredBundle>... bundles) {
    bundle.context.disableDropwizardBundle(bundles);
    return this;
}
 
Example #26
Source File: GuiceyConfigurationInfo.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Note that this list could be larger then {@link #getDropwizardBundles()} because multiple bundle instances
 * of the same class could be registered.
 *
 * @return types of all enabled normal guice modules or empty list
 * @see ru.vyarus.dropwizard.guice.GuiceBundle.Builder#bundles(GuiceyBundle...)
 * @see ConfigurationInfo#getInfo(ItemId) for loaded model object for id
 */
public List<ItemId<ConfiguredBundle>> getDropwizardBundleIds() {
    return context.getItems(ConfigItem.DropwizardBundle, Filters.enabled());
}
 
Example #27
Source File: GuiceyConfigurationInfo.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Note that multiple instances could be installed for some bundles, but returned list will contain just
 * bundle type (no matter how many instances were actually installed).
 *
 * @return types of all installed and enabled dropwizard bundles or empty list
 */
public List<Class<ConfiguredBundle>> getDropwizardBundles() {
    return typesOnly(getDropwizardBundleIds());
}
 
Example #28
Source File: DropwizardBundlesInitializedEvent.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * Note that transitive bundles would be also included (if bundles tracking not disabled
 * {@link ru.vyarus.dropwizard.guice.GuiceyOptions#TrackDropwizardBundles}).
 *
 * @return initialized dropwizard bundles (excluding disabled)
 */
public List<ConfiguredBundle> getBundles() {
    return bundles;
}