/** * Extracts a task id from the given configuration. * * @param config * @return the task id in the given configuration. * @throws RuntimeException if the configuration can't be parsed. */ public static String getTaskId(final Configuration config) { try { return Tang.Factory.getTang().newInjector(config).getNamedInstance(TaskConfigurationOptions.Identifier.class); } catch (final InjectionException ex) { throw new RuntimeException("Unable to determine task identifier. Giving up.", ex); } } }
/** * Extracts a context id from the given configuration. * * @param c * @return the context id in the given configuration. * @throws RuntimeException if the configuration can't be parsed. */ public static String getIdentifier(final Configuration c) { try { return Tang.Factory.getTang().newInjector(c).getNamedInstance( ContextIdentifier.class); } catch (final InjectionException e) { throw new RuntimeException("Unable to determine context identifier. Giving up.", e); } } }
.setIdentifier(injector.getNamedInstance(DriverIdentifier.class)) .setDriverMemory(injector.getNamedInstance(DriverMemory.class)) .setUserName(System.getProperty("user.name")) .setConfiguration(configurationSerializer.toString(driverConfiguration)); for (final String globalFileName : injector.getNamedInstance(JobGlobalFiles.class)) { LOG.log(Level.FINEST, "Adding global file: {0}", globalFileName); jbuilder.addGlobalFile(getFileResourceProto(globalFileName, ReefServiceProtos.FileType.PLAIN)); for (final String globalLibraryName : injector.getNamedInstance(JobGlobalLibraries.class)) { LOG.log(Level.FINEST, "Adding global library: {0}", globalLibraryName); jbuilder.addGlobalFile(getFileResourceProto(globalLibraryName, ReefServiceProtos.FileType.LIB)); for (final String localFileName : injector.getNamedInstance(DriverLocalFiles.class)) { LOG.log(Level.FINEST, "Adding local file: {0}", localFileName); jbuilder.addLocalFile(getFileResourceProto(localFileName, ReefServiceProtos.FileType.PLAIN)); for (final String localLibraryName : injector.getNamedInstance(DriverLocalLibraries.class)) { LOG.log(Level.FINEST, "Adding local library: {0}", localLibraryName); jbuilder.addLocalFile(getFileResourceProto(localLibraryName, ReefServiceProtos.FileType.LIB));
/** * 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(); }