Creates the velocity context, adding process variables as parameters.
179413
protected VelocityContext createVelocityContext() throws ActivityException {
        try {
            VelocityContext context = null;
            String toolboxFile = getAttributeValueSmart(VELOCITY_TOOLBOX_FILE);
            if (toolboxFile != null && FileHelper.fileExistsOnClasspath(toolboxFile)) {
                throw new ActivityException("TODO: Velocity Toolbox Support");
                // XMLToolboxManager toolboxManager = new XMLToolboxManager();
                // toolboxManager.load(FileHelper.fileInputStreamFromClasspath(toolboxFile));
                // context = new VelocityContext(toolboxManager.getToolbox(toolboxFile));
            }
            else {
                context = new VelocityContext();
            }

            Process processVO = getMainProcessDefinition();
            List<Variable> varVOs = processVO.getVariables();
            for (Variable variableVO : varVOs) {
              String variableName = variableVO.getName();
              Object variableValue = getVariableValue(variableName);
              context.put(variableName, variableValue);
            }

            return context;
        }
        catch (Exception ex) {
            throw new ActivityException(-1, ex.getMessage(), ex);
        }
    }
579094
@Initialize(scope = Scope.SCENARIO)
    public void initializeContextVariables() {
        Properties p = new HandlerConfigLoader().loadProperties(configurationManager, "context");
        for ( Map.Entry e : p.entrySet()) {
            ChorusContext.getContext().put(e.getKey().toString(), e.getValue().toString());
        }
    }
750491
static TrialContext makeContext(UUID trialId, int trialNumber, Experiment experiment) {
    return new TrialContext(trialId, trialNumber, experiment);
  }
103624
def create_context(self, message_queue, task_id):
        
        params = (self.settings.dest_directory, self.file_url.json_data, self.seek_amt, self.bytes_to_read)
        return DownloadContext(self.settings, params, message_queue, task_id)
703358
def produce_context(namespace, context_id, max_delay=None):
    """"""
    try:
        context_obj = get_context(namespace, context_id)
        logger.info("Found context '%s:%s'", namespace, context_id)
    except ContextError:
        logger.info("Context '%s:%s' not found", namespace, context_id)
        if max_delay is not None:
            max_delay = float(max_delay)
        logger.info("Context error handled with max_delay=%s", max_delay)
        if not max_delay \
                or arrival_delay_greater_than(context_id, max_delay):
            context_obj = {}
            logger.info(
                "Timeout: waited %s seconds for context '%s'",
                max_delay, context_id)
        else:
            msg = "Context '{}' not found: resorting".format(context_id)
            raise OutOfOrderError(msg)

    return context_obj
87735
def create_sequence(context)
      pid_callback = lambda do |sequence|
        @mutex.synchronize { @pid = sequence.pid }
      end
      return RightScale::ExecutableSequenceProxy.new(context, :pid_callback => pid_callback )
    end
480942
protected Parameter createSizeParameter(ParameterContext context) {
        ModelReference intModel = createModelRefFactory(context).apply(resolver.resolve(Integer.TYPE));
        return new ParameterBuilder()
            .name(getSizeName())
            .parameterType(SIZE_TYPE)
            .modelRef(intModel)
            .description(SIZE_DESCRIPTION)
            .build();
    }
87471
def _setup(self):
        ""
        self.example.error = None
        self.example.traceback = ''
        # inject function contexts from parent functions
        c = Context(parent=self.context)
        #for parent in reversed(self.example.parents):
        #    c._update_properties(locals_from_function(parent))
        self.context = c
        if self.is_root_runner:
            run.before_all.execute(self.context)
        self.example.before(self.context)
150973
@SuppressWarnings("unchecked")
    void initThreadContext(WSContextService contextSvc, Map<String, String> execProps) {
        threadContext = contextSvc.captureThreadContext(execProps);
    }
63043
public void generate(GeneratorOutput genOut) throws CodeGenerationException
    {
        //
        // Create a new VelocityContext
        //
        VelocityContext vc = new VelocityContext();

        //
        // Transfer any code generation properties excepted by the templates into the context
        // 
        HashMap<String,Object> genContext = genOut.getContext();
        for(String key : genContext.keySet())
            vc.put(key, genContext.get(key));

        try
        {
            Writer genWriter = genOut.getWriter();
            Template template = getTemplate(genOut.getTemplateName());
            template.merge(vc, genWriter);    
            genWriter.close();
        }
        // never wrap RuntimeException
        catch (RuntimeException re) {
            throw re;
        }
        catch (Exception e) {
            throw new CodeGenerationException(e);
        }
    }
169784
@Override
	public Context create(String name, Tree params, CallOptions.Options opts, PacketStream stream, Context parent) {

		// Generate ID
		String id = uid.nextUID();

		// Create new Context
		if (parent == null) {
			return new Context(serviceInvoker, eventbus, id, name, params, opts, stream);
		}

		// Merge meta block
		if (parent.params != null) {
			Tree parentMeta = parent.params.getMeta(false);
			if (parentMeta != null && !parentMeta.isEmpty()) {
				Tree currentMeta = params.getMeta(true);
				if (currentMeta.isEmpty()) {
					currentMeta.setObject(parentMeta.asObject());
				} else {
					currentMeta.copyFrom(parentMeta, false);
				}
			}
		}

		// Verify call level
		if (maxCallLevel > 0 && parent.level >= maxCallLevel) {
			throw new MaxCallLevelError(broker.getNodeID(), maxCallLevel);
		}

		// Create context (nested call)
		return new Context(id, name, params, opts, stream, parent);
	}
283327
function do_create_context(context) {
		var context = context || {};
		
		if(!context.replace) {
			context.replace = (function(chunk, context, bodies, params) {
					return chunk.tap(function(data) {
						return (params.from && params.to && (data === params.from) ) ? params.to : data;
					}).render(bodies.block, context).untap();
				});
		}
		
		if(!context.toFixed) {
			context.toFixed = (function(chunk, context, bodies, params) {
					return chunk.tap(function(data) {
						return parseFloat(data).toFixed(params.x || 0);
					}).render(bodies.block, context).untap();
				}); // end of context
		}
		
		return context;
	}
386917
def add_variables_to_context(generator):
    ''''''
    context = generator.context             # minimize attr lookup
    context['relpath_to_site'] = relpath_to_site
    context['main_siteurl'] = _MAIN_SITEURL
    context['main_lang'] = _MAIN_LANG
    context['lang_siteurls'] = _SITE_DB
    current_lang = generator.settings['DEFAULT_LANG']
    extra_siteurls = _SITE_DB.copy()
    extra_siteurls.pop(current_lang)
    context['extra_siteurls'] = extra_siteurls
1254409
public static VelocityContext parseRequest(VelocityContext context, javax.servlet.http.HttpServletRequest request) {
		final Enumeration<String> attrs = request.getAttributeNames();
		if (attrs != null) {
			String attrName = null;
			while (attrs.hasMoreElements()) {
				attrName = attrs.nextElement();
				context.put(attrName, request.getAttribute(attrName));
			}
		}
		return context;
	}
520
public static void toFile(Template template, VelocityContext context, String destPath) {
		PrintWriter writer = null;
		try {
			writer = FileUtil.getPrintWriter(destPath, Velocity.getProperty(Velocity.INPUT_ENCODING).toString(), false);
			merge(template, context, writer);
		} catch (IORuntimeException e) {
			throw new UtilException(e, "Write Velocity content to [{}] error!", destPath);
		} finally {
			IoUtil.close(writer);
		}
	}
837659
public static VelocityContext parseSession(VelocityContext context, javax.servlet.http.HttpSession session) {
		if (null != session) {
			final Enumeration<String> sessionAttrs = session.getAttributeNames();
			if (sessionAttrs != null) {
				String attrName = null;
				while (sessionAttrs.hasMoreElements()) {
					attrName = sessionAttrs.nextElement();
					context.put(attrName, session.getAttribute(attrName));
				}
			}
		}
		return context;
	}
521679
def _create_process_mixer_instance(self, instance):
        
        endpoint = instance.get('mixer_endpoint')
        if endpoint is None:
            raise CheckException("Unable to find mixer_endpoint in config file.")

        process_mixer_instance = deepcopy(instance)
        process_mixer_instance.update(
            {
                'namespace': self.MIXER_NAMESPACE,
                'prometheus_url': endpoint,
                'metrics': [
                    {
                        'go_gc_duration_seconds': 'go.gc_duration_seconds',
                        'go_goroutines': 'go.goroutines',
                        'go_info': 'go.info',
                        'go_memstats_alloc_bytes': 'go.memstats.alloc_bytes',
                        'go_memstats_alloc_bytes_total': 'go.memstats.alloc_bytes_total',
                        'go_memstats_buck_hash_sys_bytes': 'go.memstats.buck_hash_sys_bytes',
                        'go_memstats_frees_total': 'go.memstats.frees_total',
                        'go_memstats_gc_cpu_fraction': 'go.memstats.gc_cpu_fraction',
                        'go_memstats_gc_sys_bytes': 'go.memstats.gc_sys_bytes',
                        'go_memstats_heap_alloc_bytes': 'go.memstats.heap_alloc_bytes',
                        'go_memstats_heap_idle_bytes': 'go.memstats.heap_idle_bytes',
                        'go_memstats_heap_inuse_bytes': 'go.memstats.heap_inuse_bytes',
                        'go_memstats_heap_objects': 'go.memstats.heap_objects',
                        'go_memstats_heap_released_bytes': 'go.memstats.heap_released_bytes',
                        'go_memstats_heap_sys_bytes': 'go.memstats.heap_sys_bytes',
                        'go_memstats_last_gc_time_seconds': 'go.memstats.last_gc_time_seconds',
                        'go_memstats_lookups_total': 'go.memstats.lookups_total',
                        'go_memstats_mallocs_total': 'go.memstats.mallocs_total',
                        'go_memstats_mcache_inuse_bytes': 'go.memstats.mcache_inuse_bytes',
                        'go_memstats_mcache_sys_bytes': 'go.memstats.mcache_sys_bytes',
                        'go_memstats_mspan_inuse_bytes': 'go.memstats.mspan_inuse_bytes',
                        'go_memstats_mspan_sys_bytes': 'go.memstats.mspan_sys_bytes',
                        'go_memstats_next_gc_bytes': 'go.memstats.next_gc_bytes',
                        'go_memstats_other_sys_bytes': 'go.memstats.other_sys_bytes',
                        'go_memstats_stack_inuse_bytes': 'go.memstats.stack_inuse_bytes',
                        'go_memstats_stack_sys_bytes': 'go.memstats.stack_sys_bytes',
                        'go_memstats_sys_bytes': 'go.memstats.sys_bytes',
                        'go_threads': 'go.threads',
                        'grpc_server_handled_total': 'grpc.server.handled_total',
                        'grpc_server_handling_seconds': 'grpc.server.handling_seconds',
                        'grpc_server_msg_received_total': 'grpc.server.msg_received_total',
                        'grpc_server_msg_sent_total': 'grpc.server.msg_sent_total',
                        'grpc_server_started_total': 'grpc.server.started_total',
                        'mixer_adapter_dispatch_count': 'adapter.dispatch_count',
                        'mixer_adapter_dispatch_duration': 'adapter.dispatch_duration',
                        'mixer_adapter_old_dispatch_count': 'adapter.old_dispatch_count',
                        'mixer_adapter_old_dispatch_duration': 'adapter.old_dispatch_duration',
                        'mixer_config_resolve_actions': 'config.resolve_actions',
                        'mixer_config_resolve_count': 'config.resolve_count',
                        'mixer_config_resolve_duration': 'config.resolve_duration',
                        'mixer_config_resolve_rules': 'config.resolve_rules',
                        'process_cpu_seconds_total': 'process.cpu_seconds_total',
                        'process_max_fds': 'process.max_fds',
                        'process_open_fds': 'process.open_fds',
                        'process_resident_memory_bytes': 'process.resident_memory_bytes',
                        'process_start_time_seconds': 'process.start_time_seconds',
                        'process_virtual_memory_bytes': 'process.virtual_memory_bytes',
                    }
                ],
                # Defaults that were set when istio was based on PrometheusCheck
                'send_monotonic_counter': instance.get('send_monotonic_counter', False),
                'health_service_check': instance.get('health_service_check', False),
            }
        )

        return process_mixer_instance