Java 类io.dropwizard.Bundle 实例源码

项目: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);
}
项目:dropwizard-guicey    文件:ContextTreeRenderer.java   
/**
 * Renders configuration tree report according to provided config.
 * By default report padded left with one tab. Subtrees are always padded with empty lines for better
 * visibility.
 *
 * @param config tree rendering config
 * @return rendered tree
 */
@Override
public String renderReport(final ContextTreeConfig config) {

    final Set<Class<?>> scopes = service.getActiveScopes();

    final TreeNode root = new TreeNode("APPLICATION");
    renderScopeContent(config, root, Application.class);

    renderSpecialScope(config, scopes, root, "BUNDLES LOOKUP", GuiceyBundleLookup.class);
    renderSpecialScope(config, scopes, root, "DROPWIZARD BUNDLES", Bundle.class);
    renderSpecialScope(config, scopes, root, "CLASSPATH SCAN", ClasspathScanner.class);

    final StringBuilder res = new StringBuilder().append(Reporter.NEWLINE).append(Reporter.NEWLINE);
    root.render(res);
    return res.toString();
}
项目:graceland-core    文件:AbstractPlugin.java   
private void buildBinders() {
    if (!bindersBuilt) {
        jerseyBinder = Multibinder.newSetBinder(binder(), Object.class, Graceland.class);
        managedBinder = Multibinder.newSetBinder(binder(), Managed.class, Graceland.class);
        managedClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ManagedClass, Graceland.class);
        healthCheckBinder = Multibinder.newSetBinder(binder(), HealthCheck.class, Graceland.class);
        healthCheckClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.HealthCheckClass, Graceland.class);
        taskBinder = Multibinder.newSetBinder(binder(), Task.class, Graceland.class);
        taskClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.TaskClass, Graceland.class);
        bundleBinder = Multibinder.newSetBinder(binder(), Bundle.class, Graceland.class);
        bundleClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.BundleClass, Graceland.class);
        commandBinder = Multibinder.newSetBinder(binder(), Command.class, Graceland.class);
        commandClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.CommandClass, Graceland.class);
        initializerBinder = Multibinder.newSetBinder(binder(), Initializer.class, Graceland.class);
        initializerClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.InitializerClass, Graceland.class);
        configuratorBinder = Multibinder.newSetBinder(binder(), Configurator.class, Graceland.class);
        configuratorClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ConfiguratorClass, Graceland.class);

        bindersBuilt = true;
    }
}
项目:graceland-core    文件:Platform.java   
/**
 * Ran when the Dropwizard service initializes. This method is responsible for setting up the
 * {@link io.dropwizard.Bundle}s and {@link io.dropwizard.cli.Command}s.
 *
 * @param bootstrap Provided by Dropwizard.
 */
@Override
public void initialize(Bootstrap<PlatformConfiguration> bootstrap) {
    for (Initializer initializer : wrapper.getInitializers()) {
        initializer.initialize(bootstrap);
        LOGGER.debug("Registered Initializer: {}", initializer.getClass().getCanonicalName());
    }

    for (Bundle bundle : wrapper.getBundles()) {
        bootstrap.addBundle(bundle);
        LOGGER.debug("Registered Bundle: {}", bundle.getClass().getCanonicalName());
    }

    for (Command command : wrapper.getCommands()) {
        bootstrap.addCommand(command);
        LOGGER.debug("Registered Command: {}", command.getClass().getCanonicalName());
    }
}
项目:graceland-core    文件:AbstractPluginTest.java   
@Test
public void bundle_binds_work() {
    final Bundle bundle = mock(Bundle.class);
    final Class<TestBundle> bundleClass = TestBundle.class;

    Injector injector = Guice.createInjector(new AbstractPlugin() {
        @Override
        protected void configure() {
            bindBundle(bundle);
            bindBundle(bundleClass);
        }
    });

    Set<Bundle> bundleSet = injector.getInstance(Keys.Bundles);
    Set<Class<? extends Bundle>> bundleClassSet = injector.getInstance(Keys.BundleClasses);

    assertThat(bundleSet, hasSize(1));
    assertThat(bundleSet, hasItem(bundle));
    assertThat(bundleClassSet, hasSize(1));
    assertThat(bundleClassSet, hasItem(TestBundle.class));
}
项目:graceland-core    文件:PlatformTest.java   
@Test
public void initialize_adds_bundles() {
    final Bundle bundle = mock(Bundle.class);
    final Class<TestBundle> bundleClass = TestBundle.class;

    Application application = buildApplication(
            new AbstractPlugin() {
                @Override
                protected void configure() {
                    bindBundle(bundle);
                    bindBundle(bundleClass);
                }
            }
    );

    new Platform(application).initialize(bootstrap);

    verify(bootstrap).addBundle(eq(bundle));
    verify(bootstrap).addBundle(isA(TestBundle.class));
}
项目: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   
@Test
public void testAddBundleIfNotExist() {
    Bundle       newBundle = mock(Bundle.class);
    Bootstrap<?> bootstrap = new Bootstrap<>(null);
    //
    Bundle addedBundle = BootstrapExtensions.addBundleIfNotExist(bootstrap, Bundle.class, () -> newBundle);
    //
    assertThat(addedBundle).isSameAs(newBundle);
    assertThat(BootstrapExtensions.getBundles(bootstrap)).containsExactly(newBundle);
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@Test
public void testAddBundleIfNotExistPreExisting() {
    Supplier<Bundle> bundleSupplier = mock(Supplier.class);
    Bundle           oldBundle      = mock(Bundle.class);
    Bootstrap<?>     bootstrap      = new Bootstrap<>(null);
    bootstrap.addBundle(oldBundle);
    //
    Bundle addedBundle = BootstrapExtensions.addBundleIfNotExist(bootstrap, Bundle.class, bundleSupplier);
    //
    assertThat(addedBundle).isSameAs(oldBundle);
    assertThat(BootstrapExtensions.getBundles(bootstrap)).containsExactly(oldBundle);
    verifyZeroInteractions(bundleSupplier);
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@Test
public void testGetBundles() {
    Bootstrap<?> bootstrap = new Bootstrap<>(null);
    Bundle       bundle    = mock(Bundle.class);
    bootstrap.addBundle(bundle);
    //
    List<Bundle> bundles = BootstrapExtensions.getBundles(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);
}
项目:dropwizardry    文件:GuiceBootstrap.java   
@Override
public void run(Environment environment) {
    for(Class<? extends Bundle> bundleClass : runtimeBundleClasses) {
        Bundle runtimeBundle = injector.getInstance(bundleClass);
        runtimeBundle.run(environment);
    }

    //free up memory
    runtimeBundleClasses.clear();
    isInitialized = true;
}
项目:dropwizard-guicey    文件:ContextTreeRenderer.java   
/**
 * Render entire scope subtree. Scope items are rendered first and bundles at the end (because most likely
 * they will be subtrees).
 *
 * @param config tree config
 * @param root   root node
 * @param scope  scope to render
 */
private void renderScopeContent(final ContextTreeConfig config, final TreeNode root, final Class<?> scope) {
    renderScopeItems(config, root, scope);

    final List<Class<Object>> bundles = service.getData()
            .getItems(Filters.registeredBy(scope).and(Filters.type(ConfigItem.Bundle)));

    for (Class<Object> bundle : bundles) {
        renderBundle(config, root, scope, bundle);
    }
}
项目:dropwizard-guicey    文件:ConfigurationContext.java   
/**
 * Register bundles, recognized from dropwizard bundles. {@link Bundle} used as context.
 *
 * @param bundles recognized bundles
 * @see ru.vyarus.dropwizard.guice.GuiceBundle.Builder#configureFromDropwizardBundles()
 */
public void registerDwBundles(final List<GuiceyBundle> bundles) {
    setScope(Bundle.class);
    for (GuiceyBundle bundle : bundles) {
        register(ConfigItem.Bundle, bundle);
    }
    closeScope();
}
项目:dropwizard-guicey    文件:ConfigurationContext.java   
/**
 * Register bundles resolved by lookup mechanism. {@link GuiceyBundleLookup} used as context.
 *
 * @param bundles bundles resolved by lookup mechanism
 * @see GuiceyBundleLookup
 */
public void registerLookupBundles(final List<GuiceyBundle> bundles) {
    setScope(GuiceyBundleLookup.class);
    for (GuiceyBundle bundle : bundles) {
        register(ConfigItem.Bundle, bundle);
    }
    closeScope();
}
项目: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 Bundle> getDropwizardBundles(final Bootstrap<SingularityConfiguration> bootstrap) {
  return ImmutableSet.of();
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@Test(expected = NullPointerException.class)
public void testAddBundleIfNotExistNullBootstrap() {
    BootstrapExtensions.addBundleIfNotExist(null, Bundle.class, () -> mock(Bundle.class));
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@Test(expected = NullPointerException.class)
public void testAddBundleIfNotExistNullBundleSupplier() {
    BootstrapExtensions.addBundleIfNotExist(new Bootstrap<>(null), Bundle.class, null);
}
项目:dropwizard-hk2    文件:BootstrapExtensionsTest.java   
@Test(expected = NullPointerException.class)
public void testAddBundleIfNotExistNullBundleType() {
    BootstrapExtensions.addBundleIfNotExist(new Bootstrap<>(null), null, () -> mock(Bundle.class));
}
项目:soabase    文件:BundleSpec.java   
public BundleSpec(Bundle bundle, Phase phase)
{
    this.bundle = bundle;
    this.configuredBundle = null;
    this.phase = phase;
}
项目:soabase    文件:BundleSpec.java   
public Bundle getBundle()
{
    return bundle;
}
项目:dropwizardry    文件:GuiceBootstrap.java   
public void addBundle(Class<? extends Bundle> bundleClass) {
    if(isInitialized) {
        throw new IllegalStateException("You cannot add bundles after GuiceBootstrap has been run");
    }
    runtimeBundleClasses.add(bundleClass);
}
项目:dropwizard-guicey    文件:BundleItemInfoImpl.java   
public BundleItemInfoImpl(final Class<?> type) {
    super(ConfigItem.Bundle, type);
}
项目:dropwizard-guicey    文件:BundleItemInfoImpl.java   
@Override
public boolean isFromDwBundle() {
    return getRegisteredBy().contains(Bundle.class);
}
项目:dropwizard-guicey    文件:ConfigurationContext.java   
/**
 * @return all configured bundles (without duplicates)
 */
public List<GuiceyBundle> getBundles() {
    return getItems(ConfigItem.Bundle);
}
项目:graceland-core    文件:AbstractPlugin.java   
protected void bindBundle(Bundle bundle) {
    Preconditions.checkNotNull(bundle, "Bundle cannot be null.");
    buildBinders();
    bundleBinder.addBinding().toInstance(bundle);
}
项目:graceland-core    文件:AbstractPlugin.java   
protected void bindBundle(Class<? extends Bundle> bundleClass) {
    Preconditions.checkNotNull(bundleClass, "Bundle Class cannot be null.");
    buildBinders();
    bundleClassBinder.addBinding().toInstance(bundleClass);
}
项目:graceland-core    文件:InjectorWrapper.java   
public ImmutableSet<Bundle> getBundles() {
    return getAndBuildInstances(Keys.Bundles, Keys.BundleClasses);
}
项目:Singularity    文件:EmbeddedSingularityExample.java   
@Override
public Iterable<? extends Bundle> getDropwizardBundles(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);
}
项目:dropwizard-hk2    文件:BootstrapExtensions.java   
/**
 * Adds a {@link Bundle} 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 bundle of type {@code T} in the {@code bootstrap}
 */
<T extends Bundle> T addBundleIfNotExist(
    @NonNull Bootstrap<?> 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);
}
项目:Mastering-Mesos    文件:SingularityService.java   
/**
 * Dropwizard bundles used in addition to the bundles required by Singularity. This is an extension point when embedding
 * Singularity into a custom service.
 */
public Iterable<? extends Bundle> getDropwizardBundles(Bootstrap<T> bootstrap) {
  return ImmutableList.of();
}
项目:dropwizard-hk2    文件:BootstrapExtensions.java   
/**
 * Retrieves the list of {@link Bundle bundles} registered with a {@link Bootstrap}. Note, this does not return
 * {@link ConfiguredBundle configured bundles}.
 *
 * @param bootstrap
 *     {@code Bootstrap} from which to retrieve bundles
 *
 * @return The bundles in the {@code Bootstrap}
 *
 * @see #getConfiguredBundles(Bootstrap)
 */
@SuppressWarnings("unchecked")
@SneakyThrows
List<Bundle> getBundles(@NonNull Bootstrap<?> bootstrap) {
    return Collections.unmodifiableList((List<Bundle>) BUNDLES_FIELD.get(bootstrap));
}
项目:dropwizardry    文件:AbstractDropwizardModule.java   
/**
 * Anything added here will only have their run() method called. initialize() will not be called
 * @param bundleClass
 */
protected void addBundle(Class<? extends Bundle> bundleClass) {
    bundles.add(bundleClass);
}
项目:dropwizard-guicey    文件:ContextTreeRenderer.java   
/**
 * @param config tree config
 * @param info   item info
 * @return true if item is bundle and its hidden by config, false otherwise
 */
private boolean isHiddenBundle(final ContextTreeConfig config, final ItemInfo info) {
    return ConfigItem.Bundle.equals(info.getItemType()) && !isScopeVisible(config, null, info.getType());
}
项目:dropwizard-guicey    文件:ConfigurationContext.java   
/**
 * Usual bundle registration from {@link ru.vyarus.dropwizard.guice.GuiceBundle.Builder#bundles(GuiceyBundle...)}
 * or {@link ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBootstrap#bundles(GuiceyBundle...)}.
 * Context class is set to currently processed bundle.
 *
 * @param bundles bundles to register
 */
public void registerBundles(final GuiceyBundle... bundles) {
    for (GuiceyBundle bundle : bundles) {
        register(ConfigItem.Bundle, bundle);
    }
}
项目:Singularity    文件:SingularityService.java   
/**
 * Dropwizard bundles used in addition to the bundles required by Singularity. This is an extension point when embedding
 * Singularity into a custom service.
 */
public Iterable<? extends Bundle> getDropwizardBundles(Bootstrap<T> bootstrap) {
  return ImmutableList.of();
}