Search in sources :

Example 6 with BeanIdentifier

use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.

the class ClientProxyProvider method createClientProxy.

private <T> T createClientProxy(Bean<T> bean, Set<Type> types) {
    BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean);
    if (id == null) {
        throw BeanLogger.LOG.beanIdCreationFailed(bean);
    }
    BeanInstance beanInstance = new ContextBeanInstance<T>(bean, id, contextId);
    TypeInfo typeInfo = TypeInfo.of(types);
    T proxy = new ClientProxyFactory<T>(contextId, typeInfo.getSuperClass(), types, bean).create(beanInstance);
    BeanLogger.LOG.createdNewClientProxyType(proxy.getClass(), bean, id);
    return proxy;
}
Also used : ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier) TypeInfo(org.jboss.weld.util.Proxies.TypeInfo)

Example 7 with BeanIdentifier

use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.

the class AttributeBeanStore method attach.

/**
 * <p>
 * Attach the bean store, any updates from now on will be written through to
 * the underlying store.
 * </p>
 * <p/>
 * <p>
 * When the bean store is attached, the detached state is assumed to be
 * authoritative if there are any conflicts.
 * </p>
 */
public boolean attach() {
    if (!attached) {
        attached = true;
        if (isLocalBeanStoreSyncNeeded()) {
            if (!beanStore.delegate().isEmpty()) {
                // The local bean store is authoritative, so copy everything to the backing store
                for (BeanIdentifier id : beanStore) {
                    ContextualInstance<?> instance = beanStore.get(id);
                    String prefixedId = getNamingScheme().prefix(id);
                    ContextLogger.LOG.updatingStoreWithContextualUnderId(instance, id);
                    setAttribute(prefixedId, instance);
                }
            }
            if (!isAttributeLazyFetchingEnabled()) {
                // Additionally copy anything not in the local bean store but in the backing store
                fetchUninitializedAttributes();
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier)

Example 8 with BeanIdentifier

use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.

the class AttributeBeanStore method clear.

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);
}
Also used : BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier)

Example 9 with BeanIdentifier

use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.

the class AbstractContext method destroy.

@Override
public void destroy(Contextual<?> contextual) {
    if (!isActive()) {
        throw new ContextNotActiveException();
    }
    checkContextInitialized();
    if (contextual == null) {
        throw ContextLogger.LOG.contextualIsNull();
    }
    final BeanStore beanStore = getBeanStore();
    if (beanStore == null) {
        throw ContextLogger.LOG.noBeanStoreAvailable(this);
    }
    BeanIdentifier id = getId(contextual);
    ContextualInstance<?> beanInstance = beanStore.remove(id);
    if (beanInstance != null) {
        RequestScopedCache.invalidate();
        destroyContextualInstance(beanInstance);
    }
}
Also used : BeanStore(org.jboss.weld.contexts.beanstore.BeanStore) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier)

Example 10 with BeanIdentifier

use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.

the class AbstractContext method destroy.

/**
 * 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();
}
Also used : BeanStore(org.jboss.weld.contexts.beanstore.BeanStore) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier)

Aggregations

BeanIdentifier (org.jboss.weld.serialization.spi.BeanIdentifier)10 BeanStore (org.jboss.weld.contexts.beanstore.BeanStore)3 ContextualStore (org.jboss.weld.serialization.spi.ContextualStore)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ContextNotActiveException (javax.enterprise.context.ContextNotActiveException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PassivationCapable (javax.enterprise.inject.spi.PassivationCapable)1 CommonBean (org.jboss.weld.bean.CommonBean)1 StringBeanIdentifier (org.jboss.weld.bean.StringBeanIdentifier)1 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)1 ContextualInstance (org.jboss.weld.context.api.ContextualInstance)1 LockedBean (org.jboss.weld.contexts.beanstore.LockedBean)1 TypeInfo (org.jboss.weld.util.Proxies.TypeInfo)1