Search in sources :

Example 6 with Slf4JStopWatch

use of org.perf4j.slf4j.Slf4JStopWatch in project cuba by cuba-platform.

the class FoldersServiceBean method loadAppFolders.

@Override
public List<AppFolder> loadAppFolders() {
    log.debug("Loading AppFolders");
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    List<AppFolder> resultList;
    try (Transaction tx = persistence.createTransaction()) {
        String metaClassName = metadata.getExtendedEntities().getEffectiveMetaClass(AppFolder.class).getName();
        TypedQuery<AppFolder> q = persistence.getEntityManager().createQuery("select f from " + metaClassName + " f order by f.sortOrder, f.name", AppFolder.class);
        resultList = q.getResultList();
        // fetch parent folder
        resultList.forEach(Folder::getParent);
        tx.commit();
    } finally {
        stopWatch.stop();
    }
    if (CollectionUtils.isNotEmpty(resultList)) {
        Binding binding = new Binding();
        binding.setVariable("persistence", persistence);
        binding.setVariable("metadata", metadata);
        binding.setVariable("userSession", userSessionSource.getUserSession());
        Iterator<AppFolder> iterator = resultList.iterator();
        while (iterator.hasNext()) {
            AppFolder folder = iterator.next();
            try (Transaction tx = persistence.createTransaction()) {
                boolean evaluatedVisibilityScript = true;
                try {
                    if (!StringUtils.isBlank(folder.getVisibilityScript())) {
                        binding.setVariable("folder", folder);
                        Boolean visible = runScript(folder.getVisibilityScript(), binding);
                        if (BooleanUtils.isFalse(visible)) {
                            iterator.remove();
                            continue;
                        }
                    }
                } catch (Exception e) {
                    log.warn("Unable to evaluate AppFolder visibility script for folder: id: {}  name: {}", folder.getId(), folder.getName(), e);
                    // because EclipseLink Query marks transaction as rollback-only on JPQL syntax errors
                    evaluatedVisibilityScript = false;
                }
                boolean evaluatedQuantityScript = loadFolderQuantity(binding, folder);
                if (evaluatedVisibilityScript && evaluatedQuantityScript) {
                    tx.commit();
                }
            }
        }
    }
    return resultList;
}
Also used : Binding(groovy.lang.Binding) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) SearchFolder(com.haulmont.cuba.security.entity.SearchFolder) Folder(com.haulmont.cuba.core.entity.Folder) IOException(java.io.IOException) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Transaction(com.haulmont.cuba.core.Transaction)

Example 7 with Slf4JStopWatch

use of org.perf4j.slf4j.Slf4JStopWatch in project cuba by cuba-platform.

the class FoldersServiceBean method reloadAppFolders.

@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
    log.debug("Reloading AppFolders {}", folders);
    StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
    stopWatch.start();
    try {
        if (!folders.isEmpty()) {
            Binding binding = new Binding();
            binding.setVariable("persistence", persistence);
            binding.setVariable("metadata", metadata);
            binding.setProperty("userSession", userSessionSource.getUserSession());
            for (AppFolder folder : folders) {
                Transaction tx = persistence.createTransaction();
                try {
                    if (loadFolderQuantity(binding, folder)) {
                        tx.commit();
                    }
                } finally {
                    tx.end();
                }
            }
        }
        return folders;
    } finally {
        stopWatch.stop();
    }
}
Also used : Binding(groovy.lang.Binding) AppFolder(com.haulmont.cuba.core.entity.AppFolder) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Transaction(com.haulmont.cuba.core.Transaction) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 8 with Slf4JStopWatch

use of org.perf4j.slf4j.Slf4JStopWatch in project cuba by cuba-platform.

the class WindowManager method afterShowWindow.

protected void afterShowWindow(Window window) {
    if (!WindowParams.DISABLE_APPLY_SETTINGS.getBool(window.getContext())) {
        window.applySettings(getSettingsImpl(window.getId()));
    }
    if (!WindowParams.DISABLE_RESUME_SUSPENDED.getBool(window.getContext())) {
        ((DsContextImplementation) window.getDsContext()).resumeSuspended();
    }
    if (window instanceof AbstractWindow) {
        AbstractWindow abstractWindow = (AbstractWindow) window;
        if (abstractWindow.isAttributeAccessControlEnabled()) {
            AttributeAccessSupport attributeAccessSupport = AppBeans.get(AttributeAccessSupport.NAME);
            attributeAccessSupport.applyAttributeAccess(abstractWindow, false);
        }
        StopWatch readyStopWatch = new Slf4JStopWatch(window.getId() + "#" + LifeCycle.READY, LoggerFactory.getLogger(UIPerformanceLogger.class));
        abstractWindow.ready();
        readyStopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 9 with Slf4JStopWatch

use of org.perf4j.slf4j.Slf4JStopWatch in project cuba by cuba-platform.

the class WindowManager method init.

protected void init(Window window, Map<String, Object> params) {
    if (window instanceof AbstractWindow) {
        StopWatch initStopWatch = new Slf4JStopWatch(window.getId() + "#" + LifeCycle.INIT, LoggerFactory.getLogger(UIPerformanceLogger.class));
        ((AbstractWindow) window).init(params);
        initStopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 10 with Slf4JStopWatch

use of org.perf4j.slf4j.Slf4JStopWatch in project cuba by cuba-platform.

the class WindowManager method initWrapperFrame.

protected void initWrapperFrame(Window wrappingWindow, ComponentLoaderContext context, Element element, Map<String, Object> params) {
    if (wrappingWindow instanceof AbstractWindow) {
        Element companionsElem = element.element("companions");
        if (companionsElem != null) {
            StopWatch companionStopWatch = new Slf4JStopWatch(wrappingWindow.getId() + "#" + LifeCycle.COMPANION, LoggerFactory.getLogger(UIPerformanceLogger.class));
            initCompanion(companionsElem, (AbstractWindow) wrappingWindow);
            companionStopWatch.stop();
        }
    }
    StopWatch injectStopWatch = new Slf4JStopWatch(wrappingWindow.getId() + "#" + LifeCycle.INJECTION, LoggerFactory.getLogger(UIPerformanceLogger.class));
    ControllerDependencyInjector dependencyInjector = AppBeans.getPrototype(ControllerDependencyInjector.NAME, wrappingWindow, params);
    dependencyInjector.inject();
    injectStopWatch.stop();
    context.executeInjectTasks();
    context.executePostWrapTasks();
    init(wrappingWindow, params);
    context.executeInitTasks();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Element(org.dom4j.Element) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Aggregations

StopWatch (org.perf4j.StopWatch)37 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)37 UIPerformanceLogger (com.haulmont.cuba.gui.logging.UIPerformanceLogger)17 Element (org.dom4j.Element)4 Transaction (com.haulmont.cuba.core.Transaction)3 Test (org.testng.annotations.Test)3 Node (com.haulmont.bali.datastruct.Node)2 MetaClass (com.haulmont.chile.core.model.MetaClass)2 AppFolder (com.haulmont.cuba.core.entity.AppFolder)2 ComponentLoader (com.haulmont.cuba.gui.xml.layout.ComponentLoader)2 ComponentLoaderContext (com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext)2 SearchFolder (com.haulmont.cuba.security.entity.SearchFolder)2 Binding (groovy.lang.Binding)2 IOException (java.io.IOException)2 Pair (com.haulmont.bali.datastruct.Pair)1 Tree (com.haulmont.bali.datastruct.Tree)1 MetaModel (com.haulmont.chile.core.model.MetaModel)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 EntityManager (com.haulmont.cuba.core.EntityManager)1 Entity (com.haulmont.cuba.core.entity.Entity)1