use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.
the class AttributeBeanStore method iterator.
public Iterator<BeanIdentifier> iterator() {
Iterator<BeanIdentifier> iterator;
if (isAttributeLazyFetchingEnabled()) {
// Merge the bean identifiers from the local bean store and the backing store
Set<BeanIdentifier> identifiers = new HashSet<>();
for (BeanIdentifier id : beanStore) {
identifiers.add(id);
}
for (String prefixedId : getPrefixedAttributeNames()) {
identifiers.add(getNamingScheme().deprefix(prefixedId));
}
iterator = identifiers.iterator();
} else {
iterator = beanStore.iterator();
}
return iterator;
}
use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.
the class AttributeBeanStore method fetchUninitializedAttributes.
/**
* 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);
}
}
}
use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.
the class AbstractContext method get.
/**
* Get the bean if it exists in the contexts.
*
* @return An instance of the bean
* @throws ContextNotActiveException if the context is not active
* @see javax.enterprise.context.spi.Context#get(BaseBean, boolean)
*/
@Override
@SuppressFBWarnings(value = "UL_UNRELEASED_LOCK", justification = "False positive from FindBugs")
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
if (!isActive()) {
throw new ContextNotActiveException();
}
checkContextInitialized();
final BeanStore beanStore = getBeanStore();
if (beanStore == null) {
return null;
}
if (contextual == null) {
throw ContextLogger.LOG.contextualIsNull();
}
BeanIdentifier id = getId(contextual);
ContextualInstance<T> beanInstance = beanStore.get(id);
if (beanInstance != null) {
return beanInstance.getInstance();
} else if (creationalContext != null) {
LockedBean lock = null;
try {
if (multithreaded) {
lock = beanStore.lock(id);
beanInstance = beanStore.get(id);
if (beanInstance != null) {
return beanInstance.getInstance();
}
}
T instance = contextual.create(creationalContext);
if (instance != null) {
beanInstance = new SerializableContextualInstanceImpl<Contextual<T>, T>(contextual, instance, creationalContext, serviceRegistry.get(ContextualStore.class));
beanStore.put(id, beanInstance);
}
return instance;
} finally {
if (lock != null) {
lock.unlock();
}
}
} else {
return null;
}
}
use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.
the class ContextualStoreImpl method putIfAbsent.
/**
* Add a contextual (if not already present) to the store, and return it's
* id. If the contextual is passivation capable, it's id will be used,
* otherwise an id will be generated
*
* @param contextual the contextual to add
* @return the current id for the contextual
*/
@SuppressFBWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Using non-standard semantics of putIfAbsent")
public BeanIdentifier putIfAbsent(Contextual<?> contextual) {
if (contextual instanceof CommonBean<?>) {
// this is a Bean<?> created by Weld
CommonBean<?> bean = (CommonBean<?>) contextual;
passivationCapableContextuals.putIfAbsent(bean.getIdentifier(), contextual);
return bean.getIdentifier();
}
if (contextual instanceof PassivationCapable) {
// this is an extension-provided passivation capable bean
PassivationCapable passivationCapable = (PassivationCapable) contextual;
String id = passivationCapable.getId();
BeanIdentifier identifier = new StringBeanIdentifier(id);
passivationCapableContextuals.putIfAbsent(identifier, contextual);
return identifier;
} else {
BeanIdentifier id = contextuals.get(contextual);
if (id != null) {
return id;
} else {
synchronized (contextual) {
id = contextuals.get(contextual);
if (id == null) {
id = new StringBeanIdentifier(new StringBuilder().append(GENERATED_ID_PREFIX).append(idGenerator.incrementAndGet()).toString());
contextuals.put(contextual, id);
contextualsInverse.put(id, contextual);
}
return id;
}
}
}
}
use of org.jboss.weld.serialization.spi.BeanIdentifier in project core by weld.
the class ProxyFactory method createCompoundProxyName.
private static String createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) {
String className;
final List<String> interfaces = new ArrayList<String>();
for (Class<?> type : typeInfo.getInterfaces()) {
interfaces.add(type.getSimpleName());
}
Collections.sort(interfaces);
for (final String iface : interfaces) {
name.append(iface);
name.append('$');
}
// However, it is safe to share a proxy class for built-in beans of the same type (e.g. Event)
if (bean != null && !(bean instanceof AbstractBuiltInBean)) {
final BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean);
int idHash = id.hashCode();
name.append(Math.abs(idHash == Integer.MIN_VALUE ? 0 : idHash));
}
className = name.toString();
return className;
}
Aggregations