/*
(non-Javadoc)

@see javax.jms.ConnectionFactory#createContext()
325108
@Override
    public JMSContext createContext() throws JMSRuntimeException, JMSSecurityRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createContext");

        JMSContext jmsContext = null;
        try {

            // Pass sessionMode as AUTO_ACKNOWLEDGE. The sessionMode is used to create a session.In simplified
            // API(JMS 2.0), AUTO_ACKNOWLEDGE is the default sessionMode  
            jmsContext = createContext(null, null, JMSContext.AUTO_ACKNOWLEDGE);

        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "createContext");
        }
        return jmsContext;
    }
517271
public static ContextLoaderListener createSpringContextLoader(final WebApplicationContext webApplicationContext) {
        return new ContextLoaderListener() {
            @SuppressWarnings("unchecked")
            @Override
            protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
                return webApplicationContext;
            }
        };
    }
877176
protected final void setContext(@NonNull final Context context) {
        Condition.INSTANCE.ensureNotNull(context, "The context may not be null");
        this.context = context;
    }
181216
static final Context context(Element match, int matchIndex, int matchSize, Element element, int elementIndex, int elementSize) {
        return new DefaultContext(match, matchIndex, matchSize, element, elementIndex, elementSize);
    }
626948
@Benchmark
  @BenchmarkMode(Mode.SampleTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public StatsTraceContext newClientContext() {
    return StatsTraceContext.newClientContext(CallOptions.DEFAULT, Attributes.EMPTY, emptyMetadata);
  }
211899
@Override
    protected WeldCreationalContext<T> getCreationalContext(ManagedObjectInvocationContext<T> invocationContext, boolean nonContextual) throws ManagedObjectException {

        ManagedObjectContext moc;
        // for managed bean case, if invocation context is not null, use that
        if (invocationContext != null) {
            moc = invocationContext.getManagedObjectContext();

        } else {
            //otherwise, use the one created when creating this object(annotated with scope)
            moc = createContext(nonContextual);
        }
        @SuppressWarnings("unchecked")
        WeldCreationalContext<T> creationalContext = moc.getContextData(WeldCreationalContext.class);
        return creationalContext;
    }
339661
@Override
    public OrderingContext createOrderingContext()

                    throws SIConnectionUnavailableException, SIConnectionDroppedException,
                    SIErrorException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConnection.tc, "createOrderingContext", this);

        // Check that the connection isn't closed.
        checkNotClosed();

        OrderingContext context = new OrderingContextImpl();

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnection.tc, "createOrderingContext", context);

        return context;
    }
1157884
public Context getContext() {
		if (context == null) {
			context = Model.getSingleton().getSession().getContext(this.contextId);
		}
		return context;
	}
71421
@Override
    protected BaseContext createContext() {
        AppContextImpl context = getAppContext();
        RoomContextImpl answer = new RoomContextImpl();
        answer.init(context, getClass());
        return answer;
    }
486152
public void createUISharedContext(Context context) {
		if (session != null) {
			uiContexts.put(context.getIndex(), context.duplicate());
		}
	}
560046
public static void injectContextProxiesAndApplication(AbstractResourceInfo cri,
                                                          Object instance,
                                                          Application app,
                                                          ProviderFactory factory) {

        /** inject proxy for singleton only */
        if (!cri.isSingleton())
            return;

        /** application inject has been done earlier. @see LibertyJaxRsServerFactoryBean.injectContextApplication() */
        if (cri instanceof ApplicationInfo)
            return;

        JaxRsFactoryBeanCustomizer beanCustomizer = InjectionRuntimeContextHelper.findBeanCustomizer(instance.getClass(), cri.getBus());
        Boolean isManagedBean = beanCustomizer == null ? false : true;

        InjectionRuntimeContext irc = InjectionRuntimeContextHelper.getRuntimeContext();
        synchronized (instance) {
            for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) {
                Method method = entry.getValue();
                Object value = null;
                Class<?> cls = method.getParameterTypes()[0];
                if (cls == Application.class) {
                  value = app;
                } else if (VALUE_CONTEXTS.contains(cls.getName()) && factory != null) {
                    ContextProvider<?> p = factory.createContextProvider(cls, null);
                    if (p != null) {
                        value = p.createContext(null);
                    }
                } else {
                    value = cri.getContextSetterProxy(method);
                }

                if (isManagedBean)
                    irc.setRuntimeCtxObject(entry.getKey().getName(), value);
                else
                    InjectionUtils.injectThroughMethod(instance, method, value);
            }

            for (Field f : cri.getContextFields()) {
                Object value = null;
                Class<?> cls = f.getType();
                if (cls == Application.class) {
                    value = app;
                } else if (VALUE_CONTEXTS.contains(cls.getName()) && factory != null) {
                    ContextProvider<?> p = factory.createContextProvider(cls, null);
                    if (p != null) {
                        value = p.createContext(null);
                    }
                } else {
                    value = cri.getContextFieldProxy(f);
                }

                if (isManagedBean)
                    irc.setRuntimeCtxObject(f.getType().getName(), value);
                else
                    InjectionUtils.injectFieldValue(f, instance, value);
            }
        }

        Object o = null;
        //replace singleton resource after context injection is done.
        if (isManagedBean && (cri instanceof ClassResourceInfo)) {
            o = beanCustomizer.onSingletonServiceInit(instance,
                                                      InjectionRuntimeContextHelper.getBeanCustomizerContext(beanCustomizer, cri.getBus()));

            SingletonResourceProvider sp = new SingletonResourceProvider(o);
            ((ClassResourceInfo) cri).setResourceProvider(sp);
            instance = o;
        }

        if (!isManagedBean && (cri instanceof ClassResourceInfo))
        {
            //call postConstruct method for singleton resource which are non-CDI/EJB
            Method postConstructMethod = ResourceUtils.findPostConstructMethod(instance.getClass());
            InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod);
        }

    }
11869
public static ServletContextHandler create(Map<String, WebSocketHandlerWrapper> webSocketHandlers,
                                               Optional<Integer> webSocketIdleTimeoutMillis) {
        ServletContextHandler webSocketServletContextHandler = null;
        if (webSocketHandlers != null) {
            try {
                webSocketServletContextHandler = new ServletContextHandler(null, "/", true, false);
                WebSocketUpgradeFilter webSocketUpgradeFilter = WebSocketUpgradeFilter.configureContext(webSocketServletContextHandler);
                if (webSocketIdleTimeoutMillis.isPresent()) {
                    webSocketUpgradeFilter.getFactory().getPolicy().setIdleTimeout(webSocketIdleTimeoutMillis.get());
                }
                // Since we are configuring WebSockets before the ServletContextHandler and WebSocketUpgradeFilter is
                // even initialized / started, then we have to pre-populate the configuration that will eventually
                // be used by Jetty's WebSocketUpgradeFilter.
                NativeWebSocketConfiguration webSocketConfiguration = (NativeWebSocketConfiguration) webSocketServletContextHandler
                    .getServletContext().getAttribute(NativeWebSocketConfiguration.class.getName());
                for (String path : webSocketHandlers.keySet()) {
                    WebSocketCreator webSocketCreator = WebSocketCreatorFactory.create(webSocketHandlers.get(path));
                    webSocketConfiguration.addMapping(new ServletPathSpec(path), webSocketCreator);
                }
            } catch (Exception ex) {
                logger.error("creation of websocket context handler failed.", ex);
                webSocketServletContextHandler = null;
            }
        }
        return webSocketServletContextHandler;
    }
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);
	}
342458
protected SQLListenerContextImpl startContext(Connection connection, QueryMetadata metadata, RelationalPath<?> entity) {
        SQLListenerContextImpl context = new SQLListenerContextImpl(metadata, connection, entity);
        listeners.start(context);
        return context;
    }
272753
@Override
	public final Connection createConnection() throws JMSException
    {
    	String username = getStringProperty(Context.SECURITY_PRINCIPAL,null);
    	String password = getStringProperty(Context.SECURITY_CREDENTIALS,null);
    	
        return createConnection(username,password);
    }
1001144
@Bean(name = "beanManager")
    @ClientScope
    protected BeanManager createManager(RemotingContext remotingContext) {
        Assert.requireNonNull(remotingContext, "remotingContext");
        return remotingContext.getBeanManager();
    }
421246
function createContext(message) {

	var message = message || {},
		context = {}
	
	context.headers$ = _.omit(message.properties || {}, 'headers')
	context.amqp$    = message.fields     || {}
	context.req      = {}
	context.res      = {}

	if (message.content) {
		if (message.content instanceof Buffer)
			context.req = JSON.parse(message.content.toString())
		else 
			context.req = message.content
	}

	if (message.properties.headers)
		_.merge(context.headers$, message.properties.headers)

	context.service  = this
	context.invoke   = this.invoke.bind(this)
	context.command  = this.command.bind(this)
	context.publish  = this.publish.bind(this)
	context.sleep    = this.sleep.bind(this)
	context.log      = this.log

	return context
}