/** * @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; } }
/** * Instantiate a launcher for the given Configuration. * * @param runtimeConfiguration the resourcemanager configuration to be used * @return a DriverLauncher based on the given resourcemanager configuration * @throws InjectionException on configuration errors */ public static DriverLauncher getLauncher(final Configuration runtimeConfiguration) throws InjectionException { return Tang.Factory.getTang() .newInjector(runtimeConfiguration, CLIENT_CONFIG) .getInstance(DriverLauncher.class); }
@Override public void registerRunTimeOptimizations(final Injector injector, final PubSubEventHandlerWrapper pubSubWrapper) { LOG.info("Register run-time optimizations to the PubSubHandler"); runtimePasses.forEach(runtimePass -> runtimePass.getEventHandlerClasses().forEach(runtimeEventHandlerClass -> { try { final RuntimeEventHandler runtimeEventHandler = injector.getInstance(runtimeEventHandlerClass); pubSubWrapper.getPubSubEventHandler() .subscribe(runtimeEventHandler.getEventClass(), runtimeEventHandler); } catch (final Exception e) { throw new RuntimeException(e); } })); } }
/** * 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); } }
@Override public void registerRunTimeOptimizations(final Injector injector, final PubSubEventHandlerWrapper pubSubWrapper) { LOG.info("Register run-time optimizations to the PubSubHandler"); runtimePasses.forEach(runtimePass -> runtimePass.getEventHandlerClasses().forEach(runtimeEventHandlerClass -> { try { final RuntimeEventHandler runtimeEventHandler = injector.getInstance(runtimeEventHandlerClass); pubSubWrapper.getPubSubEventHandler() .subscribe(runtimeEventHandler.getEventClass(), runtimeEventHandler); } catch (final Exception e) { throw new RuntimeException(e); } })); } }
@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); } } }
public static void main(final String[] args) throws BindException, InjectionException, InterruptedException { final Configuration c = TimerMock.CONF .set(TimerMockConf.MOCK_SLEEP_TIME, 1) .build(); final Timer t = Tang.Factory.getTang().newInjector(c).getInstance(Timer.class); System.out.println("Tick..."); t.sleep(); System.out.println("...tock."); }
public static void main(final String[] args) throws BindException, InjectionException { final Tang tang = Tang.Factory.getTang(); final JavaConfigurationBuilder cb = tang.newConfigurationBuilder(); final Configuration conf = cb.build(); final Injector injector = tang.newInjector(conf); final TimerV1 timer = injector.getInstance(TimerV1.class); try { System.out.println("Tick..."); timer.sleep(); System.out.println("Tock."); } catch (final InterruptedException e) { e.printStackTrace(); } }
/** * @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); } }
/** * The starting point of the executor. */ public static void main(final String[] args) throws Exception { final Injector injector = Tang.Factory.getTang().newInjector(parseCommandLine(args)); final REEFExecutor reefExecutor = injector.getInstance(REEFExecutor.class); reefExecutor.onStart(); } }
/** * Initializes injector by copying needed handlers. * @param runtimeInjector The injector to initialize * @throws InjectionException on configuration error. */ private void initializeInjector(final Injector runtimeInjector) throws InjectionException { copyEventHandler(runtimeInjector, RuntimeParameters.ResourceStatusHandler.class); copyEventHandler(runtimeInjector, RuntimeParameters.NodeDescriptorHandler.class); copyEventHandler(runtimeInjector, RuntimeParameters.ResourceAllocationHandler.class); copyEventHandler(runtimeInjector, RuntimeParameters.RuntimeStatusHandler.class); try { runtimeInjector.bindVolatileInstance(HttpServer.class, this.originalInjector.getInstance(HttpServer.class)); LOG.log(Level.INFO, "Binding http server for the runtime implementation"); } catch (final InjectionException e) { LOG.log(Level.INFO, "Http Server is not configured for the runtime", e); } }
/** * 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; } }
public static void main(final String[] args) throws Exception { setupLogging(); Tang.Factory.getTang() .newInjector(UnsafeHDInsightRuntimeConfiguration.fromEnvironment()) .getInstance(HDICLI.class).run(args); }
/** * Get all evaluator ids and send it back to response as JSON. */ private void writeEvaluatorsJsonOutput(final HttpServletResponse response) throws IOException { LOG.log(Level.INFO, "HttpServerReefEventHandler writeEvaluatorsJsonOutput is called"); try { final EvaluatorListSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(EvaluatorListSerializer.class); final AvroEvaluatorList evaluatorList = serializer.toAvro( this.reefStateManager.getEvaluators(), this.reefStateManager.getEvaluators().size(), this.reefStateManager.getStartTime()); writeResponse(response, serializer.toString(evaluatorList)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting EvaluatorListSerializer.", e); writeResponse(response, "Error in injecting EvaluatorListSerializer: " + e); } }
/** * Write Driver Info as JSON string to Response. */ private void writeDriverJsonInformation(final HttpServletResponse response) throws IOException { LOG.log(Level.INFO, "HttpServerReefEventHandler writeDriverJsonInformation invoked."); try { final DriverInfoSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(DriverInfoSerializer.class); final AvroDriverInfo driverInfo = serializer.toAvro( this.reefStateManager.getDriverEndpointIdentifier(), this.reefStateManager.getStartTime(), this.reefStateManager.getServicesInfo()); writeResponse(response, serializer.toString(driverInfo)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting DriverInfoSerializer.", e); writeResponse(response, "Error in injecting DriverInfoSerializer: " + e); } }
/** * Write Evaluator info as JSON format to HTTP Response. */ private void writeEvaluatorInfoJsonOutput( final HttpServletResponse response, final List<String> ids) throws IOException { try { final EvaluatorInfoSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(EvaluatorInfoSerializer.class); final AvroEvaluatorsInfo evaluatorsInfo = serializer.toAvro(ids, this.reefStateManager.getEvaluators()); writeResponse(response, serializer.toString(evaluatorsInfo)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting EvaluatorInfoSerializer.", e); writeResponse(response, "Error in injecting EvaluatorInfoSerializer: " + e); } }
/** * Instantiate REEF Launcher. This method is called from REEFLauncher.main(). * @param clockConfigPath Path to the local file that contains serialized configuration * of a REEF component to launch (can be either Driver or Evaluator). * @return An instance of the configured REEFLauncher object. */ private static REEFLauncher getREEFLauncher(final String clockConfigPath) { try { final Configuration clockArgConfig = TANG.newConfigurationBuilder() .bindNamedParameter(ClockConfigurationPath.class, clockConfigPath) .build(); return TANG.newInjector(clockArgConfig).getInstance(REEFLauncher.class); } catch (final BindException ex) { throw fatal("Error in parsing the command line", ex); } catch (final InjectionException ex) { throw fatal("Unable to instantiate REEFLauncher.", ex); } }
public static void main(final String[] argv) throws IOException, BindException, InjectionException { @SuppressWarnings("unchecked") final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder( (Class<? extends ExternalConstructor<?>>[]) new Class[]{FileParser.class}); final CommandLine cl = new CommandLine(cb); cl.processCommandLine(argv, Target.class, ClassHierarchyIn.class, ConfigurationIn.class, ConfigurationOut.class); final ValidateConfiguration bip = Tang.Factory.getTang().newInjector(cb.build()).getInstance(ValidateConfiguration.class); bip.validatePlan(); }