类com.google.inject.spi.TypeListener源码实例Demo

下面列出了怎么用com.google.inject.spi.TypeListener的API类实例代码及写法,或者点击链接到github查看源代码。

@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());
        }
    });
}
 
源代码2 项目: EDDI   文件: RuntimeModule.java
@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);
        }
    });
}
 
源代码3 项目: che   文件: DestroyModule.java
@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);
                  }
                }
              });
        }
      });
}
 
源代码4 项目: Orienteer   文件: OrienteerTestModule.java
@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);
}
 
源代码5 项目: digdag   文件: ServerLifeCycleModule.java
@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);
                        }
                    }
                }
            });
        }
    });
}
 
源代码6 项目: herald   文件: LogModule.java
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);
        }
    };
}
 
源代码7 项目: nano-framework   文件: FieldInjectModule.java
@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));
            });
        }
    });
}
 
源代码8 项目: PeerWasp   文件: AppModule.java
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);
                }
            });
        }
    });
}
 
源代码9 项目: staash   文件: PaasModule.java
@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);
    
}
 
源代码10 项目: Scribengin   文件: MycilaJmxModuleExt.java
@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);
        }
      });
    }
  });
}
 
源代码11 项目: ProjectAres   文件: InjectionLogger.java
@Override
protected void configure() {
    final InjectionLogger listener = new InjectionLogger(logger);
    bindListener(Matchers.any(), (TypeListener) listener);
    bindListener(Matchers.any(), (ProvisionListener) listener);
}
 
 类所在包
 同包方法