private void checkBeanIdentifierIndexConsistency(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = session.getAttribute(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { session.setAttribute(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
private <T> void destroyContextualInstance(ContextualInstance<T> instance) { instance.getContextual().destroy(instance.getInstance(), instance.getCreationalContext()); ContextLogger.LOG.contextualInstanceRemoved(instance, this); }
/** * Detach the bean store, causing updates to longer be written through to the * underlying store. */ public boolean detach() { if (attached) { attached = false; ContextLogger.LOG.beanStoreDetached(this); return true; } else { return false; } }
public void cleanup() { final BeanStore beanStore = getBeanStore(); if (beanStore != null) { try { beanStore.clear(); } catch (Exception e) { ContextLogger.LOG.unableToClearBeanStore(beanStore); ContextLogger.LOG.catchingDebug(e); } } }
private void checkBeanIdentifierIndexConsistency(Map<String, Object> storage) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = storage.get(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { storage.put(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
@Override public <T> void put(BeanIdentifier id, ContextualInstance<T> instance) { beanStore.put(id, instance); // moved due to WELD-892 if (isAttached()) { setAttribute(namingScheme.prefix(id), instance); } ContextLogger.LOG.contextualInstanceAdded(instance.getContextual(), id, this); }
public void clear() { Iterator<BeanIdentifier> it = iterator(); while (it.hasNext()) { BeanIdentifier id = it.next(); if (isAttached()) { String prefixedId = namingScheme.prefix(id); removeAttribute(prefixedId); } it.remove(); ContextLogger.LOG.contextualInstanceRemoved(id, this); } ContextLogger.LOG.contextCleared(this); }
/** * Destroys the context */ protected void destroy() { ContextLogger.LOG.contextCleared(this); final BeanStore beanStore = getBeanStore(); if (beanStore == null) { throw ContextLogger.LOG.noBeanStoreAvailable(this); } for (BeanIdentifier id : beanStore) { destroyContextualInstance(beanStore.get(id)); } beanStore.clear(); }
@Override public void addContext(Context context) { checkWithinObserverNotification(); Preconditions.checkArgumentNotNull(context, "context"); Class<? extends Annotation> scope = context.getScope(); if (scope == null) { throw ContextLogger.LOG.contextHasNullScope(context); } if (!getBeanManager().isScope(scope)) { MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context); } if (scope == ApplicationScoped.class || scope == Dependent.class) { throw ContextLogger.LOG.cannotRegisterContext(scope, context); } getBeanManager().addContext(context); BootstrapLogger.LOG.addContext(getReceiver(), context); }
@Override public <T> ContextualInstance<T> remove(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.remove(id); if (instance != null) { if (isAttached()) { removeAttribute(namingScheme.prefix(id)); } ContextLogger.LOG.contextualInstanceRemoved(id, this); } return instance; }
@Override public <T> ContextualInstance<T> get(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.get(id); if(instance == null && isAttached() && isAttributeLazyFetchingEnabled()) { instance = cast(getAttribute(namingScheme.prefix(id))); if(instance != null) { beanStore.put(id, instance); } } ContextLogger.LOG.contextualInstanceFound(id, instance, this); return instance; }
/** * Fetch all relevant attributes from the backing store and copy instances which are not present in the local bean store. */ public void fetchUninitializedAttributes() { for (String prefixedId : getPrefixedAttributeNames()) { BeanIdentifier id = getNamingScheme().deprefix(prefixedId); if (!beanStore.contains(id)) { ContextualInstance<?> instance = (ContextualInstance<?>) getAttribute(prefixedId); beanStore.put(id, instance); ContextLogger.LOG.addingDetachedContextualUnderId(instance, id); } } }
private void checkBeanIdentifierIndexConsistency(Map<String, Object> storage) { BeanIdentifierIndex index = getServiceRegistry().get(BeanIdentifierIndex.class); if (index != null && index.isBuilt()) { Object hash = storage.get(KEY_BEAN_ID_INDEX_HASH); if (hash != null) { if (!index.getIndexHash().equals(hash)) { throw ContextLogger.LOG.beanIdentifierIndexInconsistencyDetected(hash.toString(), index.getDebugInfo()); } } else { storage.put(KEY_BEAN_ID_INDEX_HASH, index.getIndexHash()); } } } }
@Override public <T> void put(BeanIdentifier id, ContextualInstance<T> instance) { beanStore.put(id, instance); // moved due to WELD-892 if (isAttached()) { setAttribute(namingScheme.prefix(id), instance); } ContextLogger.LOG.contextualInstanceAdded(instance.getContextual(), id, this); }
public void clear() { Iterator<BeanIdentifier> it = iterator(); while (it.hasNext()) { BeanIdentifier id = it.next(); if (isAttached()) { String prefixedId = namingScheme.prefix(id); removeAttribute(prefixedId); } it.remove(); ContextLogger.LOG.contextualInstanceRemoved(id, this); } ContextLogger.LOG.contextCleared(this); }
public void cleanup() { final BeanStore beanStore = getBeanStore(); if (beanStore != null) { try { beanStore.clear(); } catch (Exception e) { ContextLogger.LOG.unableToClearBeanStore(beanStore); ContextLogger.LOG.catchingDebug(e); } } }
/** * Destroys the context */ protected void destroy() { ContextLogger.LOG.contextCleared(this); final BeanStore beanStore = getBeanStore(); if (beanStore == null) { throw ContextLogger.LOG.noBeanStoreAvailable(this); } for (BeanIdentifier id : beanStore) { destroyContextualInstance(beanStore.get(id)); } beanStore.clear(); }
@Override public void addContext(Context context) { checkWithinObserverNotification(); Preconditions.checkArgumentNotNull(context, "context"); Class<? extends Annotation> scope = context.getScope(); if (scope == null) { throw ContextLogger.LOG.contextHasNullScope(context); } if (!getBeanManager().isScope(scope)) { MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context); } if (scope == ApplicationScoped.class || scope == Dependent.class) { throw ContextLogger.LOG.cannotRegisterContext(scope, context); } getBeanManager().addContext(context); BootstrapLogger.LOG.addContext(getReceiver(), context); }
@Override public <T> ContextualInstance<T> remove(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.remove(id); if (instance != null) { if (isAttached()) { removeAttribute(namingScheme.prefix(id)); } ContextLogger.LOG.contextualInstanceRemoved(id, this); } return instance; }
@Override public <T> ContextualInstance<T> get(BeanIdentifier id) { ContextualInstance<T> instance = beanStore.get(id); if(instance == null && isAttached() && isAttributeLazyFetchingEnabled()) { instance = cast(getAttribute(namingScheme.prefix(id))); if(instance != null) { beanStore.put(id, instance); } } ContextLogger.LOG.contextualInstanceFound(id, instance, this); return instance; }