Search in sources :

Example 1 with NoSuchComponentException

use of org.osgi.service.blueprint.container.NoSuchComponentException in project aries by apache.

the class BlueprintRepository method reCreateInstance.

public void reCreateInstance(String name) {
    ExecutionContext oldContext = ExecutionContext.Holder.setContext(this);
    try {
        Set<String> toCreate = new HashSet<String>();
        Set<String> deps = getInvertedDependencies().get(name);
        if (deps == null) {
            throw new NoSuchComponentException(name);
        }
        for (String dep : deps) {
            boolean ok = true;
            for (SatisfiableRecipe r : getAllRecipes(SatisfiableRecipe.class, dep)) {
                if (!r.isSatisfied()) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                toCreate.add(dep);
            }
        }
        createInstances(toCreate);
        for (String n : toCreate) {
            Recipe r = recipes.get(n);
            if (r instanceof ServiceRecipe) {
                ServiceRecipe sr = (ServiceRecipe) r;
                if (!sr.isRegistered()) {
                    sr.register();
                }
            }
        }
    } finally {
        ExecutionContext.Holder.setContext(oldContext);
    }
}
Also used : ExecutionContext(org.apache.aries.blueprint.di.ExecutionContext) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) NoSuchComponentException(org.osgi.service.blueprint.container.NoSuchComponentException) HashSet(java.util.HashSet)

Example 2 with NoSuchComponentException

use of org.osgi.service.blueprint.container.NoSuchComponentException in project aries by apache.

the class BlueprintURLContext method lookup.

@Override
public Object lookup(Name name) throws NamingException, ServiceUnavailableException {
    ServiceReference<BlueprintContainer> blueprintContainerRef = getBlueprintContainerRef(_callersBundle);
    Object result;
    try {
        BlueprintContainer blueprintContainer = _callersBundle.getBundleContext().getService(blueprintContainerRef);
        BlueprintName bpName;
        if (name instanceof BlueprintName) {
            bpName = (BlueprintName) name;
        } else if (_parentName != null) {
            bpName = new BlueprintName(_parentName.toString() + "/" + name.toString());
        } else {
            bpName = (BlueprintName) _parser.parse(name.toString());
        }
        if (bpName.hasComponent()) {
            String componentId = bpName.getComponentId();
            try {
                result = blueprintContainer.getComponentInstance(componentId);
            } catch (NoSuchComponentException nsce) {
                throw new NameNotFoundException(nsce.getMessage());
            }
        } else {
            result = new BlueprintURLContext(_callersBundle, bpName, _env);
        }
    } finally {
        _callersBundle.getBundleContext().ungetService(blueprintContainerRef);
    }
    return result;
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) NoSuchComponentException(org.osgi.service.blueprint.container.NoSuchComponentException)

Example 3 with NoSuchComponentException

use of org.osgi.service.blueprint.container.NoSuchComponentException in project aries by apache.

the class BlueprintRepository method doGetInstancesToDestroy.

protected void doGetInstancesToDestroy(Map<Recipe, Future<Object>> toDestroy, String name) {
    Recipe recipe = recipes.get(name);
    if (recipe != null) {
        if (recipe instanceof ServiceRecipe) {
            ((ServiceRecipe) recipe).unregister();
        }
        Future<Object> future = instances.remove(name);
        if (future != null && future.isDone()) {
            Set<String> deps = getInvertedDependencies().get(name);
            for (String dep : deps) {
                doGetInstancesToDestroy(toDestroy, dep);
            }
            toDestroy.put(recipe, future);
        }
    } else {
        throw new NoSuchComponentException(name);
    }
}
Also used : IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) NoSuchComponentException(org.osgi.service.blueprint.container.NoSuchComponentException)

Example 4 with NoSuchComponentException

use of org.osgi.service.blueprint.container.NoSuchComponentException in project aries by apache.

the class DependencyGraph method getSortedRecipes.

public LinkedHashMap<String, Recipe> getSortedRecipes(Collection<String> names) {
    // construct the graph
    Map<String, Node> nodes = new LinkedHashMap<String, Node>();
    for (String name : names) {
        Object object = repository.getObject(name);
        if (object == null) {
            throw new NoSuchComponentException(name);
        }
        if (object instanceof Recipe) {
            Recipe recipe = (Recipe) object;
            if (!recipe.getName().equals(name)) {
                throw new RuntimeException("Recipe '" + name + "' returned from the repository has name '" + name + "'");
            }
            createNode(name, recipe, nodes);
        }
    }
    // find all initial leaf nodes (and islands)
    List<Node> sortedNodes = new ArrayList<Node>(nodes.size());
    LinkedList<Node> leafNodes = new LinkedList<Node>();
    for (Node n : nodes.values()) {
        if (n.referenceCount == 0) {
            // move it directly to the finished list, so they are first
            if (n.references.size() == 0) {
                sortedNodes.add(n);
            } else {
                leafNodes.add(n);
            }
        }
    }
    // pluck the leaves until there are no leaves remaining
    while (!leafNodes.isEmpty()) {
        Node node = leafNodes.removeFirst();
        sortedNodes.add(node);
        for (Node ref : node.references) {
            ref.referenceCount--;
            if (ref.referenceCount == 0) {
                leafNodes.add(ref);
            }
        }
    }
    // unprocessed nodes in the graph, we have one or more curcuits
    if (sortedNodes.size() != nodes.size()) {
        findCircuit(nodes.values().iterator().next(), new ArrayList<Recipe>(nodes.size()));
        // find circuit should never fail, if it does there is a programming error
        throw new RuntimeException("Internal Error: expected a CircularDependencyException");
    }
    // return the recipes
    LinkedHashMap<String, Recipe> sortedRecipes = new LinkedHashMap<String, Recipe>();
    for (Node node : sortedNodes) {
        sortedRecipes.put(node.name, node.recipe);
    }
    return sortedRecipes;
}
Also used : RefRecipe(org.apache.aries.blueprint.di.RefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) ArrayList(java.util.ArrayList) NoSuchComponentException(org.osgi.service.blueprint.container.NoSuchComponentException) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

NoSuchComponentException (org.osgi.service.blueprint.container.NoSuchComponentException)4 Recipe (org.apache.aries.blueprint.di.Recipe)3 RefRecipe (org.apache.aries.blueprint.di.RefRecipe)3 CollectionRecipe (org.apache.aries.blueprint.di.CollectionRecipe)2 IdRefRecipe (org.apache.aries.blueprint.di.IdRefRecipe)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 ExecutionContext (org.apache.aries.blueprint.di.ExecutionContext)1 BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)1