/** * Construct a new component cache. * * @param dir The cache directory (or {@code null} to disable disk-based caching). * @param loader The class loader to be used when loading components from disk (or {@code null} if not needed). */ public ComponentCache(@Nullable Path dir, @Nullable ClassLoader loader) { cacheDir = dir; classLoader = loader; instantiator = NodeInstantiator.create(); cache = new ConcurrentHashMap<>(); }
Object instantiate(@Nonnull DAGNode<Component, Dependency> node) throws InjectionException { DAGNode<Component,Dependency> n2 = processNode(node, node); return instantiator.instantiate(n2); }
public <T> T tryGetInstance(QualifierMatcher qmatch, Class<T> type) throws InjectionException { DAGNode<Component, Dependency> node = GraphtUtils.findSatisfyingNode(graph, qmatch, type); return node != null ? type.cast(instantiator.instantiate(node)) : null; }
/** * Create a node processor that will instantiate nodes. It will return nodes whose satisfactions * have been replaced with instance satisfactions containing the instance. * * @return The node processor. */ public static NodeProcessor instantiate() { return instantiate(NodeInstantiator.create()); }
@Nonnull @Override public Object apply(@Nullable DAGNode<Component, Dependency> input) { Preconditions.checkNotNull(input, "input node"); try { return instantiate(input); } catch (InjectionException e) { throw new RecommenderBuildException("cannot instantiate " + input.getLabel(), e); } }
/** * Create a new static injector. * * @param g The object graph. */ public StaticInjector(DAGNode<Component,Dependency> g) { graph = g; lifecycle = new LifecycleManager(); instantiator = NodeInstantiator.create(lifecycle); capture = new RuntimeException("Static injector instantiated (backtrace shows instantiation point)"); }
@Nullable public <T> T tryGetInstance(Class<T> type) throws InjectionException { Desire d = Desires.create(null, type, true); DAGEdge<Component, Dependency> e = graph.getOutgoingEdgeWithLabel(l -> l.hasInitialDesire(d)); if (e != null) { return type.cast(instantiator.instantiate(e.getTail())); } else { DAGNode<Component, Dependency> node = GraphtUtils.findSatisfyingNode(graph, Qualifiers.matchDefault(), type); if (node != null) { return type.cast(instantiator.instantiate(node)); } else { return null; } } }
/** * Instantiate the recommender graph. This requires the graph to have been resolved with a real * DAO instance, not just a class, if anything references the DAO. Use {@link * LenskitConfiguration#buildGraph()} to get such a graph. The result of instantiating a graph * is that all shareable nodes will be instantiated. * * @return A new recommender graph with all shareable nodes pre-instantiated. * @throws RecommenderBuildException If there is an error instantiating the graph. */ public DAGNode<Component,Dependency> instantiate() throws RecommenderBuildException { try (LifecycleManager lm = new LifecycleManager()) { NodeInstantiator instantiator = NodeInstantiator.create(lm); // TODO Verify that no sharable components are lifecycle-managed return replaceShareableNodes(NodeProcessors.instantiate(instantiator)); } catch (InjectionException e) { throw new RecommenderBuildException("Recommender instantiation failed", e); } }
Object result = instantiator.instantiate(node); if (result == null) {
/** * Construct a new component cache. * * @param dir The cache directory (or {@code null} to disable disk-based caching). * @param loader The class loader to be used when loading components from disk (or {@code null} if not needed). */ public ComponentCache(@Nullable Path dir, @Nullable ClassLoader loader) { cacheDir = dir; classLoader = loader; instantiator = NodeInstantiator.create(); cache = new ConcurrentHashMap<>(); }
Object instantiate(@Nonnull DAGNode<Component, Dependency> node) throws InjectionException { DAGNode<Component,Dependency> n2 = processNode(node, node); return instantiator.instantiate(n2); }
/** * Create a node processor that will instantiate nodes. It will return nodes whose satisfactions * have been replaced with instance satisfactions containing the instance. * * @return The node processor. */ public static NodeProcessor instantiate() { return instantiate(NodeInstantiator.create()); }
public <T> T tryGetInstance(QualifierMatcher qmatch, Class<T> type) throws InjectionException { DAGNode<Component, Dependency> node = GraphtUtils.findSatisfyingNode(graph, qmatch, type); return node != null ? type.cast(instantiator.instantiate(node)) : null; }
/** * Create a new static injector. * * @param g The object graph. */ public StaticInjector(DAGNode<Component,Dependency> g) { graph = g; lifecycle = new LifecycleManager(); instantiator = NodeInstantiator.create(lifecycle); capture = new RuntimeException("Static injector instantiated (backtrace shows instantiation point)"); }
@Nonnull @Override public Object apply(@Nullable DAGNode<Component, Dependency> input) { Preconditions.checkNotNull(input, "input node"); try { return instantiate(input); } catch (InjectionException e) { throw new RecommenderBuildException("cannot instantiate " + input.getLabel(), e); } }
/** * Instantiate the recommender graph. This requires the graph to have been resolved with a real * DAO instance, not just a class, if anything references the DAO. Use {@link * LenskitConfiguration#buildGraph()} to get such a graph. The result of instantiating a graph * is that all shareable nodes will be instantiated. * * @return A new recommender graph with all shareable nodes pre-instantiated. * @throws RecommenderBuildException If there is an error instantiating the graph. */ public DAGNode<Component,Dependency> instantiate() throws RecommenderBuildException { try (LifecycleManager lm = new LifecycleManager()) { NodeInstantiator instantiator = NodeInstantiator.create(lm); // TODO Verify that no sharable components are lifecycle-managed return replaceShareableNodes(NodeProcessors.instantiate(instantiator)); } catch (InjectionException e) { throw new RecommenderBuildException("Recommender instantiation failed", e); } }
@Nullable public <T> T tryGetInstance(Class<T> type) throws InjectionException { Desire d = Desires.create(null, type, true); DAGEdge<Component, Dependency> e = graph.getOutgoingEdgeWithLabel(l -> l.hasInitialDesire(d)); if (e != null) { return type.cast(instantiator.instantiate(e.getTail())); } else { DAGNode<Component, Dependency> node = GraphtUtils.findSatisfyingNode(graph, Qualifiers.matchDefault(), type); if (node != null) { return type.cast(instantiator.instantiate(node)); } else { return null; } } }
Object result = instantiator.instantiate(node); if (result == null) {