Search in sources :

Example 11 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder 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 12 with JsonArrayBuilder

use of org.jboss.weld.probe.Json.JsonArrayBuilder 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)

Example 13 with JsonArrayBuilder

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

the class JsonObjects method createBasicObserverJson.

@SuppressFBWarnings(value = "BC_VACUOUS_INSTANCEOF", justification = "WELD-2452, with CDI 1.2 API, this doesn't need to be true.")
static JsonObjectBuilder createBasicObserverJson(ObserverMethod<?> observerMethod, Probe probe) {
    JsonObjectBuilder observerBuilder = createSimpleObserverJson(observerMethod, probe);
    observerBuilder.add(RECEPTION, observerMethod.getReception().toString());
    observerBuilder.add(TX_PHASE, observerMethod.getTransactionPhase().toString());
    if (!observerMethod.getObservedQualifiers().isEmpty()) {
        JsonArrayBuilder qualifiersBuilder = Json.arrayBuilder();
        for (Annotation qualifier : observerMethod.getObservedQualifiers()) {
            qualifiersBuilder.add(qualifier.toString());
        }
        observerBuilder.add(QUALIFIERS, qualifiersBuilder);
    }
    if (observerMethod instanceof ObserverMethodImpl) {
        ObserverMethodImpl<?, ?> observerMethodImpl = (ObserverMethodImpl<?, ?>) observerMethod;
        observerBuilder.add(DECLARING_BEAN, createSimpleBeanJson(observerMethodImpl.getDeclaringBean(), probe));
    }
    if (isUnrestrictedProcessAnnotatedTypeObserver(observerMethod)) {
        observerBuilder.add(DESCRIPTION, WARNING_UNRESTRICTED_PAT_OBSERVER);
    }
    // WELD-2452 to be removed once WFLY is EE 8 certified
    if (observerMethod instanceof Prioritized) {
        // Every OM is now instance of Prioritized
        final int priority = Prioritized.class.cast(observerMethod).getPriority();
        observerBuilder.add(PRIORITY, priority);
        observerBuilder.add(PRIORITY_RANGE, Components.PriorityRange.of(priority).toString());
    }
    return observerBuilder;
}
Also used : Prioritized(javax.enterprise.inject.spi.Prioritized) ObserverMethodImpl(org.jboss.weld.event.ObserverMethodImpl) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder) Annotation(java.lang.annotation.Annotation) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with JsonArrayBuilder

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

the class JsonObjects method createFilterJsonArray.

static JsonObjectBuilder createFilterJsonArray(Filter filter, String type) {
    JsonObjectBuilder filterBuilder = Json.objectBuilder(true);
    filterBuilder.add(TYPE, type);
    filterBuilder.add(NAME, filter.getName());
    JsonArrayBuilder activationsBuilder = Json.arrayBuilder(true);
    filterBuilder.add(ACTIVATIONS, activationsBuilder);
    if (filter.getClassAvailableActivations() != null && !filter.getClassAvailableActivations().isEmpty()) {
        for (Metadata<ClassAvailableActivation> metadata : filter.getClassAvailableActivations()) {
            activationsBuilder.add(Json.objectBuilder().add(INVERTED, metadata.getValue().isInverted()).add(CLASS_AVAILABILITY, metadata.getValue().getClassName()));
        }
    }
    if (filter.getSystemPropertyActivations() != null && !filter.getSystemPropertyActivations().isEmpty()) {
        for (Metadata<SystemPropertyActivation> metadata : filter.getSystemPropertyActivations()) {
            JsonObjectBuilder sysPropBuilder = Json.objectBuilder().add(SYS_PROPERTY, metadata.getValue().getName());
            if (metadata.getValue().getValue() != null) {
                sysPropBuilder.add(VALUE, metadata.getValue().getValue());
            }
            activationsBuilder.add(sysPropBuilder);
        }
    }
    return filterBuilder;
}
Also used : ClassAvailableActivation(org.jboss.weld.bootstrap.spi.ClassAvailableActivation) SystemPropertyActivation(org.jboss.weld.bootstrap.spi.SystemPropertyActivation) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 15 with JsonArrayBuilder

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

the class JsonObjects method inspectContext.

private static JsonArrayBuilder inspectContext(Class<? extends Annotation> scope, BeanManagerImpl beanManager, Probe probe) {
    Context context;
    try {
        context = beanManager.getContext(scope);
    } catch (ContextNotActiveException e) {
        return null;
    }
    JsonArrayBuilder builder = Json.arrayBuilder();
    for (Bean<?> bean : probe.getBeans()) {
        if (bean.getScope().equals(scope)) {
            Object contextualInstance = context.get(bean);
            if (contextualInstance != null) {
                JsonObjectBuilder instanceBuilder = createSimpleBeanJson(bean, probe);
                instanceBuilder.add(OBJECT_TO_STRING, contextualInstance.getClass().getName() + "@" + Integer.toHexString(contextualInstance.hashCode()));
                instanceBuilder.add(AS_STRING, Strings.abbreviate(contextualInstance.toString(), CONTEXTUAL_INSTANCE_TO_STRING_LIMIT));
                builder.add(instanceBuilder);
            }
        }
    }
    return builder;
}
Also used : Context(javax.enterprise.context.spi.Context) AbstractConversationContext(org.jboss.weld.contexts.AbstractConversationContext) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Aggregations

JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)16 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)16 ProxyObject (org.jboss.weld.bean.proxy.ProxyObject)5 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)3 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)3 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)3 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