Java 类io.dropwizard.ConfiguredBundle 实例源码

项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@SuppressWarnings("unchecked")
@Test
public void testGetImplementingBundles() {
    Bootstrap<?>     bootstrap     = new Bootstrap<>(null);
    ConfiguredBundle hashSetBundle = (ConfiguredBundle) mock(HashSet.class, withSettings().extraInterfaces(ConfiguredBundle.class).defaultAnswer(RETURNS_DEEP_STUBS));
    ConfiguredBundle hashMapBundle = (ConfiguredBundle) mock(HashMap.class, withSettings().extraInterfaces(ConfiguredBundle.class).defaultAnswer(RETURNS_DEEP_STUBS));
    Bundle           treeSetBundle = (Bundle) mock(TreeSet.class, withSettings().extraInterfaces(Bundle.class).defaultAnswer(RETURNS_DEEP_STUBS));
    Bundle           treeMapBundle = (Bundle) mock(TreeMap.class, withSettings().extraInterfaces(Bundle.class).defaultAnswer(RETURNS_DEEP_STUBS));
    bootstrap.addBundle(hashMapBundle);
    bootstrap.addBundle(hashSetBundle);
    bootstrap.addBundle(treeMapBundle);
    bootstrap.addBundle(treeSetBundle);
    //
    List<Set> setBundles = BootstrapExtensions.getImplementingBundles(bootstrap, Set.class);
    List<Map> mapBundles = BootstrapExtensions.getImplementingBundles(bootstrap, Map.class);
    //
    assertThat(setBundles).isNotNull();
    assertThat(setBundles).containsExactlyInAnyOrder((Set) hashSetBundle, (Set) treeSetBundle);
    assertThat(mapBundles).isNotNull();
    assertThat(mapBundles).containsExactlyInAnyOrder((Map) hashMapBundle, (Map) treeMapBundle);
}
项目:airpal    文件:AirpalApplication.java   
@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();
}
项目:Mastering-Mesos    文件:SingularityService.java   
@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");

  final GuiceBundle<SingularityConfiguration> guiceBundle = GuiceBundle.defaultBuilder(SingularityConfiguration.class)
      .modules(new SingularityServiceModule())
      .modules(additionalModules)
      .build();
  bootstrap.addBundle(guiceBundle);

  bootstrap.addBundle(new CorsBundle());
  bootstrap.addBundle(new ViewBundle());
  bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
  bootstrap.addBundle(new AssetsBundle("/assets/api-docs/", "/api-docs/", "index.html", "api-docs"));
  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().setSerializationInclusion(Include.NON_NULL);
  bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@SuppressWarnings("unchecked")
@Test
public void testGetConfiguredBundles() {
    Bootstrap<?>     bootstrap = new Bootstrap<>(null);
    ConfiguredBundle bundle    = mock(ConfiguredBundle.class);
    bootstrap.addBundle(bundle);
    //
    List<ConfiguredBundle> bundles = BootstrapExtensions.getConfiguredBundles(bootstrap);
    //
    assertThat(bundles).isNotNull();
    assertThat(bundles).containsExactly(bundle);
}
项目:dropwizard-hk2bundle    文件:HK2Bundle.java   
@Override
public void initialize(Bootstrap<?> bootstrap) {
    this.application = bootstrap.getApplication();

    listServices(Bundle.class).forEach(bootstrap::addBundle);
    listServices(ConfiguredBundle.class).forEach(bootstrap::addBundle);
    listServices(Command.class).forEach(bootstrap::addCommand);
}
项目:dropwizard-hk2bundle    文件:HK2Bundle.java   
@Override
protected void configure() {
    bind(HK2ValidationBundle.class)
            .to(HK2ValidationBundle.class)
            .to(Bundle.class)
            .in(Singleton.class);

    bind(HK2ConfiguredBundle.class)
            .to(HK2ConfiguredBundle.class)
            .to(ConfiguredBundle.class)
            .in(Singleton.class);
}
项目:airpal    文件:AirpalApplicationBase.java   
@Override
public void initialize(Bootstrap<T> bootstrap)
{
    for (ConfiguredBundle<T> configuredBundle : getConfiguredBundles()) {
        bootstrap.addBundle(configuredBundle);
    }
    for (Bundle bundle : getBundles()) {
        bootstrap.addBundle(bundle);
    }
}
项目:Mastering-Mesos    文件:EmbeddedSingularityExample.java   
@Override
public Iterable<? extends ConfiguredBundle<SingularityConfiguration>> getDropwizardConfiguredBundles(final Bootstrap<SingularityConfiguration> bootstrap) {
  return ImmutableSet.of();
}
项目:Mastering-Mesos    文件:SingularityService.java   
public Iterable<? extends ConfiguredBundle<T>> getDropwizardConfiguredBundles(Bootstrap<T> bootstrap) {
  return ImmutableList.of();
}
项目:dropwizard-db-sharding-bundle    文件:DBShardingBundle.java   
@Override
@SuppressWarnings("unchecked")
public void initialize(Bootstrap<?> bootstrap) {
    //shardBundles.forEach(shardBundle -> bootstrap.addBundle((ConfiguredBundle)shardBundle));
    shardBundles.forEach(hibernateBundle -> bootstrap.addBundle((ConfiguredBundle) hibernateBundle));
}
项目:dropwizard-websocket-jee7-bundle    文件:WebsocketBundleTest.java   
@Test
public void websocketBundleImplementsConfiguredBundleInterface() {
    assertTrue(ConfiguredBundle.class.isAssignableFrom(WebsocketBundle.class));
}
项目:Fiazard    文件:FiazardApp.java   
private <T extends ConfiguredBundle<FiazardConfig>> T registerBundle(Bootstrap<FiazardConfig> bootstrap, T bundle) {
       bootstrap.addBundle(bundle);
    return bundle;
}
项目:soabase    文件:BundleSpec.java   
public BundleSpec(ConfiguredBundle<T> configuredBundle, Phase phase)
{
    this.bundle = null;
    this.configuredBundle = configuredBundle;
    this.phase = phase;
}
项目:soabase    文件:BundleSpec.java   
public ConfiguredBundle<T> getConfiguredBundle()
{
    return configuredBundle;
}
项目:dropwizardry    文件:AbstractDropwizardModule.java   
protected void addConfiguredBundle(@SuppressWarnings("rawtypes") Class<? extends ConfiguredBundle> bundleClass) {
    configuredBundles.add(bundleClass);
}
项目:airpal    文件:AirpalApplicationBase.java   
public Iterable<ConfiguredBundle<T>> getConfiguredBundles()
{
    return Arrays.asList(new ViewBundle());
}
项目:Singularity    文件:EmbeddedSingularityExample.java   
@Override
public Iterable<? extends ConfiguredBundle<SingularityConfiguration>> getDropwizardConfiguredBundles(final Bootstrap<SingularityConfiguration> bootstrap) {
  return ImmutableSet.of();
}
项目:Singularity    文件:SingularityService.java   
@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(new SingularityServiceModule())
      .modules(new SingularityAuthModule())
      .modules(additionalModules)
      .build();
  bootstrap.addBundle(guiceBundle);

  bootstrap.addBundle(new CorsBundle());
  bootstrap.addBundle(new ViewBundle<>());
  bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
  bootstrap.addBundle(new AssetsBundle("/assets/api-docs/", "/api-docs/", "index.html", "api-docs"));
  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().setSerializationInclusion(Include.NON_NULL);
  bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
项目:Singularity    文件:SingularityService.java   
public Iterable<? extends ConfiguredBundle<T>> getDropwizardConfiguredBundles(Bootstrap<T> bootstrap) {
  return ImmutableList.of();
}
项目:dropwizard-hk2    文件:BootstrapExtensions.java   
/**
 * Adds a {@link ConfiguredBundle} to a {@link Bootstrap bootstrap} in an idempotent manner. Use this when multiple bundles may want a
 * specific bundle as a dependency, but don't know if another bundle has already added it to the application.
 *
 * @param bootstrap
 *     {@code Bootstrap} to which the bundle should be added
 * @param bundleType
 *     Type of the bundle to look for when verifying that it hasn't already been added to the {@code bootstrap}
 * @param bundleSupplier
 *     Supplier for the bundle if it has not already been added to the {@code bootstrap}
 * @param <T>
 *     Type of the bundle
 *
 * @return The first configured bundle of type {@code T} in the {@code bootstrap}
 */
<U extends Configuration, T extends ConfiguredBundle<U>> T addConfiguredBundleIfNotExist(
    @NonNull Bootstrap<U> bootstrap, @NonNull Class<T> bundleType, @NonNull Supplier<T> bundleSupplier
) {
    List<T> implementingBundles = getImplementingBundles(bootstrap, bundleType);
    if (implementingBundles.isEmpty()) {
        T bundle = bundleSupplier.get();
        bootstrap.addBundle(bundle);
        return bundle;
    }
    return implementingBundles.get(0);
}
项目:dropwizard-hk2    文件:BootstrapExtensions.java   
/**
 * Retrieves the list of {@link ConfiguredBundle configured bundles} registered with a {@link Bootstrap}. Note, this does not return
 * {@link Bundle bundles}.
 *
 * @param bootstrap
 *     {@code Bootstrap} from which to retrieve configured bundles
 *
 * @return The configured bundles in the {@code Bootstrap}
 *
 * @see #getBundles(Bootstrap)
 */
@SuppressWarnings("unchecked")
@SneakyThrows
List<ConfiguredBundle> getConfiguredBundles(@NonNull Bootstrap<?> bootstrap) {
    return Collections.unmodifiableList((List<ConfiguredBundle>) CONFIGURED_BUNDLES_FIELD.get(bootstrap));
}