/** * 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)"); }
@Override public void close() { lifecycle.close(); closed = true; }
/** * 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); } }
@Override public void close() { lifecycle.close(); closed = true; }
/** * 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)"); }
/** * 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); } }