@Override public boolean addDestructionCallback(final Object beanInstance, final DestructionCallback<?> destructionCallback) { return contextManager.addDestructionCallback(beanInstance, destructionCallback); }
@Override public void destroyBean(final Object ref) { contextManager.destroy(ref); }
@Override public boolean isManaged(final Object ref) { return contextManager.isManaged(ref); }
@Override public T newInstance() { return contextManager.getNewInstance(handle.getFactoryName()); }
private Collection<FactoryHandle> addFactories() { final Collection<FactoryHandle> eager = new ArrayList<>(); logger.debug("Adding factories..."); final long start = System.currentTimeMillis(); final Collection<FactoryHandle> allFactoryHandles = contextManager.getAllFactoryHandles(); for (final FactoryHandle handle : allFactoryHandles) { if (handle.isEager()) { eager.add(handle); } addFactory(handle); } final long duration = System.currentTimeMillis() - start; logger.debug("Added {} factories in {}ms.", allFactoryHandles.size(), duration); return eager; }
private void initializeEagerBeans(final Collection<FactoryHandle> eager) { logger.debug("Initializing eager beans..."); final long start = System.currentTimeMillis(); if (logger.isTraceEnabled()) { for (final FactoryHandle handle : eager) { logger.trace("Initializing {}...", handle); final long beanStart = System.currentTimeMillis(); contextManager.getEagerInstance(handle.getFactoryName()); final long duration = System.currentTimeMillis() - beanStart; logger.trace("Finished initializing in {}ms.", duration); } } else { for (final FactoryHandle handle : eager) { contextManager.getEagerInstance(handle.getFactoryName()); } } final long duration = System.currentTimeMillis() - start; logger.debug("Initialized {} eager beans in {}ms.", eager.size(), duration); }
public void addFactory(final Factory<?> factory) { contextManager.addFactory(factory); addFactory(factory.getHandle()); } }
@Override public T getInstance() { final T instance = contextManager.getInstance(handle.getFactoryName()); if (instance instanceof Proxy) { @SuppressWarnings("unchecked") final Proxy<T> proxy = (Proxy<T>) instance; // Forces bean to be loaded. proxy.unwrap(); } return instance; }
/** * This method performs any cleanup required for destroying a type. It will * invoke generated statements from decorators, invoke disposers or predestroy * methods, and destroy and {@link Dependent} scoped dependencies. * * @param instance The instance being destroyed. * @param contextManager For destroying dependencies. */ @SuppressWarnings("unchecked") public void destroyInstance(final Object instance, final ContextManager contextManager) { final Object unwrapped = maybeUnwrapProxy(instance); generatedDestroyInstance(unwrapped, contextManager); referenceMaps.remove(unwrapped); for (final Object depRef : dependentScopedDependencies.get((T) unwrapped)) { contextManager.destroy(depRef); } dependentScopedDependencies.removeAll(instance); }