本文整理汇总了Java中com.google.inject.Stage类的典型用法代码示例。如果您正苦于以下问题:Java Stage类的具体用法?Java Stage怎么用?Java Stage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Stage类属于com.google.inject包,在下文中一共展示了Stage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import com.google.inject.Stage; //导入依赖的package包/类
@Override
protected void configure() {
// @InjectorScoped annotation
install(new InjectorScopeModule());
// Provide a global, catch-all exception handler
bind(LoggingExceptionHandler.class).in(Singleton.class);
bind(ExceptionHandler.class).to(LoggingExceptionHandler.class);
bind(new TypeLiteral<ExceptionHandler<Throwable>>(){}).to(LoggingExceptionHandler.class);
bind(Thread.UncaughtExceptionHandler.class).to(LoggingExceptionHandler.class);
// Evil decorator thing
// Create it manually so we can use it before the injector is ready
bind(DecoratorFactory.class).toInstance(DecoratorFactory.get());
install(new NumberFactory.Manifest());
install(new ParsersManifest());
requestStaticInjection(SystemFutureCallback.class);
if(currentStage() == Stage.DEVELOPMENT) {
// This is useful, but it makes the LeakDetector unhappy
//install(new RepeatInjectionDetector());
}
}
示例2: getGuiceStage
import com.google.inject.Stage; //导入依赖的package包/类
public Stage getGuiceStage(){
String stageString = System.getProperty(PROPERTY_NAME);
final Stage stage;
boolean development = Stage.DEVELOPMENT.name().equals(stageString);
boolean production = Stage.PRODUCTION.name().equals(stageString);
if(development || production){
stage = development ? Stage.DEVELOPMENT : Stage.PRODUCTION;
logger.warn("using Guice Stage {} from JVM arg -D{}={}", stage, PROPERTY_NAME, stageString);
}else if(stageString != null){
stage = Stage.PRODUCTION;
logger.warn("unrecognized JVM arg value -D{}={}, using Guice Stage {}", PROPERTY_NAME, stageString,
Stage.PRODUCTION);
}else{
stage = Stage.PRODUCTION;
logger.warn("using default Guice Stage={}", Stage.PRODUCTION);
}
return stage;
}
示例3: initialize
import com.google.inject.Stage; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<ServerConfiguration> bootstrap) {
bootstrap.addBundle(hibernateBundle);
bootstrap.addBundle(new AssetsBundle("/swagger-spec", "/api-spec", null));
bootstrap.addBundle(GuiceBundle.<ServerConfiguration>newBuilder()
.addModule(new AbstractModule(){
@Override protected void configure() {}
@Provides SessionFactory sessionFactoryProvider() { return hibernateBundle.getSessionFactory();}
})
.setConfigClass(ServerConfiguration.class)
.enableAutoConfig(getClass().getPackage().getName())
.build(Stage.DEVELOPMENT)
);
bootstrap.addBundle(new Java8Bundle());
// Enable variable substitution with environment variables
bootstrap.setConfigurationSourceProvider(
new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
new EnvironmentVariableSubstitutor(false)
)
);
}
示例4: main
import com.google.inject.Stage; //导入依赖的package包/类
public static void main(String... args) {
final long start = System.currentTimeMillis();
try {
final Injector injector = Guice.createInjector(Stage.PRODUCTION, new SingularityRunnerBaseModule(SingularityExecutorCleanupConfiguration.class, ImmutableSet.of(SingularityS3Configuration.class, SingularityExecutorConfiguration.class)), new SingularityExecutorModule(), new SingularityExecutorCleanupModule(), new SingularityClientModule(), new SingularityMesosClientModule());
final SingularityExecutorCleanupRunner runner = injector.getInstance(SingularityExecutorCleanupRunner.class);
LOG.info("Starting cleanup");
final SingularityExecutorCleanupStatistics statistics = runner.cleanup();
LOG.info("Finished with {} after {}", statistics, JavaUtils.duration(start));
System.exit(0);
} catch (Throwable t) {
LOG.error("Finished after {} with error", JavaUtils.duration(start), t);
System.exit(1);
}
}
示例5: main
import com.google.inject.Stage; //导入依赖的package包/类
public static void main(String... args) {
final long start = System.currentTimeMillis();
try {
final Injector injector = Guice.createInjector(Stage.PRODUCTION, new SingularityRunnerBaseModule(SingularityExecutorConfiguration.class, ImmutableSet.<Class<? extends BaseRunnerConfiguration>>of(SingularityS3Configuration.class)), new SingularityExecutorModule());
final SingularityExecutorRunner executorRunner = injector.getInstance(SingularityExecutorRunner.class);
final Protos.Status driverStatus = executorRunner.run();
LOG.info("Executor finished after {} with status: {}", JavaUtils.duration(start), driverStatus);
System.exit(driverStatus == Protos.Status.DRIVER_STOPPED ? 0 : 1);
} catch (Throwable t) {
LOG.error("Finished after {} with error", JavaUtils.duration(start), t);
System.exit(1);
}
}
示例6: initialize
import com.google.inject.Stage; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<ProductCatalogConfiguration> bootstrap) {
bootstrap.addBundle(discoveryBundle);
bootstrap.addBundle(new MigrationsBundle<ProductCatalogConfiguration>() {
@Override
public PooledDataSourceFactory getDataSourceFactory(ProductCatalogConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
guiceBundle = GuiceBundle.<ProductCatalogConfiguration> newBuilder().addModule(new ProductCatalogModule())
.enableAutoConfig(getClass().getPackage().getName()).setConfigClass(ProductCatalogConfiguration.class)
.build(Stage.PRODUCTION);
bootstrap.addBundle(guiceBundle);
// Uncomment below to read the yaml file from Jar
// bootstrap.setConfigurationSourceProvider(new
// ResourceConfigurationSourceProvider());
}
示例7: initialize
import com.google.inject.Stage; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<ProductReviewConfiguration> bootstrap) {
bootstrap.addBundle(discoveryBundle);
bootstrap.addBundle(new MigrationsBundle<ProductReviewConfiguration>() {
@Override
public PooledDataSourceFactory getDataSourceFactory(ProductReviewConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
guiceBundle = GuiceBundle.<ProductReviewConfiguration> newBuilder().addModule(new ProductReviewModule())
.enableAutoConfig(getClass().getPackage().getName()).setConfigClass(ProductReviewConfiguration.class)
.build(Stage.PRODUCTION);
bootstrap.addBundle(guiceBundle);
// Uncomment below to read the yaml file from Jar
// bootstrap.setConfigurationSourceProvider(new
// ResourceConfigurationSourceProvider());
}
示例8: Client
import com.google.inject.Stage; //导入依赖的package包/类
public Client(@NonNull Path filePath, @NonNull Config config, boolean cleanRun, @NonNull List<?> listeners) {
this.filePath = checkFile(filePath);
this.cleanRun = cleanRun;
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new ConfigurationModule(ConfigValidator.checkValid(config.withFallback(ConfigFactory.load()))),
new JpaRepositoryModule(),
new ServiceModule()
);
persistService = injector.getInstance(PersistService.class);
persistService.start();
handlerType = injector.getInstance(MovieHandler.Type.class);
handlerChain = injector.getInstance(MovieHandler.class);
importProgressService = injector.getInstance(ImportProgressService.class);
eventBus = new EventBus();
listeners.forEach(eventBus::register);
}
示例9: getInjector
import com.google.inject.Stage; //导入依赖的package包/类
@Override
protected Injector getInjector() {
// Create injector
Injector injector = Guice.createInjector(Stage.PRODUCTION,
new EnvironmentModule(environment),
new LogModule(environment),
new ExtensionModule(environment),
new RESTServiceModule(sessionMap),
new TunnelModule()
);
// Inject any annotated members of this class
injector.injectMembers(this);
return injector;
}
示例10: initialize
import com.google.inject.Stage; //导入依赖的package包/类
protected void initialize()
{
EuropaConfiguration europaConfiguration = null;
if(_configFilePath != null)
europaConfiguration = EuropaConfiguration.fromFile(new File(_configFilePath));
else
europaConfiguration = EuropaConfiguration.fromEnvironment();
europaConfiguration.setStage(_stage);
Injector injector = Guice.createInjector(Stage.PRODUCTION,
new PersistenceModule(),
new AjaxHelperModule(),
new ObjectStoreModule(),
new EuropaInjectorModule(europaConfiguration));
injector.injectMembers(this);
initializeWebServer(injector);
}
示例11: addStageCreationRule
import com.google.inject.Stage; //导入依赖的package包/类
private void addStageCreationRule() {
// stage rule
config.creationPipeline.creationRules.add(new CreationRule() {
@Override
public Optional<Function<RecipeCreationContext, SupplierRecipe>> apply(
CoreDependencyKey<?> key, CoreInjector injector) {
if (Stage.class.equals(key.getType().getType()))
return Optional.of(ctx -> new SupplierRecipeImpl(
() -> guiceConfig.stage));
else
return Optional.empty();
}
});
}
示例12: testImmediateStarts
import com.google.inject.Stage; //导入依赖的package包/类
@Test
public void testImmediateStarts()
throws Exception
{
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new LifeCycleModule(),
new Module()
{
@Override
public void configure(Binder binder)
{
binder.bind(InstanceThatRequiresStart.class).in(Scopes.SINGLETON);
binder.bind(InstanceThatUsesInstanceThatRequiresStart.class).in(Scopes.SINGLETON);
}
});
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
lifeCycleManager.start();
Assert.assertEquals(stateLog, ImmutableList.of("InstanceThatUsesInstanceThatRequiresStart:OK"));
}
示例13: testSubClassAnnotated
import com.google.inject.Stage; //导入依赖的package包/类
@Test
public void testSubClassAnnotated()
throws Exception
{
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new LifeCycleModule(),
new Module()
{
@Override
public void configure(Binder binder)
{
binder.bind(SimpleBase.class).to(SimpleBaseImpl.class).in(Scopes.SINGLETON);
}
});
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
lifeCycleManager.start();
Assert.assertEquals(stateLog, ImmutableList.of("postSimpleBaseImpl"));
lifeCycleManager.destroy();
Assert.assertEquals(stateLog, ImmutableList.of("postSimpleBaseImpl", "preSimpleBaseImpl"));
}
示例14: testIllegalMethods
import com.google.inject.Stage; //导入依赖的package包/类
@Test
public void testIllegalMethods()
throws Exception
{
try {
Guice.createInjector(
Stage.PRODUCTION,
new Module()
{
@Override
public void configure(Binder binder)
{
binder.bind(IllegalInstance.class).in(Scopes.SINGLETON);
}
},
new LifeCycleModule());
Assert.fail();
}
catch (CreationException dummy) {
// correct behavior
}
}
示例15: testDuplicateMethodNames
import com.google.inject.Stage; //导入依赖的package包/类
@Test
public void testDuplicateMethodNames()
throws Exception
{
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new Module()
{
@Override
public void configure(Binder binder)
{
binder.bind(FooTestInstance.class).in(Scopes.SINGLETON);
}
},
new LifeCycleModule()
);
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
lifeCycleManager.start();
lifeCycleManager.destroy();
Assert.assertEquals(stateLog, ImmutableList.of("foo"));
}