protected Entry activate()

in cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/model/InstanceActivator.java [75:136]


	protected Entry<ExtendedActivationDTO, Object> activate(
		Bean<? extends Object> bean,
		ExtendedActivationTemplateDTO activationTemplate,
		BeanManager beanManager) {

		ExtendedActivationDTO activationDTO = new ExtendedActivationDTO();
		activationDTO.errors = new CopyOnWriteArrayList<>();
		activationDTO.template = activationTemplate;
		activationDTO.instance = _instance;

		_instance.activations.add(activationDTO);

		try (With with = new With(activationDTO)) {
			try {
				final Object object = containerState.componentContext().get(
					(Bean)bean,
					(CreationalContext)beanManager.createCreationalContext(bean));

				final Set<Annotation> qualifiers = bean.getQualifiers();

				try {
					beanManager.fireEvent(object, Sets.hashSet(qualifiers, Initialized.Literal.of(ComponentScoped.class)).toArray(new Annotation[0]));
				}
				catch (Throwable t) {
					_log.error(l -> l.error("CCR Error in activator event @Initialized for {} on {}", _instance, bundle(), t));
					activationDTO.errors.add(Throw.asString(t));
				}

				activationDTO.onClose = a -> {
					try (With with2 = new With(a)) {
						try {
							beanManager.fireEvent(object, Sets.hashSet(qualifiers, BeforeDestroyed.Literal.of(ComponentScoped.class)).toArray(new Annotation[0]));
						}
						catch (Throwable t) {
							_log.error(l -> l.error("CCR Error in activator event @BeforeDestroyed for {} on {}", _instance, bundle(), t));
							activationDTO.errors.add(Throw.asString(t));
						}

						containerState.componentContext().destroy();

						try {
							beanManager.fireEvent(object, Sets.hashSet(qualifiers, Destroyed.Literal.of(ComponentScoped.class)).toArray(new Annotation[0]));
						}
						catch (Throwable t) {
							_log.error(l -> l.error("CCR Error in activator event @Destroyed for {} on {}", _instance, bundle(), t));
							activationDTO.errors.add(Throw.asString(t));
						}

						_instance.activations.remove(a);
					}
				};

				return new AbstractMap.SimpleImmutableEntry<>(activationDTO, object);
			}
			catch (Throwable t) {
				_log.error(l -> l.error("CCR Error in activator create for {} on {}", _instance, bundle(), t));
				activationDTO.errors.add(Throw.asString(t));

				return new AbstractMap.SimpleImmutableEntry<>(activationDTO, null);
			}
		}
	}