Search in sources :

Example 16 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ApiDocsServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response, final ConfiguredObject<?> managedObject) throws ServletException, IOException {
    ConfiguredObjectFinder finder = getConfiguredObjectFinder(managedObject);
    final Class<? extends ConfiguredObject> configuredClass;
    final Class<? extends ConfiguredObject>[] hierarchy;
    final String[] servletPathParts = request.getServletPath().split("/");
    final Model model = managedObject.getModel();
    if (servletPathParts.length < 4) {
        configuredClass = null;
        hierarchy = null;
    } else {
        configuredClass = getConfiguredClass(request, managedObject);
        if (configuredClass == null) {
            sendError(response, HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        hierarchy = finder.getHierarchy(configuredClass);
        if (hierarchy == null) {
            sendError(response, HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (!_typeSpecialisations.containsKey(configuredClass)) {
            List<Class<? extends ConfiguredObject>> types = new ArrayList<>(model.getTypeRegistry().getTypeSpecialisations(configuredClass));
            _typeSpecialisations.putIfAbsent(configuredClass, types);
        }
    }
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);
    PrintWriter writer = response.getWriter();
    writePreamble(writer);
    writeHead(writer, hierarchy, configuredClass);
    if (hierarchy == null) {
        writer.println("<table class=\"api\">");
        writer.println("<thead>");
        writer.println("<tr>");
        writer.println("<th class=\"type\">Type</th>");
        writer.println("<th class=\"path\">Path</th>");
        writer.println("<th class=\"description\">Description</th>");
        writer.println("</tr>");
        writer.println("</thead>");
        writer.println("<tbody>");
        SortedSet<Class<? extends ConfiguredObject>> managedCategories = new TreeSet<>(CLASS_COMPARATOR);
        managedCategories.addAll(finder.getManagedCategories());
        String pathStem = "/" + servletPathParts[1] + "/" + (servletPathParts.length == 2 ? "latest" : servletPathParts[2]) + "/";
        for (Class<? extends ConfiguredObject> category : managedCategories) {
            Class<? extends ConfiguredObject> objClass = category;
            String path = pathStem + category.getSimpleName().toLowerCase();
            writer.println("<tr>");
            writer.println("<td class=\"type\"><a href=" + ((servletPathParts.length == 2) ? "\"latest/" : "") + objClass.getSimpleName().toLowerCase() + "\">" + objClass.getSimpleName() + "</a></td>");
            writer.println("<td class=\"path\">" + path + "</td>");
            writer.println("<td class=\"description\">" + objClass.getAnnotation(ManagedObject.class).description() + "</td>");
            writer.println("</tr>");
        }
        writer.println("</tbody>");
        writer.println("</table>");
    } else {
        final List<Class<? extends ConfiguredObject>> types = _typeSpecialisations.get(configuredClass);
        writeCategoryDescription(writer, configuredClass);
        writeUsage(writer, request, hierarchy, configuredClass);
        writeTypes(writer, model, types);
        writeAttributes(writer, configuredClass, model, types);
        writeStatistics(writer, configuredClass, model, types);
        writeOperations(writer, configuredClass, model, types);
        writeContext(writer, configuredClass, model, types);
    }
    writeFoot(writer);
}
Also used : Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) PrintWriter(java.io.PrintWriter)

Example 17 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BrokerQueryServlet method getAllObjects.

@Override
protected List<ConfiguredObject<?>> getAllObjects(final Broker<?> broker, final Class<? extends ConfiguredObject> category, final HttpServletRequest request) {
    if (category == Broker.class) {
        return Collections.<ConfiguredObject<?>>singletonList(broker);
    } else {
        final Model brokerModel = broker.getModel();
        List<Class<? extends ConfiguredObject>> hierarchy = new ArrayList<>();
        Class<? extends ConfiguredObject> element = category;
        while (element != null && element != Broker.class) {
            hierarchy.add(element);
            Class<? extends ConfiguredObject> parentType = brokerModel.getParentType(element);
            if (parentType == null) {
                break;
            } else {
                element = parentType;
            }
        }
        Collections.reverse(hierarchy);
        Collection<ConfiguredObject<?>> parents = Collections.<ConfiguredObject<?>>singletonList(broker);
        Collection<ConfiguredObject<?>> children = Collections.emptyList();
        for (Class<? extends ConfiguredObject> childClass : hierarchy) {
            children = new HashSet<>();
            for (ConfiguredObject<?> parent : parents) {
                children.addAll((Collection<? extends ConfiguredObject<?>>) parent.getChildren(childClass));
            }
            parents = children;
        }
        return new ArrayList<>(children);
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) Model(org.apache.qpid.server.model.Model) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 18 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectToMapConverter method incorporateChildrenIntoMap.

private void incorporateChildrenIntoMap(final ConfiguredObject confObject, Class<? extends ConfiguredObject> clazz, Map<String, Object> object, ConverterOptions converterOptions) {
    List<Class<? extends ConfiguredObject>> childTypes = new ArrayList<>(confObject.getModel().getChildTypes(clazz));
    Collections.sort(childTypes, new Comparator<Class<? extends ConfiguredObject>>() {

        @Override
        public int compare(final Class<? extends ConfiguredObject> o1, final Class<? extends ConfiguredObject> o2) {
            return o1.getSimpleName().compareTo(o2.getSimpleName());
        }
    });
    ConverterOptions childConverterOptions = new ConverterOptions(converterOptions, converterOptions.getDepth() - 1);
    for (Class<? extends ConfiguredObject> childClass : childTypes) {
        Collection children = confObject.getChildren(childClass);
        if (children != null) {
            List<? extends ConfiguredObject> sortedChildren = new ArrayList<ConfiguredObject>(children);
            if (Comparable.class.isAssignableFrom(childClass)) {
                Collections.sort((List) sortedChildren);
            } else {
                Collections.sort(sortedChildren, new Comparator<ConfiguredObject>() {

                    @Override
                    public int compare(final ConfiguredObject o1, final ConfiguredObject o2) {
                        return o1.getName().compareTo(o2.getName());
                    }
                });
            }
            List<Map<String, Object>> childObjects = new ArrayList<>();
            for (ConfiguredObject child : sortedChildren) {
                childObjects.add(convertObjectToMap(child, childClass, childConverterOptions));
            }
            if (!childObjects.isEmpty()) {
                String childTypeSingular = childClass.getSimpleName().toLowerCase();
                object.put(childTypeSingular + (childTypeSingular.endsWith("s") ? "es" : "s"), childObjects);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 19 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectToMapConverter method collectInheritedActualContext.

private void collectInheritedActualContext(ConfiguredObject<?> confObject, Map<String, Object> contextValues) {
    ConfiguredObject parent = confObject.getParent();
    if (parent != null) {
        collectInheritedActualContext(parent, contextValues);
    }
    Object value = confObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
    if (value instanceof Map) {
        contextValues.putAll((Map<String, Object>) value);
    }
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 20 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class MetaDataServlet method processOperations.

private Map<String, Map> processOperations(final Class<? extends ConfiguredObject> type, final Model model) {
    Collection<ConfiguredObjectOperation<?>> operations = model.getTypeRegistry().getOperations(type).values();
    Map<String, Map> attributeDetails = new LinkedHashMap<>();
    for (ConfiguredObjectOperation<?> operation : operations) {
        Map<String, Object> attrDetails = new LinkedHashMap<>();
        attrDetails.put("name", operation.getName());
        attrDetails.put("returnType", operation.getReturnType().getSimpleName());
        if (!"".equals(operation.getDescription())) {
            attrDetails.put("description", operation.getDescription());
        }
        List<OperationParameter> parameters = operation.getParameters();
        if (!parameters.isEmpty()) {
            Map<String, Map> paramDetails = new LinkedHashMap<>();
            for (OperationParameter param : parameters) {
                Map<String, Object> paramAttrs = new LinkedHashMap<>();
                paramAttrs.put("type", param.getType().getSimpleName());
                paramAttrs.put("mandatory", param.isMandatory());
                if (!"".equals(param.getDefaultValue())) {
                    paramAttrs.put("defaultValue", param.getDefaultValue());
                }
                paramDetails.put(param.getName(), paramAttrs);
            }
            attrDetails.put("parameters", paramDetails);
        }
        attributeDetails.put(operation.getName(), attrDetails);
    }
    return attributeDetails;
}
Also used : OperationParameter(org.apache.qpid.server.model.OperationParameter) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObjectOperation(org.apache.qpid.server.model.ConfiguredObjectOperation) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)91 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)28 List (java.util.List)23 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)22 LinkedHashMap (java.util.LinkedHashMap)20 UUID (java.util.UUID)20 Map (java.util.Map)18 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6 State (org.apache.qpid.server.model.State)6 Collection (java.util.Collection)5 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)5 Model (org.apache.qpid.server.model.Model)5 Preference (org.apache.qpid.server.model.preferences.Preference)5 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4