Search in sources :

Example 1 with SimpleBeanStore

use of org.eclipse.jetty.cdi.core.SimpleBeanStore in project jetty.project by eclipse.

the class WebSocketScopeContext method get.

@SuppressWarnings("unchecked")
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("{} get({},{})", this, contextual, creationalContext);
    }
    Bean<T> bean = (Bean<T>) contextual;
    if (bean.getBeanClass().isAssignableFrom(Session.class)) {
        return (T) this.session;
    }
    if (beanStore == null) {
        beanStore = new SimpleBeanStore();
    }
    List<ScopedInstance<?>> beans = beanStore.getBeans(contextual);
    if ((beans != null) && (!beans.isEmpty())) {
        for (ScopedInstance<?> instance : beans) {
            if (instance.bean.equals(bean)) {
                return (T) instance.instance;
            }
        }
    }
    // no bean found, create it
    T t = bean.create(creationalContext);
    ScopedInstance<T> customInstance = new ScopedInstance<>();
    customInstance.bean = bean;
    customInstance.creationalContext = creationalContext;
    customInstance.instance = t;
    beanStore.addBean(customInstance);
    return t;
}
Also used : SimpleBeanStore(org.eclipse.jetty.cdi.core.SimpleBeanStore) ScopedInstance(org.eclipse.jetty.cdi.core.ScopedInstance) Bean(javax.enterprise.inject.spi.Bean)

Example 2 with SimpleBeanStore

use of org.eclipse.jetty.cdi.core.SimpleBeanStore in project jetty.project by eclipse.

the class WebSocketScopeContext method create.

public void create() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("{} create()", this);
    }
    current.set(this);
    beanStore = new SimpleBeanStore();
}
Also used : SimpleBeanStore(org.eclipse.jetty.cdi.core.SimpleBeanStore)

Aggregations

SimpleBeanStore (org.eclipse.jetty.cdi.core.SimpleBeanStore)2 Bean (javax.enterprise.inject.spi.Bean)1 ScopedInstance (org.eclipse.jetty.cdi.core.ScopedInstance)1