コード例 #1
0
  @SuppressWarnings("unchecked")
  <T, X> void registerBeans(@Observes AfterBeanDiscovery event, final BeanManager beanManager) {

    if (beanManager.getBeans(RemoteCacheManager.class).isEmpty()) {
      LOGGER.addDefaultRemoteCacheManager();
      event.addBean(createDefaultRemoteCacheManagerBean(beanManager));
    }

    for (Map.Entry<Type, Set<Annotation>> entry : remoteCacheInjectionPoints.entrySet()) {

      event.addBean(
          new BeanBuilder(beanManager)
              .readFromType(beanManager.createAnnotatedType(Reflections.getRawType(entry.getKey())))
              .addType(entry.getKey())
              .addQualifiers(entry.getValue())
              .beanLifecycle(
                  new ContextualLifecycle<RemoteCache<?, ?>>() {
                    @Override
                    public RemoteCache<?, ?> create(
                        Bean<RemoteCache<?, ?>> bean, CreationalContext<RemoteCache<?, ?>> ctx) {
                      return remoteCacheProducer.produce(ctx);
                    }

                    @Override
                    public void destroy(
                        Bean<RemoteCache<?, ?>> bean,
                        RemoteCache<?, ?> instance,
                        CreationalContext<RemoteCache<?, ?>> ctx) {
                      remoteCacheProducer.dispose(instance);
                    }
                  })
              .create());
    }
  }
コード例 #2
0
  <T> void saveRemoteInjectionPoints(
      @Observes ProcessInjectionTarget<T> event, BeanManager beanManager) {
    final InjectionTarget<T> injectionTarget = event.getInjectionTarget();

    for (InjectionPoint injectionPoint : injectionTarget.getInjectionPoints()) {
      final Annotated annotated = injectionPoint.getAnnotated();
      final Type type = annotated.getBaseType();
      final Class<?> rawType = Reflections.getRawType(annotated.getBaseType());
      final Set<Annotation> qualifiers =
          Reflections.getQualifiers(beanManager, annotated.getAnnotations());

      if (rawType.equals(RemoteCache.class) && qualifiers.isEmpty()) {
        qualifiers.add(new AnnotationLiteral<Default>() {});
        addRemoteCacheInjectionPoint(type, qualifiers);

      } else if (!annotated.isAnnotationPresent(Remote.class)
          && Reflections.getMetaAnnotation(annotated, Remote.class) != null
          && rawType.isAssignableFrom(RemoteCache.class)) {

        addRemoteCacheInjectionPoint(type, qualifiers);
      }
    }
  }