Search in sources :

Example 11 with JsonObjectBuilder

use of org.jboss.weld.probe.Json.JsonObjectBuilder in project core by weld.

the class JsonObjects method createSimpleBeanJson.

/**
 * The simple representation consists of the generated id, {@link Components.BeanKind}, {@link Bean#getBeanClass()} and bean archive id (if not a built-in
 * bean).
 *
 * @param bean
 * @param probe
 * @return the simple bean representation
 */
static JsonObjectBuilder createSimpleBeanJson(Bean<?> bean, Probe probe) {
    JsonObjectBuilder builder = Json.objectBuilder(true);
    builder.add(ID, probe.getBeanId(bean));
    builder.add(KIND, BeanKind.from(bean).toString());
    builder.add(BEAN_CLASS, bean.getBeanClass().getName());
    // BDA
    BeanManagerImpl beanManager = probe.getBeanManager(bean);
    if (beanManager != null) {
        builder.add(BDA_ID, Components.getId(beanManager.getId()));
    }
    return builder;
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 12 with JsonObjectBuilder

use of org.jboss.weld.probe.Json.JsonObjectBuilder in project core by weld.

the class JsonObjects method createDeclaredProducers.

/**
 * @param bean
 * @param probe
 * @return
 */
static JsonArrayBuilder createDeclaredProducers(Bean<?> bean, Probe probe) {
    JsonArrayBuilder declaredProducers = Json.arrayBuilder();
    for (AbstractProducerBean<?, ?, ?> producerBean : probe.getDeclaredProducers(bean)) {
        JsonObjectBuilder producerBuilder = createSimpleBeanJson(producerBean, probe);
        if (producerBean.getProducer() instanceof ProducerMethodProducer) {
            ProducerMethodProducer<?, ?> producer = (ProducerMethodProducer<?, ?>) producerBean.getProducer();
            producerBuilder.add(PRODUCER_INFO, annotatedMethodToString((AnnotatedMethod<?>) producer.getAnnotated(), bean.getBeanClass()));
        } else if (producerBean.getProducer() instanceof ProducerFieldProducer) {
            ProducerFieldProducer<?, ?> producer = (ProducerFieldProducer<?, ?>) producerBean.getProducer();
            producerBuilder.add(PRODUCER_INFO, annotatedFieldToString(producer.getAnnotated(), bean.getBeanClass()));
        }
        declaredProducers.add(producerBuilder);
    }
    return declaredProducers;
}
Also used : AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) ProducerFieldProducer(org.jboss.weld.injection.producer.ProducerFieldProducer) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) ProducerMethodProducer(org.jboss.weld.injection.producer.ProducerMethodProducer)

Example 13 with JsonObjectBuilder

use of org.jboss.weld.probe.Json.JsonObjectBuilder in project core by weld.

the class JsonObjects method createContextJson.

static JsonObjectBuilder createContextJson(String id, Class<? extends Annotation> scope, BeanManagerImpl beanManager, Probe probe, HttpServletRequest req) {
    JsonObjectBuilder builder = createSimpleContextJson(id, scope);
    builder.add(INSTANCES, inspectContext(scope, beanManager, probe));
    if (req != null && ConversationScoped.class.equals(scope)) {
        HttpSession session = req.getSession(false);
        if (session != null) {
            // Get all available conversation ids
            Object conversationsAttribute = session.getAttribute(AbstractConversationContext.CONVERSATIONS_ATTRIBUTE_NAME);
            if (conversationsAttribute != null && conversationsAttribute instanceof Map) {
                @SuppressWarnings("unchecked") Map<String, ManagedConversation> conversationsMap = (Map<String, ManagedConversation>) conversationsAttribute;
                if (!conversationsMap.isEmpty()) {
                    JsonArrayBuilder cidsBuilder = Json.arrayBuilder();
                    for (String cid : conversationsMap.keySet()) {
                        cidsBuilder.add(cid);
                    }
                    builder.add(CIDS, cidsBuilder);
                }
            }
        }
    }
    return builder;
}
Also used : ConversationScoped(javax.enterprise.context.ConversationScoped) HttpSession(javax.servlet.http.HttpSession) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) ManagedConversation(org.jboss.weld.context.ManagedConversation) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Map(java.util.Map)

Example 14 with JsonObjectBuilder

use of org.jboss.weld.probe.Json.JsonObjectBuilder in project core by weld.

the class JsonObjects method createFullInvocationJson.

/**
 * @param invocation
 * @param probe
 * @return
 */
static JsonObjectBuilder createFullInvocationJson(Invocation invocation, Probe probe) {
    JsonObjectBuilder invocationBuilder = createBasicInvocationJson(invocation, probe);
    invocationBuilder.add(TYPE, invocation.getType().toString());
    if (invocation.hasChildren()) {
        JsonArrayBuilder childrenBuilder = Json.arrayBuilder();
        for (Invocation child : invocation.getChildren()) {
            childrenBuilder.add(createFullInvocationJson(child, probe));
        }
        invocationBuilder.add(CHILDREN, childrenBuilder);
    }
    return invocationBuilder;
}
Also used : JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 15 with JsonObjectBuilder

use of org.jboss.weld.probe.Json.JsonObjectBuilder in project core by weld.

the class JsonObjects method createBootstrapStatsJson.

static JsonArrayBuilder createBootstrapStatsJson(Probe probe) {
    JsonArrayBuilder builder = Json.arrayBuilder();
    Map<EventType, AtomicInteger> counts = probe.getBootstrapStats().getCounts();
    List<EventType> sortedKeys = new ArrayList<>(counts.keySet());
    Collections.sort(sortedKeys, new Comparator<EventType>() {

        @Override
        public int compare(EventType o1, EventType o2) {
            return Integer.compare(o1.getPriority(), o2.getPriority());
        }
    });
    for (EventType eventType : sortedKeys) {
        JsonObjectBuilder eventBuilder = Json.objectBuilder();
        eventBuilder.add(NAME, eventType.toString());
        eventBuilder.add(TYPE, eventType.getType());
        eventBuilder.add(FIRED, counts.get(eventType).get());
        eventBuilder.add(OBSERVERS, Queries.find(probe.getObservers(), 1, 0, new ObserverFilters(probe, eventType.getType(), null)).getTotal());
        builder.add(eventBuilder);
    }
    return builder;
}
Also used : EventType(org.jboss.weld.probe.BootstrapStats.EventType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ObserverFilters(org.jboss.weld.probe.Queries.ObserverFilters) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Aggregations

JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)25 JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)16 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)5 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)4 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)4 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)4 EventType (org.jboss.weld.probe.BootstrapStats.EventType)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Annotation (java.lang.annotation.Annotation)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)2 Bean (javax.enterprise.inject.spi.Bean)2 ProcessAnnotatedType (javax.enterprise.inject.spi.ProcessAnnotatedType)2 ProcessSyntheticAnnotatedType (javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType)2 AbstractClassBean (org.jboss.weld.bean.AbstractClassBean)2 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)2 SessionBean (org.jboss.weld.bean.SessionBean)2 ModuleEnablement (org.jboss.weld.bootstrap.enablement.ModuleEnablement)2