com.google.inject.spi.InjectionListener Java Examples
The following examples show how to use
com.google.inject.spi.InjectionListener.
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: LifecycleModule.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
private <I> void invokePostConstruct(final TypeEncounter<I> encounter, final Method postConstruct) { encounter.register(new InjectionListener<I>() { @Override public void afterInjection(final I injectee) { try { postConstruct.setAccessible(true); postConstruct.invoke(injectee); } catch (final IllegalAccessException | InvocationTargetException e) { if (e.getCause() instanceof UnrecoverableException) { if (((UnrecoverableException) e.getCause()).isShowException()) { log.error("An unrecoverable Exception occurred. Exiting HiveMQ", e); } System.exit(1); } throw new ProvisionException("An error occurred while calling @PostConstruct", e); } } }); }
Example #2
Source File: DestroyModule.java From che with Eclipse Public License 2.0 | 6 votes |
@Override protected void configure() { final Destroyer destroyer = new Destroyer(errorHandler); bind(Destroyer.class).toInstance(destroyer); bindListener( Matchers.any(), new TypeListener() { @Override public <T> void hear(TypeLiteral<T> type, TypeEncounter<T> encounter) { encounter.register( new InjectionListener<T>() { @Override public void afterInjection(T injectee) { final Method[] methods = get(injectee.getClass(), annotationType); if (methods.length > 0) { // copy array when pass it outside final Method[] copy = new Method[methods.length]; System.arraycopy(methods, 0, copy, 0, methods.length); destroyer.add(injectee, copy); } } }); } }); }
Example #3
Source File: LifeCycleStageModule.java From james-project with Apache License 2.0 | 6 votes |
private <A extends Annotation> void bind(BindingBuilder<A> binding) { final Stager<A> stager = binding.stager; final StageableTypeMapper typeMapper = binding.typeMapper; bind(type(stager.getStage())).toInstance(stager); bindListener(binding.typeMatcher, new AbstractMethodTypeListener(asList(stager.getStage())) { @Override protected <I> void hear(final Method stageMethod, final TypeLiteral<I> parentType, final TypeEncounter<I> encounter, final Class<? extends Annotation> annotationType) { encounter.register((InjectionListener<I>) injectee -> { Stageable stageable = new StageableMethod(stageMethod, injectee); stager.register(stageable); typeMapper.registerType(stageable, parentType); }); } }); }
Example #4
Source File: OrienteerTestModule.java From Orienteer with Apache License 2.0 | 6 votes |
@Override protected void configure() { bind(Boolean.class).annotatedWith(Names.named("testing")).toInstance(true); bindListener(InstanceOfMatcher.createFor(WebApplication.class), new TypeListener() { @Override public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) { final Provider<Injector> injectorProvider = encounter.getProvider(Injector.class); encounter.register((InjectionListener<Object>) injected -> { WebApplication app = (WebApplication) injected; app.getComponentInstantiationListeners().add(new GuiceComponentInjector(app, injectorProvider.get())); }); } }); bind(OrienteerTester.class).asEagerSingleton(); Provider<OrienteerTester> provider = binder().getProvider(OrienteerTester.class); bind(WicketTester.class).toProvider(provider); bind(WicketOrientDbTester.class).toProvider(provider); }
Example #5
Source File: LifecycleModule.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
private <I> void addPreDestroyToRegistry(final TypeEncounter<I> encounter, final Method preDestroy, final LifecycleRegistry registry) { encounter.register(new InjectionListener<I>() { @Override public void afterInjection(final I injectee) { registry.addPreDestroyMethod(preDestroy, injectee); } }); }
Example #6
Source File: InjectionLogger.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { logger.info("Encountered type " + type); encounter.register((InjectionListener<I>) injectee -> { logger.info("Injected " + injectee); }); }
Example #7
Source File: ServerLifeCycleModule.java From digdag with Apache License 2.0 | 5 votes |
@Override public void configure(Binder binder) { binder.disableCircularProxies(); binder.bindListener(Matchers.any(), new TypeListener() { @Override public <T> void hear(TypeLiteral<T> type, TypeEncounter<T> encounter) { encounter.register(new InjectionListener<T>() { @Override public void afterInjection(T obj) { ServerLifeCycleManager initialized = lifeCycleManagerRef.get(); if (initialized == null) { earlyInjected.add(obj); } else { try { initialized.manageInstance(obj); } catch (Exception e) { // really nothing we can do here throw new Error(e); } } } }); } }); }
Example #8
Source File: LogModule.java From herald with Apache License 2.0 | 5 votes |
private TypeListener createTypeListener() { return new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> typeLiteral, final TypeEncounter<I> typeEncounter) { typeEncounter.register((InjectionListener<I>) LoggerInjector::inject); } }; }
Example #9
Source File: AppModule.java From PeerWasp with MIT License | 5 votes |
private void messageBusRegisterRule() { // This rule registers all objects created by Guice with the message bus. // As a result, all instances created by Guice can receive messages without explicit // subscription. bindListener(Matchers.any(), new TypeListener() { @Override public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { typeEncounter.register(new InjectionListener<I>() { public void afterInjection(I i) { messageBus.subscribe(i); } }); } }); }
Example #10
Source File: PaasModule.java From staash with Apache License 2.0 | 5 votes |
@Override protected void configure() { LOG.info("Loading PaasModule"); bind(EventBus.class).toInstance(eventBus); bindListener(Matchers.any(), new TypeListener() { public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { typeEncounter.register(new InjectionListener<I>() { public void afterInjection(I i) { eventBus.register(i); } }); } }); bind(TaskManager.class).to(InlineTaskManager.class); // Constants bind(String.class).annotatedWith(Names.named("namespace")).toInstance("com.netflix.pass."); bind(String.class).annotatedWith(Names.named("appname" )).toInstance("paas"); bind(AbstractConfiguration.class).toInstance(ConfigurationManager.getConfigInstance()); // Configuration bind(PaasConfiguration.class).to(ArchaeusPaasConfiguration.class).in(Scopes.SINGLETON); // Stuff bind(ScheduledExecutorService.class).annotatedWith(Names.named("tasks")).toInstance(Executors.newScheduledThreadPool(10)); bind(DaoProvider.class).in(Scopes.SINGLETON); // Rest resources bind(DataResource.class).in(Scopes.SINGLETON); bind(SchemaAdminResource.class).to(JerseySchemaAdminResourceImpl.class).in(Scopes.SINGLETON); bind(SchemaService.class).to(DaoSchemaService.class).in(Scopes.SINGLETON); }
Example #11
Source File: MycilaJmxModuleExt.java From Scribengin with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void configure() { bindListener(ClassToTypeLiteralMatcherAdapter.adapt(Matchers.annotatedWith(JmxBean.class)), new TypeListener() { @Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { final Provider<JmxExporter> exporter = encounter.getProvider(JmxExporter.class); encounter.register(new InjectionListener<I>() { @Override public void afterInjection(I injectee) { exporter.get().register(injectee); } }); } }); }
Example #12
Source File: StartablesModule.java From james-project with Apache License 2.0 | 4 votes |
private <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { InjectionListener<? super I> injectionListener = ignored -> startables.add(type.getRawType().asSubclass(Startable.class)); encounter.register(injectionListener); }