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; }
@Override public int compare(ComponentDeclaration cd1, ComponentDeclaration cd2) { long id1 = cd1.getBundleContext().getBundle().getBundleId(); long id2 = cd2.getBundleContext().getBundle().getBundleId(); if(id1 == id2) { // sort by component id long cid1 = cd1.getId(); long cid2 = cd2.getId(); return cid1 > cid2 ? 1 : -1; } return id1 > id2 ? 1 : -1; } }
private boolean componentMustBeAddedToGraph(ComponentDeclaration cd) { if(m_componentState == ComponentState.ALL) { return true; } else if(m_componentState == ComponentState.UNREGISTERED) { return cd.getState() == ComponentDeclaration.STATE_UNREGISTERED; } return false; }
Bundle bundle = cd.getBundleContext().getBundle(); if(!matchBundle(bundle, bids)) { continue; String name = cd.getName(); if (!mayDisplay(component, servicesFilter, componentsRegex, cids)) { continue; 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()]);
/** * Is a dependency required by default ? * * @param c the component on which the dependency is added * @param ctx the bundle context * @return true if the dependency is required by default, false if not */ public static boolean isDependencyRequiredByDefault(Component c) { BundleContext ctx = ((ComponentContext) c).getBundleContext(); String defaultRequiredDependency = ctx.getProperty(DEFAULT_REQUIRED_DEPENDENCY); if (defaultRequiredDependency != null) { defaultRequiredDependency = defaultRequiredDependency.trim(); String componentName = c.getComponentDeclaration().getClassName(); for (String pkg : defaultRequiredDependency.split(",")) { if (componentName.startsWith(pkg)) { return true; } } } return false; }
/** * Checks if a component can be displayed. We make a logical OR between the three following conditions: * * - the component service properties are matching a given service filter ("services" option) * - the component implementation class name is matching some regex ("components" option) * - the component declaration name is matching some regex ("names" option) * * If some component ids are provided, then the component must also match one of them. */ private boolean mayDisplay(Component component, Filter servicesFilter, String[] components, List<Long> componentIds) { // Check component id if (componentIds.size() > 0) { long componentId = ((ComponentDeclaration) component).getId(); if (componentIds.indexOf(componentId) == -1) { return false; } } if (servicesFilter == null && components.length == 0) { return true; } // Check component service properties boolean servicesMatches = servicesMatches(component, servicesFilter); // Check components regexs, which may match component implementation class name boolean componentsMatches = componentMatches(((ComponentDeclaration) component).getClassName(), components); // Logical OR between service properties match and component service/impl match. return servicesMatches || componentsMatches; }
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"));
@Override public String toString() { String result = ""; for(ComponentDeclaration c : m_components) { result += " -> " + c.getName(); } return result; }
for(DependencyGraphNode p : node.getPredecessors()) { ComponentNode componentNode = (ComponentNode)p; Bundle bundle = componentNode.getComponentDeclaration().getBundleContext().getBundle(); MissingDependency missingDependency = new MissingDependency( node.getDependencyDeclaration().getName(),
@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; } } } });
/** * Checks if a given filter is matching some service properties possibly provided by a component */ private boolean servicesMatches(Component component, Filter servicesFilter) { boolean match = false; if (servicesFilter != null) { String[] services = ((ComponentDeclaration) component).getServices(); if (services != null) { Dictionary<String, Object> properties = component.getServiceProperties(); if (properties == null) { properties = new Hashtable<String, Object>(); } if (properties.get(Constants.OBJECTCLASS) == null) { properties.put(Constants.OBJECTCLASS, services); } match = servicesFilter.match(properties); } } return match; }
private void buildDependecyNodesAndEdges() { for(DependencyGraphNode node : m_componentToNode.values()) { ComponentNode componentNode = (ComponentNode)node; ComponentDependencyDeclaration[] dependencyDeclarations = componentNode.getComponentDeclaration().getComponentDependencies(); for(ComponentDependencyDeclaration cdd : dependencyDeclarations) { if(dependencyMustBeAddedToGraph(cdd)) { DependencyNode dependencyNode = new DependencyNode(cdd); m_dependencyToNode.put(cdd, dependencyNode); // add edges from the component node to newly created dependency node componentNode.addSuccessor(dependencyNode); // add edges from the newly created dependency node to the components // providing those dependencies (only applicable to service dependencies) List<ComponentNode> providerComponents = getProviderComponents(dependencyNode); for(ComponentNode p : providerComponents) { dependencyNode.addSuccessor(p); } } } } }
@Override public Object addingService(@SuppressWarnings("rawtypes") ServiceReference reference) { try { ServiceEventImpl event = new ServiceEventImpl(m_component, reference, null); if (obtainServiceBeforeInjecting()) { Object service = event.getEvent(); // will dereference the service object. if (service == null) { // service concurrently removed, ignore return null; } } return event; } catch (IllegalStateException e) { // most likely our bundle is being stopped. Only log an exception if our component is enabled. if (m_component.isActive()) { m_component.getLogger().warn("could not handle service dependency for component %s", e, m_component.getComponentDeclaration().getClassName()); } return null; } }
@Override public String toString() { return m_componentDeclaration.getName(); }
m_component.getComponentDeclaration().getClassName());
private void printCircularDependencies(List<CircularDependency> circularDependencies) { for(CircularDependency c : circularDependencies) { System.out.print(" *"); for(ComponentDeclaration cd : c.getComponents()) { System.out.print(" -> " + cd.getName()); } System.out.println(); } }
private void invokeSwap(String swapMethod, ServiceEventImpl previous, ServiceEventImpl current, Object[] instances) { if (m_debug) { System.out.println("invoke swap: " + swapMethod + " on component " + m_component + ", instances: " + Arrays.toString(instances) + " - " + ((ComponentDeclaration)m_component).getState());
private boolean componentProvidesDependency(ComponentNode componentNode, DependencyNode dependencyNode) { ComponentDeclaration cd = componentNode.getComponentDeclaration(); String dependencyName = dependencyNode.getDependencyDeclaration().getName(); String simpleName = getSimpleName(dependencyName); Properties properties = parseProperties(dependencyName); String componentName = cd.getName(); String simpleComponentName = componentName; int cuttOff = simpleComponentName.indexOf("("); if (cuttOff != -1) { simpleComponentName = simpleComponentName.substring(0, cuttOff).trim(); } for (String serviceName : simpleComponentName.split(",")) { if (simpleName.equals(serviceName.trim()) && doPropertiesMatch(properties, parseProperties(componentName))) { return true; } } return false; }