/** * @param baseInjector base {@link Injector} to extend upon * @return an {@link Injector} which has {@link LocalMessageDispatcher} for testing. * @throws InjectionException when failed to inject {@link LocalMessageDispatcher} */ public static Injector forkInjector(final Injector baseInjector) throws InjectionException { final Injector injector = baseInjector .forkInjector(LocalMessageEnvironment.LOCAL_MESSAGE_ENVIRONMENT_CONFIGURATION); injector.getInstance(LocalMessageDispatcher.class); return injector; } }
/** * @param baseInjector base {@link Injector} to extend upon * @return an {@link Injector} which has {@link LocalMessageDispatcher} for testing. * @throws InjectionException when failed to inject {@link LocalMessageDispatcher} */ public static Injector forkInjector(final Injector baseInjector) throws InjectionException { final Injector injector = baseInjector .forkInjector(LocalMessageEnvironment.LOCAL_MESSAGE_ENVIRONMENT_CONFIGURATION); injector.getInstance(LocalMessageDispatcher.class); return injector; } }
/** * Instantiates a new Topology instance. * @param operatorName specified name of the operator * @param topologyClass specified topology type * @return Topology instance * @throws InjectionException */ public Topology getNewInstance(final Class<? extends Name<String>> operatorName, final Class<? extends Topology> topologyClass) throws InjectionException { final Injector newInjector = injector.forkInjector(); newInjector.bindVolatileParameter(OperatorNameClass.class, operatorName); return newInjector.getInstance(topologyClass); } }
@Inject private GroupCommClientImpl(@Parameter(SerializedGroupConfigs.class) final Set<String> groupConfigs, final GroupCommNetworkHandler groupCommNetworkHandler, final ConfigurationSerializer configSerializer, final Injector injector) { LOG.log(Level.FINEST, "GroupCommHandler-{0}", groupCommNetworkHandler); for (final String groupConfigStr : groupConfigs) { try { final Configuration groupConfig = configSerializer.fromString(groupConfigStr); final Injector forkedInjector = injector.forkInjector(groupConfig); final CommunicationGroupServiceClient commGroupClient = forkedInjector.getInstance(CommunicationGroupServiceClient.class); this.communicationGroups.put(commGroupClient.getName(), commGroupClient); } catch (final InjectionException | IOException e) { throw new RuntimeException("Unable to deserialize operator config", e); } } }
/** * Helper method to create a new EvaluatorManager instance. * * @param id identifier of the Evaluator * @param desc NodeDescriptor on which the Evaluator executes. * @return a new EvaluatorManager instance. */ private EvaluatorManager getNewEvaluatorManagerInstance(final String id, final EvaluatorDescriptorImpl desc) { LOG.log(Level.FINEST, "Creating Evaluator Manager for Evaluator ID {0}", id); final Injector child = this.injector.forkInjector(); try { child.bindVolatileParameter(EvaluatorManager.EvaluatorIdentifier.class, id); child.bindVolatileParameter(EvaluatorManager.EvaluatorDescriptorName.class, desc); } catch (final BindException e) { throw new RuntimeException("Unable to bind evaluator identifier and name.", e); } final EvaluatorManager result; try { result = child.getInstance(EvaluatorManager.class); } catch (final InjectionException e) { throw new RuntimeException("Unable to instantiate a new EvaluatorManager for Evaluator ID: " + id, e); } return result; }
/** * @param jobIdentifier * @param remoteIdentifier * @return * @throws BindException * @throws InjectionException */ private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier) throws BindException, InjectionException { final Injector child = this.injector.forkInjector(); child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier); child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier); return child.getInstance(RunningJobImpl.class); } }
/** * Extends {@code baseInjector} to have {@link LocalMessageEnvironment} instance for the given {@code senderId}. * * @param baseInjector provided by {@link LocalMessageDispatcher#getInjector()} * or {@link LocalMessageDispatcher#forkInjector(Injector)} * @param senderId the identifier for the sender * @return an {@link Injector} which has {@link LocalMessageDispatcher} instance for {@link MessageEnvironment} * @throws InjectionException when fails to inject {@link MessageEnvironment} */ public static Injector forkInjector(final Injector baseInjector, final String senderId) throws InjectionException { final Injector injector = baseInjector.forkInjector(TANG.newConfigurationBuilder() .bindNamedParameter(MessageParameters.SenderId.class, senderId).build()); injector.getInstance(MessageEnvironment.class); return injector; } }
/** * Extends {@code baseInjector} to have {@link LocalMessageEnvironment} instance for the given {@code senderId}. * * @param baseInjector provided by {@link LocalMessageDispatcher#getInjector()} * or {@link LocalMessageDispatcher#forkInjector(Injector)} * @param senderId the identifier for the sender * @return an {@link Injector} which has {@link LocalMessageDispatcher} instance for {@link MessageEnvironment} * @throws InjectionException when fails to inject {@link MessageEnvironment} */ public static Injector forkInjector(final Injector baseInjector, final String senderId) throws InjectionException { final Injector injector = baseInjector.forkInjector(TANG.newConfigurationBuilder() .bindNamedParameter(MessageParameters.SenderId.class, senderId).build()); injector.getInstance(MessageEnvironment.class); return injector; } }
/** * Instantiates the root context. * <p> * This also launches the initial task if there is any. * * @param injector * @param rootContextConfiguration * @param rootServiceConfiguration * @return ContextRuntime * @throws ContextClientCodeException */ private static ContextRuntime getRootContext(final Injector injector, final Configuration rootContextConfiguration, final Optional<Configuration> rootServiceConfiguration) throws ContextClientCodeException { final ContextRuntime result; if (rootServiceConfiguration.isPresent()) { final Injector rootServiceInjector; try { rootServiceInjector = injector.forkInjector(rootServiceConfiguration.get()); } catch (final BindException e) { throw new ContextClientCodeException(ContextClientCodeException.getIdentifier(rootContextConfiguration), Optional.<String>empty(), "Unable to instatiate the root context", e); } result = new ContextRuntime(rootServiceInjector, rootContextConfiguration); } else { result = new ContextRuntime(injector.forkInjector(), rootContextConfiguration); } return result; }
final Injector forkedInjector = injector.forkInjector(operatorConfig);
/** * Instantiates a new CommunicationGroupDriver instance. * @param groupName specified name of the communication group * @param topologyClass topology implementation * @param numberOfTasks minimum number of tasks needed in this group before start * @param customFanOut fanOut for TreeTopology * @return CommunicationGroupDriver instance * @throws InjectionException */ public CommunicationGroupDriver getNewInstance( final Class<? extends Name<String>> groupName, final Class<? extends Topology> topologyClass, final int numberOfTasks, final int customFanOut) throws InjectionException { final Injector newInjector = injector.forkInjector(); newInjector.bindVolatileParameter(CommGroupNameClass.class, groupName); newInjector.bindVolatileParameter(TopologyClass.class, topologyClass); newInjector.bindVolatileParameter(CommGroupNumTask.class, numberOfTasks); newInjector.bindVolatileParameter(TreeTopologyFanOut.class, customFanOut); return newInjector.getInstance(CommunicationGroupDriver.class); } }
final Injector childServiceInjector = this.serviceInjector.forkInjector(); final ContextRuntime newChildContext = new ContextRuntime(childServiceInjector, contextConfiguration, Optional.of(this));
new AvroConfigurationSerializer().fromString(rd.getSerializedConfiguration().toString()); final Injector runtimeInjector = rootInjector.forkInjector(config, runtimeConfig);
final Injector taskInjector = this.contextInjector.forkInjector(taskConfig); final TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class); taskRuntime.initialize();
this.serviceInjector.forkInjector(serviceConfiguration);
/** * Create a new ContextRuntime. * * @param serviceInjector the serviceInjector to be used. * @param contextConfiguration the Configuration for this context. * @throws ContextClientCodeException if the context cannot be instantiated. */ ContextRuntime(final Injector serviceInjector, final Configuration contextConfiguration, final Optional<ContextRuntime> parentContext) throws ContextClientCodeException { this.serviceInjector = serviceInjector; this.parentContext = parentContext; // Trigger the instantiation of the services try { final Set<Object> services = serviceInjector.getNamedInstance(Services.class); this.contextInjector = serviceInjector.forkInjector(contextConfiguration); this.contextLifeCycle = this.contextInjector.getInstance(ContextLifeCycle.class); } catch (BindException | InjectionException e) { final Optional<String> parentID = this.getParentContext().isPresent() ? Optional.of(this.getParentContext().get().getIdentifier()) : Optional.<String>empty(); throw new ContextClientCodeException( ContextClientCodeException.getIdentifier(contextConfiguration), parentID, "Unable to spawn context", e); } // Trigger the context start events on contextInjector. this.contextLifeCycle.start(); }