@Override public void release() { if ( beanInstance == null ) { return; } try { if ( bean == null ) { // todo : BeanInstanceProducer#release? return; } bean.destroy( beanInstance, creationalContext ); } catch (Exception ignore) { } finally { if ( creationalContext != null ) { try { creationalContext.release(); } catch (Exception ignore) { } } this.beanInstance = null; this.creationalContext = null; this.bean = null; this.beanManager = null; } }
@Override @SuppressWarnings("unchecked") public ForeignDescriptor createForeignDescriptor(Binding binding) { Class<?> clazz; if (ClassBinding.class.isAssignableFrom(binding.getClass())) { clazz = ((ClassBinding<?>) binding).getService(); } else if (InstanceBinding.class.isAssignableFrom(binding.getClass())) { clazz = ((InstanceBinding<?>) binding).getService().getClass(); } else { throw new RuntimeException( org.glassfish.jersey.internal.LocalizationMessages .UNKNOWN_DESCRIPTOR_TYPE(binding.getClass().getSimpleName())); } Set<Bean<?>> beans = beanManager.getBeans(clazz); if (beans.isEmpty()) { return null; } Bean bean = beans.iterator().next(); CreationalContext ctx = beanManager.createCreationalContext(bean); return ForeignDescriptor.wrap(bean, instance -> bean.destroy(instance, ctx)); }
@Override public void destroy(T instance, CreationalContext<T> tCreationalContext) { bean.destroy(instance, tCreationalContext); }
@Override public void destroy(T instance, CreationalContext<T> creationalContext) { wrapped.destroy(instance, creationalContext); } }
@Override public void dispose(T instance) { bean.destroy(instance, null); }
@Override public void destroy(T instance, CreationalContext<T> creationalContext) { wrapped.destroy(instance, creationalContext); } }
@Override public void destroy(T instance, CreationalContext<T> context) { bean.destroy(instance,context); }
/** * Call destroy */ @Override public void destroy(T instance, CreationalContext<T> env) { _bean.destroy(instance, env); }
@Override public void destroy(T instance, CreationalContext<T> creationalContext) { wrapped.destroy(instance, creationalContext); } }
public void destroy(Object o) { final CreationalContext cc = beanManager.createCreationalContext(b); ((Bean)b).destroy(o, cc); } };
public void destroy(Object o) { final CreationalContext cc = beanManager.createCreationalContext(b); ((Bean)b).destroy(o, cc); } };
@Override protected void destroyProviderInstance(final RequiredRolesProvider instance) { if (dependentProviders.containsKey(instance)) { final BeanDef beanDef = dependentProviders.remove(instance); beanDef.bean.destroy(instance, beanDef.creationalContext); } }
public void beforeShutdown(@Observes BeforeShutdown event, BeanManager beanManager) { // Take care of destroying singletons for (Bean singleton : singletons) { CreationalContext cc = beanManager.createCreationalContext(singleton); Object o = beanManager.getReference(singleton, singleton.getBeanClass(), cc); singleton.destroy(o, cc); } } }
@Override public void destroy(T instance, CreationalContext<T> env) { getBean().destroy(instance, env); } }
void destroyBean(NGSessionScopeInstance customScopeInstance) { getBeans().remove(customScopeInstance.bean.getBeanClass()); customScopeInstance.bean.destroy(customScopeInstance.instance, customScopeInstance.ctx); }
@Test @SpecAssertion(section = "4.2", id = "bbc") public void testIndirectSubClassInheritsPreDestroyOnSuperclass() { OrderProcessor.preDestroyCalled = false; assert getBeans(IndirectOrderProcessor.class).size() == 1; Bean<IndirectOrderProcessor> bean = getBeans(IndirectOrderProcessor.class).iterator().next(); CreationalContext<IndirectOrderProcessor> creationalContext = getCurrentManager().createCreationalContext(bean); IndirectOrderProcessor instance = getInstanceByType(IndirectOrderProcessor.class); bean.destroy(instance, creationalContext); assert OrderProcessor.preDestroyCalled; }
@Test @SpecAssertion(section = "4.2", id = "bba") public void testSubClassDoesNotInheritPreDestroyConstructOnSuperclassBlockedByIntermediateClass() { OrderProcessor.preDestroyCalled = false; assert getBeans(NovelOrderProcessor.class).size() == 1; Bean<NovelOrderProcessor> bean = getBeans(NovelOrderProcessor.class).iterator().next(); CreationalContext<NovelOrderProcessor> creationalContext = getCurrentManager().createCreationalContext(bean); NovelOrderProcessor instance = getInstanceByType(NovelOrderProcessor.class); bean.destroy(instance, creationalContext); assert !OrderProcessor.preDestroyCalled; }
@Test(groups = { "enterpriseBeans", "lifecycle" }) @SpecAssertion(section = "5.5.3", id = "a") public void testDependentObjectsDestroyed() { Bean<UniStadt> uniStadtBean = getBeans(UniStadt.class).iterator().next(); CreationalContext<UniStadt> creationalContext = getCurrentManager().createCreationalContext(uniStadtBean); UniStadt marburg = uniStadtBean.create(creationalContext); assert marburg != null : "Couldn't find the main SFSB"; uniStadtBean.destroy(marburg, creationalContext); GrossStadt frankfurt = getInstanceByType(GrossStadt.class); assert frankfurt.isSchlossDestroyed(); }
/** * This method will properly destroy the @Dependent scoped instance. * It will have no effect if the bean is NormalScoped as those have their * own lifecycle which we must not disrupt. */ public void destroy() { if (!BeanManagerProvider.getInstance().getBeanManager().isNormalScope(bean.getScope())) { bean.destroy(instance, creationalContext); } }
/** * This method will properly destroy the @Dependent scoped instance. * It will have no effect if the bean is NormalScoped as those have their * own lifecycle which we must not disrupt. */ public void destroy() { if (!BeanManagerProvider.getInstance().getBeanManager().isNormalScope(bean.getScope())) { bean.destroy(instance, creationalContext); } }