use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.
the class WebAppManager method clearTimeout.
public static void clearTimeout(final Context cx, final Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
JaggeryContext context = CommonManager.getJaggeryContext();
ServletContext servletContext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
String contextPath = servletContext.getContextPath();
RhinoTopLevel.clearTimeout(cx, thisObj, args, funObj);
List<String> taskIds = timeouts.get(contextPath);
taskIds.remove(String.valueOf(args[0]));
}
use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.
the class WebSocketHostObject method jsConstructor.
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws Exception {
int argsCount = args.length;
if (argsCount != 0) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, hostObjectName, argsCount, true);
}
WebSocketHostObject who = new WebSocketHostObject();
who.contextFactory = cx.getFactory();
JaggeryContext currentContext = (JaggeryContext) RhinoEngine.getContextProperty(EngineConstants.JAGGERY_CONTEXT);
JaggeryContext asyncContext = new JaggeryContext();
asyncContext.setEngine(currentContext.getEngine());
asyncContext.setScope(currentContext.getScope());
asyncContext.setTenantDomain(currentContext.getTenantDomain());
asyncContext.addProperty(Constants.SERVLET_CONTEXT, currentContext.getProperty(Constants.SERVLET_CONTEXT));
asyncContext.addProperty(LogHostObject.LOG_LEVEL, currentContext.getProperty(LogHostObject.LOG_LEVEL));
asyncContext.addProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER, currentContext.getProperty(FileHostObject.JAVASCRIPT_FILE_MANAGER));
asyncContext.addProperty(Constants.JAGGERY_CORE_MANAGER, currentContext.getProperty(Constants.JAGGERY_CORE_MANAGER));
asyncContext.addProperty(Constants.JAGGERY_INCLUDED_SCRIPTS, new HashMap<String, Boolean>());
asyncContext.addProperty(Constants.JAGGERY_INCLUDES_CALLSTACK, new Stack<String>());
asyncContext.addProperty(Constants.JAGGERY_REQUIRED_MODULES, new HashMap<String, ScriptableObject>());
who.asyncContext = asyncContext;
return who;
}
use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.
the class WebAppManager method setTimeout.
public static String setTimeout(final Context cx, final Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
JaggeryContext context = CommonManager.getJaggeryContext();
ServletContext servletContext = (ServletContext) context.getProperty(Constants.SERVLET_CONTEXT);
String contextPath = servletContext.getContextPath();
String taskId = RhinoTopLevel.setTimeout(cx, thisObj, args, funObj);
List<String> taskIds = timeouts.get(contextPath);
if (taskIds == null) {
taskIds = new ArrayList<String>();
timeouts.put(contextPath, taskIds);
}
taskIds.add(taskId);
return taskId;
}
use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.
the class JaggeryDeployerManager method addSessionCreatedListners.
private static void addSessionCreatedListners(Context context, JSONArray arr) {
if (arr != null) {
try {
JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(context.getServletContext());
CommonManager.setJaggeryContext(sharedContext);
RhinoEngine engine = sharedContext.getEngine();
org.mozilla.javascript.Context cx = engine.enterContext();
ServletContext servletContext = (ServletContext) sharedContext.getProperty(org.jaggeryjs.hostobjects.web.Constants.SERVLET_CONTEXT);
List<String> jsListeners = new ArrayList<String>();
Object[] scripts = arr.toArray();
for (Object script : scripts) {
if (!(script instanceof String)) {
log.error("Invalid value for initScripts/destroyScripts in jaggery.conf : " + script);
continue;
}
String path = (String) script;
path = path.startsWith("/") ? path : "/" + path;
Stack<String> callstack = CommonManager.getCallstack(sharedContext);
callstack.push(path);
jsListeners.add(path);
}
servletContext.setAttribute(JaggeryCoreConstants.JS_CREATED_LISTENERS, jsListeners);
} finally {
if (org.mozilla.javascript.Context.getCurrentContext() != null) {
RhinoEngine.exitContext();
}
}
}
}
use of org.jaggeryjs.scriptengine.engine.JaggeryContext in project jaggery by wso2.
the class JaggeryDeployerManager method addSessionDestroyedListners.
private static void addSessionDestroyedListners(Context context, JSONArray arr) {
if (arr != null) {
try {
JaggeryContext sharedContext = WebAppManager.sharedJaggeryContext(context.getServletContext());
CommonManager.setJaggeryContext(sharedContext);
RhinoEngine engine = sharedContext.getEngine();
org.mozilla.javascript.Context cx = engine.enterContext();
ServletContext servletContext = (ServletContext) sharedContext.getProperty(org.jaggeryjs.hostobjects.web.Constants.SERVLET_CONTEXT);
List<String> jsListeners = new ArrayList<String>();
Object[] scripts = arr.toArray();
for (Object script : scripts) {
if (!(script instanceof String)) {
log.error("Invalid value for initScripts/destroyScripts in jaggery.conf : " + script);
continue;
}
String path = (String) script;
path = path.startsWith("/") ? path : "/" + path;
Stack<String> callstack = CommonManager.getCallstack(sharedContext);
callstack.push(path);
jsListeners.add(path);
}
servletContext.setAttribute(JaggeryCoreConstants.JS_DESTROYED_LISTENERS, jsListeners);
} finally {
if (org.mozilla.javascript.Context.getCurrentContext() != null) {
RhinoEngine.exitContext();
}
}
}
}
Aggregations