com.google.inject.spi.TypeListener Java Examples
The following examples show how to use
com.google.inject.spi.TypeListener.
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 |
@Override protected void configure() { final boolean newRegistry = lifecycleRegistry.compareAndSet(null, new LifecycleRegistry()); bind(LifecycleRegistry.class).toInstance(lifecycleRegistry.get()); if (newRegistry) { bind(LifecycleShutdownRegistration.class).asEagerSingleton(); } bindListener(Matchers.any(), new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) { executePostConstruct(encounter, type.getRawType(), lifecycleRegistry.get()); } }); }
Example #2
Source File: RuntimeModule.java From EDDI with Apache License 2.0 | 6 votes |
@Override protected void configure() { registerConfigFiles(this.configFiles); //init system runtime eagerly bind(SystemRuntime.IRuntime.class).to(BaseRuntime.class).asEagerSingleton(); bind(IResourceClientLibrary.class).to(ResourceClientLibrary.class).in(Scopes.SINGLETON); bind(IBotStoreClientLibrary.class).to(BotStoreClientLibrary.class).in(Scopes.SINGLETON); bind(IPackageStoreClientLibrary.class).to(PackageStoreClientLibrary.class).in(Scopes.SINGLETON); bind(IPackageStoreService.class).to(PackageStoreService.class).in(Scopes.SINGLETON); bind(IBotStoreService.class).to(BotStoreService.class).in(Scopes.SINGLETON); bind(IBotFactory.class).to(BotFactory.class).in(Scopes.SINGLETON); bind(IPackageFactory.class).to(PackageFactory.class).in(Scopes.SINGLETON); bind(IAutoBotDeployment.class).to(AutoBotDeployment.class).in(Scopes.SINGLETON); //call init method of system runtime after creation bindListener(HasInitMethod.INSTANCE, new TypeListener() { public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { encounter.register(InitInvoker.INSTANCE); } }); }
Example #3
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 #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: 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 #6
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 #7
Source File: FieldInjectModule.java From nano-framework with Apache License 2.0 | 5 votes |
@Override public void configure(final Binder binder) { binder.bindListener(Matchers.any(), new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) { final List<Field> fields = fields(Lists.newArrayList(), type.getRawType()); fields.stream().filter(field -> field.isAnnotationPresent(FieldInject.class)).forEach(field -> { final FieldInject inject = field.getAnnotation(FieldInject.class); encounter.register(ReflectUtils.newInstance(inject.value(), field)); }); } }); }
Example #8
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 #9
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 #10
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 #11
Source File: InjectionLogger.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configure() { final InjectionLogger listener = new InjectionLogger(logger); bindListener(Matchers.any(), (TypeListener) listener); bindListener(Matchers.any(), (ProvisionListener) listener); }