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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations