Java 类com.google.inject.spi.InjectionListener 实例源码

项目: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);
                  }
                }
              });
        }
      });
}
项目:agon    文件:AgonModule.java   
@Override
protected void configure() {
    bind(ActionRepository.class).to(CassandraActionRepository.class);
    bind(PlayerRepository.class).to(CassandraPlayerRepository.class);
    bind(BadgeRepository.class).to(CassandraBadgeRepository.class);
    bind(EventRepository.class).to(CassandraEventRepository.class);
    bind(EventTypeRepository.class).to(CassandraEventTypeRepository.class);

    this.eventBus =  new AsyncEventBus(java.util.concurrent.Executors.newCachedThreadPool());
    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);
                }
            });
        }
    });
}
项目:guice    文件:MembersInjectorImpl.java   
void notifyListeners(T instance) throws InternalProvisionException {
  ImmutableList<InjectionListener<? super T>> localInjectionListeners = injectionListeners;
  if (localInjectionListeners == null) {
    // no listeners
    return;
  }
  // optimization: use manual for/each to save allocating an iterator here
  for (int i = 0; i < localInjectionListeners.size(); i++) {
    InjectionListener<? super T> injectionListener = localInjectionListeners.get(i);
    try {
      injectionListener.afterInjection(instance);
    } catch (RuntimeException e) {
      throw InternalProvisionException.errorNotifyingInjectionListener(
          injectionListener, typeLiteral, e);
    }
  }
}
项目:guice-ext-annotations    文件:GeneralTypeListener.java   
@Override
@SuppressWarnings("unchecked")
public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
    final Class<? super I> actualType = type.getRawType();
    if (!Utils.isPackageValid(actualType)) {
        return;
    }
    if (typeClass.isAssignableFrom(actualType)) {
        encounter.register(new InjectionListener<I>() {
            @Override
            public void afterInjection(final I injectee) {
                try {
                    postProcessor.process((T) injectee);
                } catch (Exception ex) {
                    throw new IllegalStateException(
                            String.format("Failed to process type %s of class %s",
                                    typeClass.getSimpleName(), injectee.getClass().getSimpleName()), ex);
                }
            }
        });
    }
}
项目:yar    文件:InitializableTypeListener.java   
@Override
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
    if (Initializable.class.isAssignableFrom(type.getRawType())) {
        encounter.register(new InjectionListener<I>() {
            @Override
            public void afterInjection(I injectee) {
                if (injectee instanceof Initializable) {
                    Initializable initializable = (Initializable) injectee;
                    initializable.init();
                }
            }
        });
    } else {
        encounter.addError("Unsupported type: %s", type);
    }
}
项目:simplejavayoutubeuploader    文件:UploaderModule.java   
private void mapUtil() {
    final EventBus eventBus = new EventBus();
    bind(EventBus.class).toInstance(eventBus);
    bindListener(Matchers.any(), new TypeListener() {
        @Override
        public <I> void hear(@SuppressWarnings("unused") final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
            encounter.register(new InjectionListener<I>() {
                @Override
                public void afterInjection(final I injectee) {
                    eventBus.register(injectee);
                }
            });
        }
    });

    requestStaticInjection(TextUtil.class);
}
项目:jalphanode    文件:InjectorModule.java   
protected void bindMBeanListener() {
    final MBeanAnnotationScanner scanner = new MBeanAnnotationScanner();
    this.bindListener(Matchers.any(), new TypeListener() {

            @Override
            public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
                final MBeanMetadata metadata = scanner.scan(type.getRawType());

                if (metadata != null) {
                    encounter.register((InjectionListener<I>) injectee -> {
                        try {
                            final ResourceDynamicMBean dynamicMBean = new ResourceDynamicMBean(injectee,
                                    metadata);

                            mBeanRegistry.register(dynamicMBean, metadata.getObjectName());
                        } catch (Exception e) {
                            LOG.error("Could not register MBean {}", metadata.getObjectName(), e);
                        }
                    });
                }
            }
        });
}
项目:Ka-Websocket    文件:InjectionListenerRegister.java   
/**
 * Invokes all registered InjectionListeners.
 * 
 * @param injectee  The object that has been injected.
 */
@Override
public void afterInjection(Object injectee) {

   for (InjectionListener<Object> listener : listeners) {
       // Only invoke singletons once, if oncePerSingleton is true
       if (oncePerSingleton && injectee.getClass().isAnnotationPresent(Singleton.class)) {
           if (vistedClasses.contains(injectee.getClass())) {          
              continue;
           } else {
               vistedClasses.add(injectee.getClass());
           }

       }
       listener.afterInjection(injectee);

   }

}
项目:ProjectAres    文件:InjectionLogger.java   
@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);
    });
}
项目:Lagerta    文件:PostCreationListener.java   
@Override public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
    encounter.register(new InjectionListener<I>() {
        @Override public void afterInjection(I injectee) {
            if (!(injectee instanceof Ignite)) {
                Injection.postCreate(injectee, ignite);
                extractLifecycle(injectee, lifecycleBeans);
            }
        }
    });
}
项目:guice-bootstrap    文件:LifeCycleModule.java   
@Override
public void configure(Binder binder)
{
    binder.disableCircularProxies();

    binder.bindListener(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)
                {
                    if (isLifeCycleClass(obj.getClass())) {
                        LifeCycleManager lifeCycleManager = lifeCycleManagerRef.get();
                        if (lifeCycleManager != null) {
                            try {
                                lifeCycleManager.addInstance(obj);
                            }
                            catch (Exception e) {
                                throw new Error(e);
                            }
                        }
                        else {
                            injectedInstances.add(obj);
                        }
                    }
                }
            });
        }
    });
}
项目:r01fb    文件:BeanImplementedPersistenceServicesCoreBootstrapGuiceModuleBase.java   
@Override
public <I> void hear(final TypeLiteral<I> type,
                     final TypeEncounter<I> encounter) {
    encounter.register(// AFTER the type is injected it MUST be registered at the EventBus
                       new InjectionListener<I>() {
                                @Override
                                public void afterInjection(final I injecteeEventListener) {
                                    log.warn("\tRegistering {} event listener at event bus {}",
                                             injecteeEventListener.getClass(),
                                             _eventBusProvider.get());
                                    _eventBusProvider.get()
                                                     .register(injecteeEventListener);  // register the indexer (the indexer is an event listener)
                                }
                       });
}
项目: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);
                        }
                    }
                }
            });
        }
    });
}
项目: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);
        }
    };
}
项目:houdini    文件:ObjectConverterModule.java   
private TypeListener createTypeListener(final ObjectConverterRegistry registry) {
    return new TypeListener() {
        @Override
        public <I> void hear(final TypeLiteral<I> typeLiteral, final TypeEncounter<I> typeEncounter) {
            typeEncounter.register(new InjectionListener<I>() {
                @Override
                public void afterInjection(final I injectee) {
                    registry.registerConverters(injectee);
                }
            });
        }
    };
}
项目:gae-jersey-guice-jsf    文件:PostConstructTypeListener.java   
@Override
public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter)
{
    Class<? super I> clz = typeLiteral.getRawType();
    if (packagePrefix != null && !clz.getName().startsWith(packagePrefix))
        return;

    final Method method = getPostConstructMethod(clz);
    if (method != null)
    {
        typeEncounter.register(new InjectionListener<I>()
        {
            @Override
            public void afterInjection(Object i)
            {
                try
                {
                    // call the @PostConstruct annotated method after all dependencies have been injected
                    method.invoke(i);
                }
                catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
                {
                    throw new RuntimeException(e);
                }
            }
        });
    }
}
项目:guice    文件:EncounterImpl.java   
@Override
public void register(InjectionListener<? super T> injectionListener) {
  checkState(valid, "Encounters may not be used after hear() returns.");

  if (injectionListeners == null) {
    injectionListeners = Lists.newArrayList();
  }

  injectionListeners.add(injectionListener);
}
项目:guice    文件:TypeListenerTest.java   
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
  ++count;

  MembersInjector membersInjector = new CountingMembersInjector();
  encounter.register(membersInjector);
  encounter.register(membersInjector);

  InjectionListener injectionListener = new CountingInjectionListener();
  encounter.register(injectionListener);
  encounter.register(injectionListener);
}
项目: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);
                }
            });
        }
    });
}
项目:ddp-client-java    文件:SampleApplicationModule.java   
@Override
protected void configure() {
    bind(SampleApplication.class);

    bind(MessageConverter.class).to(JsonMessageConverter.class).in(Singleton.class);
    bind(ObjectConverter.class).to(JsonObjectConverter.class).in(Singleton.class);
    bind(SubscriptionAdapter.class).to(MapSubscriptionAdapter.class).in(Singleton.class);
    bind(DDPMessageEndpoint.class).to(DDPMessageEndpointImpl.class).in(Singleton.class);
    bind(SubscriptionEventDispatcher.class).asEagerSingleton();
    bind(MeteorCollectionRepository.class).to(MeteorCollectionRepositoryImpl.class).in(Singleton.class);
    bind(RPCClient.class).to(RPCClientImpl.class).in(Singleton.class);
    bind(EventBus.class).in(Singleton.class);

    bindListener(
            new AbstractMatcher<TypeLiteral<?>>() {
                @Override
                public boolean matches(TypeLiteral<?> typeLiteral) {
                    return typeLiteral.getRawType().isAnnotationPresent(Presents.class);
                }
            },
            new TypeListener() {
                @Override
                public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
                    final Presents presents = type.getRawType().getAnnotation(Presents.class);
                    encounter.register((InjectionListener<I>) injectee -> {
                        final FXMLLoader loader = new FXMLLoader(injectee.getClass().getResource(presents.value()));
                        loader.setController(injectee);
                        try {
                            loader.load();
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    });
                }
            }
    );
}
项目:guice-old    文件:EncounterImpl.java   
public void register(InjectionListener<? super T> injectionListener) {
  checkState(valid, "Encounters may not be used after hear() returns.");

  if (injectionListeners == null) {
    injectionListeners = Lists.newArrayList();
  }

  injectionListeners.add(injectionListener);
}
项目:guice-old    文件:MembersInjectorImpl.java   
void notifyListeners(T instance, Errors errors) throws ErrorsException {
  int numErrorsBefore = errors.size();
  for (InjectionListener<? super T> injectionListener : injectionListeners) {
    try {
      injectionListener.afterInjection(instance);
    } catch (RuntimeException e) {
      errors.errorNotifyingInjectionListener(injectionListener, typeLiteral, e);
    }
  }
  errors.throwIfNewErrors(numErrorsBefore);
}
项目:guice-old    文件:TypeListenerTest.java   
public void testInstallingInjectionListener() {
  final List<Object> injectees = Lists.newArrayList();
  final InjectionListener<Object> injectionListener = new InjectionListener<Object>() {
    public void afterInjection(Object injectee) {
      injectees.add(injectee);
    }
  };

  Injector injector = Guice.createInjector(new AbstractModule() {
    @Override protected void configure() {
      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          encounter.register(injectionListener);
        }
      });
      bind(A.class);
    }
  });

  assertEquals(ImmutableList.of(), injectees);

  Object a1 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1), injectees);

  Object a2 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1, a2), injectees);

  Object b1 = injector.getInstance(B.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);

  Provider<A> aProvider = injector.getProvider(A.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);
  A a3 = aProvider.get();
  A a4 = aProvider.get();
  assertEquals(ImmutableList.of(a1, a2, b1, a3, a4), injectees);
}
项目:guice-old    文件:TypeListenerTest.java   
@SuppressWarnings({"rawtypes", "unchecked"})
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
  ++count;

  MembersInjector membersInjector = new CountingMembersInjector();
  encounter.register(membersInjector);
  encounter.register(membersInjector);

  InjectionListener injectionListener = new CountingInjectionListener();
  encounter.register(injectionListener);
  encounter.register(injectionListener);
}
项目:guice-ext-annotations    文件:AnnotatedFieldTypeListener.java   
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
    final Class<? super I> actualType = type.getRawType();
    if (!Utils.isPackageValid(actualType)) {
        return;
    }
    Class<? super I> investigatingType = actualType;
    while (investigatingType != null && !investigatingType.equals(Object.class)) {
        for (final Field field : investigatingType.getDeclaredFields()) {
            if (field.isAnnotationPresent(annotationClass)) {
                encounter.register(new InjectionListener<I>() {
                    @Override
                    public void afterInjection(final I injectee) {
                        try {
                            field.setAccessible(true);
                            postProcessor.process(field.getAnnotation(annotationClass), field, injectee);
                        } catch (Exception ex) {
                            throw new IllegalStateException(
                                    String.format("Failed to process annotation %s on field %s of class %s",
                                            annotationClass.getSimpleName(), field.getName(),
                                            injectee.getClass().getSimpleName()), ex);
                        }
                    }
                });
            }
        }
        investigatingType = investigatingType.getSuperclass();
    }
}
项目:guice-ext-annotations    文件:AnnotatedMethodTypeListener.java   
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) {
    final Class<? super I> actualType = type.getRawType();
    if (!Utils.isPackageValid(actualType)) {
        return;
    }
    Class<? super I> investigatingType = actualType;
    while (investigatingType != null && !investigatingType.equals(Object.class)) {
        for (final Method method : investigatingType.getDeclaredMethods()) {
            if (method.isAnnotationPresent(annotationClass)) {
                encounter.register(new InjectionListener<I>() {
                    @Override
                    public void afterInjection(final I injectee) {
                        try {
                            method.setAccessible(true);
                            postProcessor.process(method.getAnnotation(annotationClass), method, injectee);
                        } catch (Exception ex) {
                            throw new IllegalStateException(
                                    String.format("Failed to process annotation %s on method %s of class %s",
                                            annotationClass.getSimpleName(), method.getName(),
                                            injectee.getClass().getSimpleName()), ex);
                        }
                    }
                });
            }
        }
        investigatingType = investigatingType.getSuperclass();
    }
}
项目:google-guice    文件:EncounterImpl.java   
public void register(InjectionListener<? super T> injectionListener) {
  checkState(valid, "Encounters may not be used after hear() returns.");

  if (injectionListeners == null) {
    injectionListeners = Lists.newArrayList();
  }

  injectionListeners.add(injectionListener);
}
项目:google-guice    文件:MembersInjectorImpl.java   
void notifyListeners(T instance, Errors errors) throws ErrorsException {
  int numErrorsBefore = errors.size();
  for (InjectionListener<? super T> injectionListener : injectionListeners) {
    try {
      injectionListener.afterInjection(instance);
    } catch (RuntimeException e) {
      errors.errorNotifyingInjectionListener(injectionListener, typeLiteral, e);
    }
  }
  errors.throwIfNewErrors(numErrorsBefore);
}
项目:google-guice    文件:TypeListenerTest.java   
public void testInstallingInjectionListener() {
  final List<Object> injectees = Lists.newArrayList();
  final InjectionListener<Object> injectionListener = new InjectionListener<Object>() {
    public void afterInjection(Object injectee) {
      injectees.add(injectee);
    }
  };

  Injector injector = Guice.createInjector(new AbstractModule() {
    protected void configure() {
      bindListener(onlyAbcd, new TypeListener() {
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
          encounter.register(injectionListener);
        }
      });
      bind(A.class);
    }
  });

  assertEquals(ImmutableList.of(), injectees);

  Object a1 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1), injectees);

  Object a2 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1, a2), injectees);

  Object b1 = injector.getInstance(B.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);

  Provider<A> aProvider = injector.getProvider(A.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);
  A a3 = aProvider.get();
  A a4 = aProvider.get();
  assertEquals(ImmutableList.of(a1, a2, b1, a3, a4), injectees);
}
项目: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);

}
项目: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);
        }
      });
    }
  });
}
项目:mynlp    文件:MyNlps.java   
private static Injector createInject() {

        Settings settings = Settings.build();

        Environment environment = new Environment(settings);


        ArrayList<Module> modules = Lists.newArrayList();

        modules.add(new AbstractModule() {
            @Override
            protected void configure() {

                bind(Settings.class).toInstance(settings);
                bind(Environment.class).toInstance(environment);
                bind(MynlpResourceFactory.class).toInstance(environment.getMynlpResourceFactory());

                //process initialize interface
                bindListener(new AbstractMatcher<TypeLiteral<?>>() {
                    @Override
                    public boolean matches(TypeLiteral<?> t) {
                        return InitInterface.class.isAssignableFrom(t.getRawType());
                    }
                }, new TypeListener() {
                    @SuppressWarnings({"unchecked", "rawtypes"})
                    @Override
                    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
                        encounter.register((InjectionListener) injectee -> {
                            InitInterface initInterface = (InitInterface) injectee;
                            try {
                                initInterface.init();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        });
                    }
                });

            }
        });


        //加载模块,在配置文件中声明的
        modules.addAll(loadModules(environment));

        Injector injector = Guice.createInjector(modules);

        return injector;
    }
项目:GRIP    文件:GripUiModule.java   
@Override
protected void configure() {
  bind(GripMode.class).toInstance(GripMode.GUI);

  bindListener(Matchers.any(), new TypeListener() {
    @Override
    public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
      typeEncounter.register((InjectionListener<I>) i -> {
        if (!i.getClass().isAnnotationPresent(ParametrizedController.class)) {
          return;
        }
        try {
          FXMLLoader.load(i.getClass().getResource(
              i.getClass().getAnnotation(ParametrizedController.class).url()),
              null, null,
              c -> i
          );
        } catch (IOException e) {
          throw new IllegalStateException("Failed to load FXML", e);
        }
      });
    }
  });


  install(new FactoryModuleBuilder()
      .implement(StepController.class, StepController.class)
      .build(StepController.Factory.class));

  // Source Factories
  install(new FactoryModuleBuilder().build(new TypeLiteral<SourceController
      .BaseSourceControllerFactory<Source>>() {
  }));
  install(new FactoryModuleBuilder().build(MultiImageFileSourceController.Factory.class));
  install(new FactoryModuleBuilder().build(CameraSourceController.Factory.class));
  install(new FactoryModuleBuilder().build(HttpSourceController.Factory.class));
  install(new FactoryModuleBuilder().build(ClassifierSourceController.Factory.class));
  install(new FactoryModuleBuilder().build(VideoFileSourceController.Factory.class));
  // END Source Factories

  // Components
  install(new FactoryModuleBuilder().build(StartStoppableButton.Factory.class));
  install(new FactoryModuleBuilder().build(ExceptionWitnessResponderButton.Factory.class));
  // End Components

  // Controllers
  install(new FactoryModuleBuilder().build(OperationController.Factory.class));
  install(new FactoryModuleBuilder().build(SocketHandleView.Factory.class));
  install(new FactoryModuleBuilder().build(OutputSocketController.Factory.class));
  // End arbitrary controllers

  // InputSocketController Factories
  install(new FactoryModuleBuilder().build(new TypeLiteral<InputSocketController
      .BaseInputSocketControllerFactory<Object>>() {
  }));
  install(new FactoryModuleBuilder().build(CheckboxInputSocketController.Factory.class));
  install(new FactoryModuleBuilder().build(ListSpinnerInputSocketController.Factory.class));
  install(new FactoryModuleBuilder().build(RangeInputSocketController.Factory.class));
  install(new FactoryModuleBuilder().build(new TypeLiteral<SelectInputSocketController
      .Factory<Object>>() {
  }));
  install(new FactoryModuleBuilder().build(NumberSpinnerInputSocketController.Factory.class));
  install(new FactoryModuleBuilder().build(SliderInputSocketController.Factory.class));
  install(new FactoryModuleBuilder().build(TextFieldInputSocketController.Factory.class));
  // END Input Socket Controller Factories

}
项目:GRIP    文件:GripCoreModule.java   
@Override
protected void configure() {
  bind(GripMode.class).toInstance(GripMode.HEADLESS);

  // Register any injected object on the event bus
  bindListener(Matchers.any(), new TypeListener() {
    @Override
    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
      encounter.register((InjectionListener<I>) eventBus::register);
    }
  });

  bind(EventBus.class).toInstance(eventBus);
  bind(EventLogger.class).asEagerSingleton();

  // Allow for just injecting the settings provider, instead of the whole pipeline
  bind(SettingsProvider.class).to(Pipeline.class);

  install(new FactoryModuleBuilder().build(new TypeLiteral<Connection.Factory<Object>>() {
  }));

  bind(StepIndexer.class).to(Pipeline.class);
  bind(ConnectionValidator.class).to(Pipeline.class);
  bind(Source.SourceFactory.class).to(Source.SourceFactoryImpl.class);

  bind(InputSocket.Factory.class).to(InputSocketImpl.FactoryImpl.class);
  bind(OutputSocket.Factory.class).to(OutputSocketImpl.FactoryImpl.class);
  install(new FactoryModuleBuilder()
      .implement(CameraSource.class, CameraSource.class)
      .build(CameraSource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(ImageFileSource.class, ImageFileSource.class)
      .build(ImageFileSource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(MultiImageFileSource.class, MultiImageFileSource.class)
      .build(MultiImageFileSource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(HttpSource.class, HttpSource.class)
      .build(HttpSource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(NetworkTableEntrySource.class, NetworkTableEntrySource.class)
      .build(NetworkTableEntrySource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(ClassifierSource.class, ClassifierSource.class)
      .build(ClassifierSource.Factory.class));
  install(new FactoryModuleBuilder()
      .implement(VideoFileSource.class, VideoFileSource.class)
      .build(VideoFileSource.Factory.class));

  install(new FactoryModuleBuilder().build(ExceptionWitness.Factory.class));
  install(new FactoryModuleBuilder().build(Timer.Factory.class));

  bind(BenchmarkRunner.class).asEagerSingleton();

  bind(Cleaner.class).asEagerSingleton();
}
项目:guice    文件:InternalProvisionException.java   
public static InternalProvisionException errorNotifyingInjectionListener(
    InjectionListener<?> listener, TypeLiteral<?> type, RuntimeException cause) {
  return errorInUserCode(
      cause, "Error notifying InjectionListener %s of %s.%n Reason: %s", listener, type, cause);
}
项目:guice    文件:EncounterImpl.java   
ImmutableSet<InjectionListener<? super T>> getInjectionListeners() {
  return injectionListeners == null
      ? ImmutableSet.<InjectionListener<? super T>>of()
      : ImmutableSet.copyOf(injectionListeners);
}
项目:guice    文件:TypeListenerTest.java   
public void testInstallingInjectionListener() {
  final List<Object> injectees = Lists.newArrayList();
  final InjectionListener<Object> injectionListener =
      new InjectionListener<Object>() {
        @Override
        public void afterInjection(Object injectee) {
          injectees.add(injectee);
        }
      };

  Injector injector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bindListener(
                  onlyAbcd,
                  new TypeListener() {
                    @Override
                    public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
                      encounter.register(injectionListener);
                    }
                  });
              bind(A.class);
            }
          });

  assertEquals(ImmutableList.of(), injectees);

  Object a1 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1), injectees);

  Object a2 = injector.getInstance(A.class);
  assertEquals(ImmutableList.of(a1, a2), injectees);

  Object b1 = injector.getInstance(B.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);

  Provider<A> aProvider = injector.getProvider(A.class);
  assertEquals(ImmutableList.of(a1, a2, b1), injectees);
  A a3 = aProvider.get();
  A a4 = aProvider.get();
  assertEquals(ImmutableList.of(a1, a2, b1, a3, a4), injectees);
}
项目:guice-old    文件:EncounterImpl.java   
ImmutableSet<InjectionListener<? super T>> getInjectionListeners() {
  return injectionListeners == null
      ? ImmutableSet.<InjectionListener<? super T>>of()
      : ImmutableSet.copyOf(injectionListeners);
}
项目:guice-old    文件:Errors.java   
public Errors errorNotifyingInjectionListener(
    InjectionListener<?> listener, TypeLiteral<?> type, RuntimeException cause) {
  return errorInUserCode(cause, "Error notifying InjectionListener %s of %s.%n"
      + " Reason: %s", listener, type, cause);
}
项目:stdlib    文件:ConfigurationPropertyRegistryModule.java   
@Override
public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter)
{
    final Class<?> discoveredType = type.getRawType();

    int reconfigurables = 0;

    // Process @Inject constructor
    for (Constructor<?> constructor : discoveredType.getDeclaredConstructors())
    {
        if (constructor.isAnnotationPresent(Inject.class))
        {
            reconfigurables += processMethod(discoveredType, constructor);
        }
    }

    // Walk up the hierarchy and look for the declared fields
    for (Class<?> clazz = discoveredType; clazz != null; clazz = clazz.getSuperclass())
    {
        // Process @Inject @Named fields
        for (Field field : clazz.getDeclaredFields())
        {
            if (field.isAnnotationPresent(Inject.class) && field.isAnnotationPresent(Named.class))
            {
                final Named named = field.getAnnotation(Named.class);

                registry.register(discoveredType, injectorRef, named.value(), field.getType(), field);

                reconfigurables++;
            }
        }

        // Process @Inject methods
        for (Method method : clazz.getDeclaredMethods())
        {
            if (method.isAnnotationPresent(Inject.class))
            {
                reconfigurables += processMethod(discoveredType, method);
            }
        }
    }

    // If there were config properties in this type, register an InjectionListener to grab instances for runtime reconfiguration
    // TODO should all the props be @Reconfigurable for this?
    if (reconfigurables > 0)
        encounter.register(new InjectionListener<I>()
        {
            @Override
            public void afterInjection(final I injectee)
            {
                registry.addInstance(discoveredType, injectee);
            }
        });
}