org.mozilla.javascript.Context.getThreadLocal()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(2.9k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.mozilla.javascript.Context.getThreadLocal()方法的一些代码示例,展示了Context.getThreadLocal()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getThreadLocal()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:getThreadLocal

Context.getThreadLocal介绍

[英]Get a value corresponding to a key.

Since the Context is associated with a thread it can be used to maintain values that can be later retrieved using the current thread.

Note that the values are maintained with the Context, so if the Context is disassociated from the thread the values cannot be retrieved. Also, if private data is to be maintained in this manner the key should be a java.lang.Object whose reference is not divulged to untrusted code.
[中]获取与键对应的值。
由于上下文与线程关联,因此可以使用它来维护值,这些值可以在以后使用当前线程检索。
请注意,这些值与上下文一起维护,因此如果上下文与线程解除关联,则无法检索这些值。此外,如果要以这种方式维护私有数据,则密钥应该是java。对象,其引用未泄露给不受信任的代码。

代码示例

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry

private ConfigurationContext getConfigContext(Context cx) throws CarbonException {
  Object configurationContextObject = cx
      .getThreadLocal(MashupConstants.AXIS2_CONFIGURATION_CONTEXT);
  if (configurationContextObject != null
    && configurationContextObject instanceof ConfigurationContext) {
    return (ConfigurationContext) configurationContextObject;
  } else {
    throw new CarbonException(
        "Error obtaining the Service Meta Data : Axis2 ConfigurationContext");
  }
}

代码示例来源:origin: io.apigee.trireme/trireme-util

@JSConstructor
@SuppressWarnings("unused")
public static Object construct(Context cx, Object[] args, Function ctorObj, boolean inNewExpr)
{
  if (!inNewExpr) {
    return cx.newObject(ctorObj, CLASS_NAME, args);
  }
  Scriptable context = objArg(args, 0, Scriptable.class, true);
  ScriptRunner runner = (ScriptRunner)cx.getThreadLocal(ScriptRunner.RUNNER);
  ContextImpl self = new ContextImpl();
  self.globalProxy = new Forwarder(runner.getScriptScope(), context);
  context.setParentScope(null);
  self.context = context;
  return self;
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry

public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj,
                    boolean inNewExpr) throws CarbonException {
  RegistryHostObject registryHostObject = new RegistryHostObject();
  if (args.length == 0) {
    AxisConfiguration axisConfig = registryHostObject.getConfigContext(cx).getAxisConfiguration();
    Object object = cx.getThreadLocal(MashupConstants.AXIS2_SERVICE);
    AxisService axisService;
    if (object instanceof AxisService) {
      axisService = (AxisService) object;
    } else {
      throw new CarbonException("Error obtaining the AxisService.");
    }
    String mashupAuthor = (String) axisService.getParameter(
        MashupConstants.MASHUP_AUTHOR).getValue();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    registryHostObject.registry = RegistryHostObjectContext.getUserRegistry(mashupAuthor, tenantId);
    return registryHostObject;
  } else {
    throw new CarbonException("Registry() constructor doesn't accept arguments.");
  }
}

相关文章

微信公众号

Context类方法