Search in sources :

Example 1 with PerformanceData

use of com.servoy.j2db.server.shared.PerformanceData in project servoy-client by Servoy.

the class ScriptEngine method compileScriptProvider.

/**
 * @param sp
 * @param scope
 * @param cx
 * @return
 */
@SuppressWarnings("nls")
protected Function compileScriptProvider(IScriptProvider sp, Scriptable scope, Context cx, String sourceName) {
    String declaration = sp.getDeclaration();
    // dont return the calc function itself but still the value.
    if (sp instanceof ScriptCalculation) {
        declaration = extractFunction(declaration, "function $1_");
    } else {
        declaration = extractFunction(declaration, "function $1");
    }
    // f below always seems to be NativeFunction instance as both Codegen.createFunctionObject and Interpreter.createFunctionObject return
    // a NativeFunction instance; and that is what cx.compileFunction(...) ends up calling
    Function f = cx.compileFunction(scope, declaration, sourceName, sp.getLineNumberOffset(), null);
    if (!(sp instanceof ScriptCalculation)) {
        if (sp.getScopeName() != null) {
            // $NON-NLS-1$
            f.put("_scopename_", f, sp.getScopeName());
        }
        // $NON-NLS-1$
        f.put("_methodname_", f, sp.getDataProviderID());
        f.put("_AllowToRunInFind_", f, Boolean.valueOf(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        sp.getDeclaration().indexOf("@AllowToRunInFind") != -1 || declaration.indexOf(".search") != -1 || declaration.indexOf("controller.loadAllRecords") != -1));
    }
    String methodName = sp.getName();
    PerformanceData performanceData = application instanceof IPerformanceDataProvider ? ((IPerformanceDataProvider) application).getPerformanceData() : null;
    if (performanceData != null) {
        String scopeName = scope.getClassName();
        if (scope instanceof LazyCompilationScope) {
            scopeName = ((LazyCompilationScope) scope).getScopeName();
            scopeName = lookForSuperCalls(sp, scopeName);
        } else if (scope.getParentScope() instanceof LazyCompilationScope) {
            scopeName = ((LazyCompilationScope) scope.getParentScope()).getScopeName();
            scopeName = lookForSuperCalls(sp, scopeName);
        } else if (scope instanceof FoundSet) {
            Scriptable parentScope = ((FoundSet) scope).getPrototype();
            if (parentScope instanceof LazyCompilationScope) {
                scopeName = ((LazyCompilationScope) parentScope).getScopeName();
            }
        }
        methodName = scopeName + "." + methodName;
        return new FunctionWrapper(f, methodName, performanceData, application.getClientID());
    }
    return f;
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) NativeFunction(org.mozilla.javascript.NativeFunction) Function(org.mozilla.javascript.Function) IPerformanceDataProvider(com.servoy.j2db.server.shared.IPerformanceDataProvider) PerformanceData(com.servoy.j2db.server.shared.PerformanceData) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Scriptable(org.mozilla.javascript.Scriptable)

Example 2 with PerformanceData

use of com.servoy.j2db.server.shared.PerformanceData in project servoy-client by Servoy.

the class NGRuntimeWindow method doOldShow.

@Override
protected void doOldShow(String formName, boolean closeAll, boolean legacyV3Behavior) {
    String currentWindowName = getApplication().getRuntimeWindowManager().getCurrentWindowName();
    IWebFormController controller = getApplication().getFormManager().getForm(formName);
    if (controller != null) {
        getApplication().getFormManager().showFormInContainer(formName, this, getTitle(), true, windowName);
        this.formName = formName;
        controller.getFormUI().setParentWindowName(getName());
        // show panel as main
        switchForm(controller);
    }
    String titleArg = getTitle();
    if (titleArg == null && controller != null) {
        titleArg = controller.getForm().getTitleText();
    }
    if (titleArg == null) {
        titleArg = formName;
    }
    titleArg = getApplication().getI18NMessageIfPrefixed(titleArg);
    getApplication().getWebsocketSession().getClientService(NGRuntimeWindowManager.WINDOW_SERVICE).executeAsyncServiceCall("show", new Object[] { getName(), formName, titleArg });
    if (windowType == JSWindow.MODAL_DIALOG && getApplication().getWebsocketSession().getEventDispatcher() != null) {
        try {
            try {
                CurrentWindow.get().sendChanges();
            } catch (IOException e) {
                Debug.log(e);
            }
            IPerformanceRegistry perfRegistry = null;
            try {
                perfRegistry = (getApplication().getApplicationServerAccess() != null ? getApplication().getApplicationServerAccess().getFunctionPerfomanceRegistry() : null);
            } catch (RemoteException e) {
                Debug.error(e);
            }
            Pair<Integer, Integer> perfId = null;
            PerformanceData performanceData = null;
            String clientID = getApplication().getClientID();
            if (perfRegistry != null) {
                performanceData = perfRegistry.getPerformanceData(getApplication().getSolutionName());
                perfId = performanceData != null ? // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                performanceData.startSubAction(// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                "showDialog(" + windowName + "->" + formName + ")", // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                System.currentTimeMillis(), IDataServer.METHOD_CALL_WAITING_FOR_USER_INPUT, clientID) : null;
            }
            try {
                getApplication().getWebsocketSession().getEventDispatcher().suspend(this, IEventDispatcher.EVENT_LEVEL_DEFAULT, IEventDispatcher.NO_TIMEOUT);
            } finally {
                if (perfId != null)
                    performanceData.endSubAction(perfId, clientID);
            }
            // this is now a hide of this window, set back the window name just before this show.
            getApplication().getRuntimeWindowManager().setCurrentWindowName(currentWindowName);
        } catch (CancellationException e) {
            // full browser refresh while waiting for modal to close?
            throw e;
        } catch (TimeoutException e) {
            Debug.error("Modal dialog suspend timed out. This should never happen");
        }
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) PerformanceData(com.servoy.j2db.server.shared.PerformanceData) IOException(java.io.IOException) IPerformanceRegistry(com.servoy.j2db.server.shared.IPerformanceRegistry) RemoteException(java.rmi.RemoteException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

PerformanceData (com.servoy.j2db.server.shared.PerformanceData)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 ScriptCalculation (com.servoy.j2db.persistence.ScriptCalculation)1 IPerformanceDataProvider (com.servoy.j2db.server.shared.IPerformanceDataProvider)1 IPerformanceRegistry (com.servoy.j2db.server.shared.IPerformanceRegistry)1 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 CancellationException (java.util.concurrent.CancellationException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Function (org.mozilla.javascript.Function)1 NativeFunction (org.mozilla.javascript.NativeFunction)1 Scriptable (org.mozilla.javascript.Scriptable)1