Search in sources :

Example 1 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class ComponentScheduler method requiresThreadPool.

private boolean requiresThreadPool(Component c, String parallel) {
    // The component declared from our DM Activator can not be parallel.
    ComponentDeclaration decl = c.getComponentDeclaration();
    if (ComponentScheduler.class.getName().equals(decl.getName())) {
        return false;
    }
    for (String prefix : parallel.trim().split(",")) {
        prefix = prefix.trim();
        boolean not = prefix.startsWith("!");
        if (not) {
            prefix = prefix.substring(1).trim();
        }
        if ("*".equals(prefix) || c.getComponentDeclaration().getClassName().startsWith(prefix)) {
            return !not;
        }
    }
    return false;
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration)

Example 2 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class ComponentExecutorFactoryImpl method getExecutorFor.

/**
 * Make concurrent a component only if it has a "parallel=true" property.
 */
@Override
public Executor getExecutorFor(Component component) {
    ComponentDeclaration decl = component.getComponentDeclaration();
    Dictionary<String, Object> properties = decl.getServiceProperties();
    if (properties != null && "true".equals(properties.get("parallel"))) {
        // the component will be handled in the threadpool.
        return m_threadPool;
    } else {
        // the component won't be handled in parallel.
        return null;
    }
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration)

Example 3 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class DMCommand method showTopComponents.

/**
 * Displays components callbacks (init/start/stop/destroy) elapsed time.
 * The components are sorted (the most time consuming components are displayed first).
 * @param max the max number of components to display (0 means all components)
 */
private void showTopComponents(int max) {
    List<Component> components = new ArrayList<>();
    for (DependencyManager manager : DependencyManager.getDependencyManagers()) {
        components.addAll(manager.getComponents());
    }
    Collections.sort(components, new Comparator<Component>() {

        @Override
        public int compare(Component c1, Component c2) {
            Map<String, Long> c1Times = c1.getComponentDeclaration().getCallbacksTime();
            Map<String, Long> c2Times = c2.getComponentDeclaration().getCallbacksTime();
            Long c1Start = c1Times.get("start");
            Long c2Start = c2Times.get("start");
            if (c1Start != null) {
                if (c2Start != null) {
                    return c1Start > c2Start ? 1 : -1;
                } else {
                    return 1;
                }
            } else {
                if (c2Start != null) {
                    return -1;
                } else {
                    return 0;
                }
            }
        }
    });
    Collections.reverse(components);
    System.out.printf("%-100s %10s %10s%n%n", "Top components (sorted by start duration time)", "[init time]", "[start time]");
    if (components.size() > 0) {
        System.out.println();
        max = max == 0 ? components.size() : Math.min(components.size(), max);
        for (int i = 0; i < components.size() && i < max; i++) {
            ComponentDeclaration decl = components.get(i).getComponentDeclaration();
            System.out.printf("%-100s %10d %10d%n", decl.getClassName(), decl.getCallbacksTime().get("init"), decl.getCallbacksTime().get("start"));
        }
    }
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) ArrayList(java.util.ArrayList) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component) Map(java.util.Map)

Example 4 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class DMCommand method dm.

/**
 * Dependency Manager "dm" command. We use gogo annotations, in order to automate documentation,
 * and also to automatically manage optional flags/options and parameters ordering.
 *
 * @param session the gogo command session, used to get some variables declared in the shell
 *        This parameter is automatically passed by the gogo runtime.
 * @param nodeps false means that dependencies are not displayed
 * @param compact true means informations are displayed in a compact format. This parameter can also be
 *        set using the "dependencymanager.compact" gogo shell variable.
 * @param notavail only unregistered components / unavailable dependencies are displayed
 * @param stats true means some statistics are displayed
 * @param services an osgi filter used to filter on some given osgi service properties.  This parameter can also be
 *        set using the "dependencymanager.services" gogo shell variable.
 * @param components a regular expression to match either component implementation class names.  This parameter can also be
 *        set using the "dependencymanager.components" gogo shell variable.
 * @param componentIds only components matching one of the specified components ids are displayed
 * @param bundleIds a list of bundle ids or symbolic names, used to filter on some given bundles
 */
@Descriptor("List dependency manager components")
public void dm(CommandSession session, @Descriptor("Hides component dependencies") @Parameter(names = { "nodeps", "nd" }, presentValue = "true", absentValue = "false") boolean nodeps, @Descriptor("Displays components using a compact form") @Parameter(names = { "compact", "cp" }, presentValue = "true", absentValue = "") String compact, @Descriptor("Only displays unavailable components") @Parameter(names = { "notavail", "na" }, presentValue = "true", absentValue = "false") boolean notavail, @Descriptor("Detects where are the root failures") @Parameter(names = { "wtf" }, presentValue = "true", absentValue = "false") boolean wtf, @Descriptor("Displays components statistics") @Parameter(names = { "stats", "stat", "st" }, presentValue = "true", absentValue = "false") boolean stats, @Descriptor("<OSGi filter used to filter some service properties>") @Parameter(names = { "services", "s" }, absentValue = "") String services, @Descriptor("<Regex(s) used to filter on component implementation class names (comma separated), can be negated using \"!\" prefix>") @Parameter(names = { "components", "c" }, absentValue = "") String components, @Descriptor("<List of component identifiers to display (comma separated)>") @Parameter(names = { "componentIds", "cid", "ci" }, absentValue = "") String componentIds, @Descriptor("<List of bundle ids or bundle symbolic names to display (comma separated)>") @Parameter(names = { "bundleIds", "bid", "bi", "b" }, absentValue = "") String bundleIds, @Descriptor("<Max number of top components to display (0=all)> This command displays components callbacks (init/start) times>") @Parameter(names = { "top" }, absentValue = "-1") int top) throws Throwable {
    boolean comp = Boolean.parseBoolean(getParam(session, ENV_COMPACT, compact));
    services = getParam(session, ENV_SERVICES, services);
    String[] componentsRegex = getParams(session, ENV_COMPONENTS, components);
    // list of bundle ids or bundle symbolic names
    ArrayList<String> bids = new ArrayList<String>();
    // list of component ids
    ArrayList<Long> cids = new ArrayList<Long>();
    // Parse and check componentIds option
    StringTokenizer tok = new StringTokenizer(componentIds, ", ");
    while (tok.hasMoreTokens()) {
        try {
            cids.add(Long.parseLong(tok.nextToken()));
        } catch (NumberFormatException e) {
            System.out.println("Invalid value for componentIds option");
            return;
        }
    }
    // Parse services filter
    Filter servicesFilter = null;
    try {
        if (services != null) {
            servicesFilter = m_context.createFilter(services);
        }
    } catch (InvalidSyntaxException e) {
        System.out.println("Invalid services OSGi filter: " + services);
        e.printStackTrace(System.err);
        return;
    }
    // Parse and check bundleIds option
    tok = new StringTokenizer(bundleIds, ", ");
    while (tok.hasMoreTokens()) {
        bids.add(tok.nextToken());
    }
    if (top != -1) {
        showTopComponents(top);
        return;
    }
    if (wtf) {
        wtf();
        return;
    }
    DependencyGraph graph = null;
    if (notavail) {
        graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.ALL_UNAVAILABLE);
    } else {
        graph = DependencyGraph.getGraph(ComponentState.ALL, DependencyState.ALL);
    }
    List<ComponentDeclaration> allComponents = graph.getAllComponents();
    Collections.sort(allComponents, COMPONENT_DECLARATION_COMPARATOR);
    long numberOfComponents = 0;
    long numberOfDependencies = 0;
    long lastBundleId = -1;
    for (ComponentDeclaration cd : allComponents) {
        Bundle bundle = cd.getBundleContext().getBundle();
        if (!matchBundle(bundle, bids)) {
            continue;
        }
        Component component = (Component) cd;
        String name = cd.getName();
        if (!mayDisplay(component, servicesFilter, componentsRegex, cids)) {
            continue;
        }
        numberOfComponents++;
        long bundleId = bundle.getBundleId();
        if (lastBundleId != bundleId) {
            lastBundleId = bundleId;
            if (comp) {
                System.out.println("[" + bundleId + "] " + compactName(bundle.getSymbolicName()));
            } else {
                System.out.println("[" + bundleId + "] " + bundle.getSymbolicName());
            }
        }
        if (comp) {
            System.out.print(" [" + cd.getId() + "] " + compactName(name) + " " + compactState(ComponentDeclaration.STATE_NAMES[cd.getState()]));
        } else {
            System.out.println(" [" + cd.getId() + "] " + name + " " + ComponentDeclaration.STATE_NAMES[cd.getState()]);
        }
        if (!nodeps) {
            List<ComponentDependencyDeclaration> dependencies = graph.getDependecies(cd);
            if (!dependencies.isEmpty()) {
                numberOfDependencies += dependencies.size();
                if (comp) {
                    System.out.print('(');
                }
                for (int j = 0; j < dependencies.size(); j++) {
                    ComponentDependencyDeclaration dep = dependencies.get(j);
                    String depName = dep.getName();
                    String depType = dep.getType();
                    int depState = dep.getState();
                    if (comp) {
                        if (j > 0) {
                            System.out.print(' ');
                        }
                        System.out.print(compactName(depName) + " " + compactState(depType) + " " + compactState(ComponentDependencyDeclaration.STATE_NAMES[depState]));
                    } else {
                        System.out.println("    " + depName + " " + depType + " " + ComponentDependencyDeclaration.STATE_NAMES[depState]);
                    }
                }
                if (comp) {
                    System.out.print(')');
                }
            }
        }
        if (comp) {
            System.out.println();
        }
    }
    if (stats) {
        System.out.println("Statistics:");
        System.out.println(" - Dependency managers: " + DependencyManager.getDependencyManagers().size());
        System.out.println(" - Components: " + numberOfComponents);
        if (!nodeps) {
            System.out.println(" - Dependencies: " + numberOfDependencies);
        }
    }
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) StringTokenizer(java.util.StringTokenizer) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Component(org.apache.felix.dm.Component) Descriptor(org.apache.felix.service.command.Descriptor)

Example 5 with ComponentDeclaration

use of org.apache.felix.dm.ComponentDeclaration in project felix by apache.

the class DMCommand method wtf.

public void wtf() {
    DependencyGraph graph = DependencyGraph.getGraph(ComponentState.UNREGISTERED, DependencyState.REQUIRED_UNAVAILABLE);
    List<ComponentDeclaration> unregisteredComponents = graph.getAllComponents();
    if (unregisteredComponents.isEmpty()) {
        System.out.println("No unregistered components found");
    } else {
        String message = unregisteredComponents.size() + " unregistered components found";
        System.out.println(message);
        System.out.println("----------------------------------------------------".substring(0, message.length()));
    }
    listResolvedBundles();
    listInstalledBundles();
    List<CircularDependency> circularDependencies = graph.getCircularDependencies();
    if (!circularDependencies.isEmpty()) {
        System.out.println("Circular dependencies:");
        printCircularDependencies(circularDependencies);
    }
    List<MissingDependency> missingConfigDependencies = graph.getMissingDependencies(CONFIGURATION);
    if (!missingConfigDependencies.isEmpty()) {
        System.out.println("The following configuration(s) are missing: ");
        printMissingDependencies(missingConfigDependencies);
    }
    List<MissingDependency> missingServiceDependencies = graph.getMissingDependencies(SERVICE);
    if (!missingServiceDependencies.isEmpty()) {
        System.out.println("The following service(s) are missing: ");
        printMissingDependencies(missingServiceDependencies);
    }
    List<MissingDependency> missingResourceDependencies = graph.getMissingDependencies(RESOURCE);
    if (!missingResourceDependencies.isEmpty()) {
        System.out.println("The following resource(s) are missing: ");
        printMissingDependencies(missingResourceDependencies);
    }
    List<MissingDependency> missingBundleDependencies = graph.getMissingDependencies(BUNDLE);
    if (!missingBundleDependencies.isEmpty()) {
        System.out.println("The following bundle(s) are missing: ");
        printMissingDependencies(missingBundleDependencies);
    }
    List<MissingDependency> missingCustomDependencies = graph.getMissingCustomDependencies();
    if (!missingCustomDependencies.isEmpty()) {
        System.out.println("The following custom dependency(ies) are missing: ");
        printMissingCustomDependencies(missingCustomDependencies);
    }
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) MissingDependency(org.apache.felix.dm.diagnostics.MissingDependency) DependencyGraph(org.apache.felix.dm.diagnostics.DependencyGraph) CircularDependency(org.apache.felix.dm.diagnostics.CircularDependency)

Aggregations

ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)18 Component (org.apache.felix.dm.Component)13 DependencyManager (org.apache.felix.dm.DependencyManager)12 ComponentDependencyDeclaration (org.apache.felix.dm.ComponentDependencyDeclaration)8 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)6 CircularDependency (org.apache.felix.dm.diagnostics.CircularDependency)4 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 ServiceDependency (org.apache.felix.dm.ServiceDependency)2 MissingDependency (org.apache.felix.dm.diagnostics.MissingDependency)2 URL (java.net.URL)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Descriptor (org.apache.felix.service.command.Descriptor)1 Bundle (org.osgi.framework.Bundle)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 LogService (org.osgi.service.log.LogService)1