Java 类io.dropwizard.Application 实例源码

项目:outland    文件:ServerSuite.java   
@Override public Application<ServerConfiguration> newApplication() {

              return new ServerMain("outland.feature.server") {

                @Override
                protected List<Module> addModules(
                    ServerConfiguration configuration, Environment environment) {
                  return Lists.newArrayList(
                      new ServerModule(configuration),
                      new HystrixModule(),
                      new RedisModule(configuration.redis),
                      new DynamoDbModule(configuration.aws),
                      new AuthModule(configuration.auth),
                      new TestFeatureServiceModule(),
                      new TestGroupModule()
                  );
                }
              };
            }
项目: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();
}
项目:dropwizard-guicey    文件:BundleSupport.java   
/**
 * Process initially registered and all transitive bundles.
 * <ul>
 * <li>Executing initial bundles (registered in {@link ru.vyarus.dropwizard.guice.GuiceBundle}
 * and by bundle lookup)</li>
 * <li>During execution bundles may register other bundles (through {@link GuiceyBootstrap})</li>
 * <li>Execute registered bundles and repeat from previous step until no new bundles registered</li>
 * </ul>
 * Bundles duplicates are checked by type: only one bundle instance may be registered.
 *
 * @param context       bundles context
 * @param configuration configuration object
 * @param environment   environment object
 * @param application   application instance
 */
public static void processBundles(final ConfigurationContext context,
                                  final Configuration configuration, final Environment environment,
                                  final Application application) {
    final List<GuiceyBundle> bundles = context.getBundles();
    final List<Class<? extends GuiceyBundle>> installedBundles = Lists.newArrayList();
    final GuiceyBootstrap guiceyBootstrap = new GuiceyBootstrap(
            context, bundles, configuration, environment, application);

    // iterating while no new bundles registered
    while (!bundles.isEmpty()) {
        final List<GuiceyBundle> processingBundles = Lists.newArrayList(BundleSupport.removeDuplicates(bundles));
        bundles.clear();
        for (GuiceyBundle bundle : removeTypes(processingBundles, installedBundles)) {

            final Class<? extends GuiceyBundle> bundleType = bundle.getClass();
            Preconditions.checkState(!installedBundles.contains(bundleType),
                    "State error: duplicate bundle '%s' registration", bundleType.getName());

            context.setScope(bundleType);
            bundle.initialize(guiceyBootstrap);
            installedBundles.add(bundleType);
            context.closeScope();
        }
    }
}
项目:dropwizard-guicey    文件:InjectorLookup.java   
/**
 * Used internally to register application specific injector.
 *
 * @param application application instance
 * @param injector    injector instance
 * @return managed object, which must be registered to remove injector on application stop
 */
public static Managed registerInjector(final Application application, final Injector injector) {
    Preconditions.checkNotNull(application, "Application instance required");
    Preconditions.checkArgument(!INJECTORS.containsKey(application),
            "Injector already registered for application %s", application.getClass().getName());
    INJECTORS.put(application, injector);
    return new Managed() {
        @Override
        public void start() throws Exception {
            // not used
        }

        @Override
        public void stop() throws Exception {
            INJECTORS.remove(application);
        }
    };
}
项目:dropwizard-pac4j    文件:AbstractApplicationTest.java   
public void setup(
        Class<? extends Application<TestConfiguration>> applicationClass,
        String configPath, ConfigOverride... configOverrides) {
    dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass,
            ResourceHelpers.resourceFilePath(configPath), configOverrides);
    dropwizardTestSupport.before();
}
项目:dropwizard-hk2    文件:EnvironmentBinder.java   
@SuppressWarnings("unchecked")
@Override
protected void configure() {
    bind(environment).to(Environment.class);
    bind(environment.healthChecks()).to(HealthCheckRegistry.class);
    bind(environment.lifecycle()).to(LifecycleEnvironment.class);
    bind(environment.metrics()).to(MetricRegistry.class);
    bind(environment.getValidator()).to(Validator.class);
    bind(configuration).to(bootstrap.getApplication().getConfigurationClass()).to(Configuration.class);
    bind(environment.getObjectMapper()).to(ObjectMapper.class);
    bind(bootstrap.getApplication()).to((Class) bootstrap.getApplication().getClass()).to(Application.class);
}
项目:dropwizard-hk2bundle    文件:HK2Bundle.java   
@Override
protected void configure() {
    bind(application);
    bind(application).to(Application.class);
    bind(environment);
    bind(environment.getObjectMapper());
    bind(environment.metrics());
    bind(environment.getValidator());
}
项目:dcos-commons    文件:TLSTruststoreTestCommand.java   
public TLSTruststoreTestCommand(Application<T> application) {
    this(
            application,
            "truststoretest",
            "Runs GET request against HTTPS secured URL with provided truststore"
    );
}
项目:microservice-bundle    文件:ApplicationRule.java   
@Override
protected void before() throws Throwable {
  Application application = applicationClass.newInstance();
  Method method = applicationClass.getMethod("main", String[].class);
  String[] params = null;
  method.invoke(null, (Object) params);
}
项目:dropwizard-helix    文件:DropWizardApplicationRunner.java   
DropWizardServer(T builtConfig,
                 Bootstrap<T> bootstrap,
                 Application<T> application,
                 Environment environment,
                 Server jettyServer,
                 MetricRegistry metricRegistry) {
  this.builtConfig = builtConfig;
  this.bootstrap = bootstrap;
  this.application = application;
  this.environment = environment;
  this.jettyServer = jettyServer;
  this.metricRegistry = metricRegistry;
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
DropWizardServer(T builtConfig,
                 Bootstrap<T> bootstrap,
                 Application<T> application,
                 Environment environment,
                 Server jettyServer,
                 MetricRegistry metricRegistry)
{
  this.builtConfig = builtConfig;
  this.bootstrap = bootstrap;
  this.application = application;
  this.environment = environment;
  this.jettyServer = jettyServer;
  this.metricRegistry = metricRegistry;
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
DropWizardServer(T builtConfig,
                 Bootstrap<T> bootstrap,
                 Application<T> application,
                 Environment environment,
                 Server jettyServer,
                 MetricRegistry metricRegistry)
{
  this.builtConfig = builtConfig;
  this.bootstrap = bootstrap;
  this.application = application;
  this.environment = environment;
  this.jettyServer = jettyServer;
  this.metricRegistry = metricRegistry;
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
DropWizardServer(T builtConfig,
                 Bootstrap<T> bootstrap,
                 Application<T> application,
                 Environment environment,
                 Server jettyServer,
                 MetricRegistry metricRegistry)
{
  this.builtConfig = builtConfig;
  this.bootstrap = bootstrap;
  this.application = application;
  this.environment = environment;
  this.jettyServer = jettyServer;
  this.metricRegistry = metricRegistry;
}
项目:dropwizard-guicey    文件:GuiceyBootstrap.java   
public GuiceyBootstrap(final ConfigurationContext context, final List<GuiceyBundle> iterationBundles,
                       final Configuration configuration, final Environment environment,
                       final Application application) {
    this.context = context;
    this.iterationBundles = iterationBundles;
    this.configuration = configuration;
    this.environment = environment;
    this.application = application;
}
项目:dropwizard-guicey    文件:GuiceyAppRule.java   
public GuiceyAppRule(final Class<? extends Application<C>> applicationClass,
                     @Nullable final String configPath,
                     final ConfigOverride... configOverrides) {
    this.applicationClass = applicationClass;
    this.configPath = configPath;
    for (ConfigOverride configOverride : configOverrides) {
        configOverride.addToSystemProperties();
    }
}
项目:dropwizard-guicey    文件:GuiceyAppRule.java   
protected Application<C> newApplication() {
    try {
        return applicationClass.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to instantiate application", e);
    }
}
项目:monasca-common    文件:AbstractAppTest.java   
public AbstractAppTest(Class<? extends Application<C>> applicationClass, String configPath,
    ConfigOverride... configOverrides) {
  this.applicationClass = applicationClass;
  this.configPath = configPath;
  for (ConfigOverride configOverride : configOverrides) {
    configOverride.addToSystemProperties();
  }
}
项目:monasca-common    文件:AbstractAppTest.java   
public Application<C> newApplication() {
  try {
    return applicationClass.newInstance();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:trellis-rosid    文件:TrellisApplicationTest.java   
@Test
public void testGetName() {
    final Application<TrellisConfiguration> app = new TrellisApplication();
    assertEquals("Trellis LDP", app.getName());

}
项目:dropwizard-hk2    文件:HK2BundleTest.java   
@Test
public void testApplicationBound() {
    assertThat(jerseyLocator.getService(Application.class)).isSameAs(RULE.getApplication());
}
项目:sam    文件:TestCommand.java   
public TestCommand(Application<SamConfiguration> application, Optional<Description> testFilter, Class<?>... testClasses) {
  super(application, "test", "Runs junit tests");
  this.testFilter = testFilter;
  this.testClasses = testClasses;
  this.application = application;
}
项目:sam    文件:CreateDatabaseCommand.java   
public CreateDatabaseCommand(Application<SamConfiguration> application) {
  super(application, "dbcreate", "Create or update the db structure");
}
项目:sam    文件:AddTestdataCommand.java   
public AddTestdataCommand(Application<SamConfiguration> application) {
  super(application, "dbtestdata", "Add testdata to the database");
  this.application = application;
}
项目:dropwizard-hk2bundle    文件:HK2Bundle.java   
private EnvBinder(Application application, Environment environment) {
    this.application = application;
    this.environment = environment;
}
项目:WebCrawler    文件:CrawlCommand.java   
public CrawlCommand(Application<T> application) {
    super("crawl", "Crawls a website");
    this.application = application;
    this.configurationClass = application.getConfigurationClass();
}
项目:kudu-ts    文件:PutBench.java   
public PutBench(Application<KTSDConfiguration> application) {
  super(application, "put-bench", "Benchmark KTSD puts");
}
项目:cassandra-reaper    文件:ReaperTestJettyRunner.java   
@Override
public Application<ReaperApplicationConfiguration> newApplication() {
  return new ReaperApplication(this.context);
}
项目:microservice-bundle    文件:ApplicationRule.java   
public ApplicationRule(Class<? extends Application> applicationClass) {
  this.applicationClass = applicationClass;
}
项目:dropwizard-helix    文件:DropWizardApplicationRunner.java   
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config           An application configuration instance (with properties set)
 * @param applicationClass The {@link io.dropwizard.Application} implementation class
 * @param <T>              The configuration class
 * @return A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration> DropWizardServer<T> createServer(
    T config,
    Class<? extends Application<T>> applicationClass) throws Exception {
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
      System.getProperty("java.io.tmpdir"),
      config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
      = bootstrap.getConfigurationFactoryFactory()
      .create((Class<T>) config.getClass(),
          bootstrap.getValidatorFactory().getValidator(),
          bootstrap.getObjectMapper(),
          "dw");
  final T builtConfig = configurationFactory.build(
      bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
      .configure(bootstrap.getMetricRegistry(),
          bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
      bootstrap.getObjectMapper(),
      bootstrap.getValidatorFactory().getValidator(),
      bootstrap.getMetricRegistry(),
      bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
    @Override
    public void lifeCycleStopped(LifeCycle event) {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config
 *  An application configuration instance (with properties set)
 * @param applicationClass
 *  The {@link io.dropwizard.Application} implementation class
 * @param <T>
 *  The configuration class
 * @return
 *  A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration>
DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception
{
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
          System.getProperty("java.io.tmpdir"),
          config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
          = bootstrap.getConfigurationFactoryFactory()
                     .create((Class<T>) config.getClass(),
                             bootstrap.getValidatorFactory().getValidator(),
                             bootstrap.getObjectMapper(),
                             "dw");
  final T builtConfig = configurationFactory.build(
          bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
             .configure(bootstrap.getMetricRegistry(),
                        bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                                                  bootstrap.getObjectMapper(),
                                                  bootstrap.getValidatorFactory().getValidator(),
                                                  bootstrap.getMetricRegistry(),
                                                  bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener()
  {
    @Override
    public void lifeCycleStopped(LifeCycle event)
    {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config
 *  An application configuration instance (with properties set)
 * @param applicationClass
 *  The {@link io.dropwizard.Application} implementation class
 * @param <T>
 *  The configuration class
 * @return
 *  A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration>
DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception
{
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
          System.getProperty("java.io.tmpdir"),
          config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
          = bootstrap.getConfigurationFactoryFactory()
                     .create((Class<T>) config.getClass(),
                             bootstrap.getValidatorFactory().getValidator(),
                             bootstrap.getObjectMapper(),
                             "dw");
  final T builtConfig = configurationFactory.build(
          bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
             .configure(bootstrap.getMetricRegistry(),
                        bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                                                  bootstrap.getObjectMapper(),
                                                  bootstrap.getValidatorFactory().getValidator(),
                                                  bootstrap.getMetricRegistry(),
                                                  bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener()
  {
    @Override
    public void lifeCycleStopped(LifeCycle event)
    {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
项目:Pinot    文件:DropWizardApplicationRunner.java   
/**
 * Creates a Jetty server for an application that can be started / stopped in-process
 *
 * @param config
 *  An application configuration instance (with properties set)
 * @param applicationClass
 *  The {@link io.dropwizard.Application} implementation class
 * @param <T>
 *  The configuration class
 * @return
 *  A Jetty server
 */
@SuppressWarnings("unchecked")
public static <T extends Configuration>
DropWizardServer<T> createServer(T config, Class<? extends Application<T>> applicationClass) throws Exception
{
  // Create application
  final Application<T> application = applicationClass.getConstructor().newInstance();

  // Create bootstrap
  final ServerCommand<T> serverCommand = new ServerCommand<T>(application);
  final Bootstrap<T> bootstrap = new Bootstrap<T>(application);
  bootstrap.addCommand(serverCommand);

  // Write a temporary config file
  File tmpConfigFile = new File(
          System.getProperty("java.io.tmpdir"),
          config.getClass().getCanonicalName() + "_" + System.currentTimeMillis());
  tmpConfigFile.deleteOnExit();
  bootstrap.getObjectMapper().writeValue(tmpConfigFile, config);

  // Parse configuration
  ConfigurationFactory<T> configurationFactory
          = bootstrap.getConfigurationFactoryFactory()
                     .create((Class<T>) config.getClass(),
                             bootstrap.getValidatorFactory().getValidator(),
                             bootstrap.getObjectMapper(),
                             "dw");
  final T builtConfig = configurationFactory.build(
          bootstrap.getConfigurationSourceProvider(), tmpConfigFile.getAbsolutePath());

  // Configure logging
  builtConfig.getLoggingFactory()
             .configure(bootstrap.getMetricRegistry(),
                        bootstrap.getApplication().getName());

  // Environment
  final Environment environment = new Environment(bootstrap.getApplication().getName(),
                                                  bootstrap.getObjectMapper(),
                                                  bootstrap.getValidatorFactory().getValidator(),
                                                  bootstrap.getMetricRegistry(),
                                                  bootstrap.getClassLoader());

  // Initialize environment
  builtConfig.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry());

  // Server
  final Server server = builtConfig.getServerFactory().build(environment);
  server.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener()
  {
    @Override
    public void lifeCycleStopped(LifeCycle event)
    {
      builtConfig.getLoggingFactory().stop();
    }
  });

  return new DropWizardServer(builtConfig, bootstrap, application, environment, server, environment.metrics());
}
项目:dropwizard-entitymanager    文件:AbstractIntegrationTest.java   
protected void setup(Class<? extends Application<TestConfiguration>> applicationClass) {
    dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath("integration-test.yaml"),
            ConfigOverride.config("dataSource.url", "jdbc:hsqldb:mem:DbTest" + System.nanoTime() + "?hsqldb.translate_dti_types=false"));
    dropwizardTestSupport.before();
}
项目:robe    文件:InitializeCommand.java   
public InitializeCommand(Application<T> service, String name, String description) {
    super(service, name, description);
}
项目:robe    文件:InitializeCommand.java   
public InitializeCommand(Application<T> service, RobeHibernateBundle hibernateBundle) {
    this(service, "initialize", "Runs Hibernate and initialize required columns", hibernateBundle);
}
项目:robe    文件:InitializeCommand.java   
public InitializeCommand(Application<T> service, String name, String description, RobeHibernateBundle hibernateBundle) {
    super(service, name, description);
    setHibernateBundle(hibernateBundle);
}
项目:dropwizard-guicey    文件:ItemInfoImpl.java   
@Override
public boolean isRegisteredDirectly() {
    return getRegisteredBy().contains(Application.class);
}
项目:dropwizard-guicey    文件:DiagnosticBundle.java   
private void report(final Application app) {
    final DiagnosticReporter reporter = new DiagnosticReporter();
    InjectorLookup.getInjector(app).get().injectMembers(reporter);
    reporter.report(statsConfig, optionsConfig, config, treeConfig);
}
项目:dropwizard-guicey    文件:ConfigurationContext.java   
private Class<?> getScope() {
    return currentScope == null ? Application.class : currentScope;
}
项目:dropwizard-guicey    文件:Jersey2Module.java   
public Jersey2Module(final Application application, final Environment environment,
                     final ConfigurationContext context) {
    this.application = application;
    this.environment = environment;
    this.context = context;
}