Search in sources :

Example 26 with Slf4JStopWatch

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

the class AbstractMessages method searchFiles.

protected String searchFiles(String pack, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StopWatch stopWatch = new Slf4JStopWatch("Messages.searchFiles");
    try {
        String cacheKey = makeCacheKey(pack, key, locale, truncatedLocale);
        String msg = strCache.get(cacheKey);
        if (msg != null)
            return msg;
        log.trace("searchFiles: {}", cacheKey);
        String packPath = confDir + "/" + pack.replaceAll("\\.", "/");
        while (packPath != null && !packPath.equals(confDir)) {
            Properties properties = loadPropertiesFromFile(packPath, locale, truncatedLocale);
            if (properties != PROPERTIES_NOT_FOUND) {
                msg = getMessageFromProperties(pack, key, locale, truncatedLocale, properties, passedPacks);
                if (msg != null)
                    return msg;
            }
            // not found, keep searching
            int pos = packPath.lastIndexOf("/");
            if (pos < 0)
                packPath = null;
            else
                packPath = packPath.substring(0, pos);
        }
        return null;
    } finally {
        stopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 27 with Slf4JStopWatch

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

the class AbstractMessages method searchClasspath.

protected String searchClasspath(String pack, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
    StopWatch stopWatch = new Slf4JStopWatch("Messages.searchClasspath");
    try {
        String cacheKey = makeCacheKey(pack, key, locale, truncatedLocale);
        String msg = strCache.get(cacheKey);
        if (msg != null)
            return msg;
        log.trace("searchClasspath: {}", cacheKey);
        String packPath = "/" + pack.replaceAll("\\.", "/");
        while (packPath != null) {
            Properties properties = loadPropertiesFromResource(packPath, locale, truncatedLocale);
            if (properties != PROPERTIES_NOT_FOUND) {
                msg = getMessageFromProperties(pack, key, locale, truncatedLocale, properties, passedPacks);
                if (msg != null)
                    return msg;
            }
            // not found, keep searching
            int pos = packPath.lastIndexOf("/");
            if (pos < 0)
                packPath = null;
            else
                packPath = packPath.substring(0, pos);
        }
        return null;
    } finally {
        stopWatch.stop();
    }
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 28 with Slf4JStopWatch

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

the class MetadataLoader method replaceExtendedMetaClasses.

protected void replaceExtendedMetaClasses() {
    StopWatch sw = new Slf4JStopWatch("Metadata.replaceExtendedMetaClasses");
    for (MetaModel model : session.getModels()) {
        MetaModelImpl modelImpl = (MetaModelImpl) model;
        List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
        for (MetaClass metaClass : modelImpl.getClasses()) {
            MetaClass effectiveMetaClass = session.getClass(extendedEntities.getEffectiveClass(metaClass));
            if (effectiveMetaClass != metaClass) {
                replaceMap.add(new Pair<>(metaClass, effectiveMetaClass));
            }
            for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
                MetaPropertyImpl propertyImpl = (MetaPropertyImpl) metaProperty;
                // replace domain
                Class effectiveDomainClass = extendedEntities.getEffectiveClass(metaProperty.getDomain());
                MetaClass effectiveDomainMeta = session.getClass(effectiveDomainClass);
                if (metaProperty.getDomain() != effectiveDomainMeta) {
                    propertyImpl.setDomain(effectiveDomainMeta);
                }
                if (metaProperty.getRange().isClass()) {
                    // replace range class
                    ClassRange range = (ClassRange) metaProperty.getRange();
                    Class effectiveRangeClass = extendedEntities.getEffectiveClass(range.asClass());
                    MetaClass effectiveRangeMeta = session.getClass(effectiveRangeClass);
                    if (effectiveRangeMeta != range.asClass()) {
                        ClassRange newRange = new ClassRange(effectiveRangeMeta);
                        newRange.setCardinality(range.getCardinality());
                        newRange.setOrdered(range.isOrdered());
                        ((MetaPropertyImpl) metaProperty).setRange(newRange);
                    }
                }
            }
        }
        for (Pair<MetaClass, MetaClass> replace : replaceMap) {
            MetaClass replacedMetaClass = replace.getFirst();
            extendedEntities.registerReplacedMetaClass(replacedMetaClass);
            MetaClassImpl effectiveMetaClass = (MetaClassImpl) replace.getSecond();
            modelImpl.registerClass(replacedMetaClass.getName(), replacedMetaClass.getJavaClass(), effectiveMetaClass);
        }
    }
    sw.stop();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) MetaModel(com.haulmont.chile.core.model.MetaModel) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Pair(com.haulmont.bali.datastruct.Pair)

Example 29 with Slf4JStopWatch

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

the class EmailSender method sendEmail.

@Override
public void sendEmail(SendingMessage sendingMessage) throws MessagingException {
    MimeMessage msg = createMimeMessage(sendingMessage);
    StopWatch sw = new Slf4JStopWatch("EmailSender.send");
    mailSender.send(msg);
    sw.stop();
    log.info("Email '{}' to '{}' has been sent successfully", msg.getSubject(), sendingMessage.getAddress());
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

Example 30 with Slf4JStopWatch

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

the class Scheduling method calculateNextCronDate.

protected long calculateNextCronDate(ScheduledTask task, long date, long currentDate, long frame) {
    StopWatch sw = new Slf4JStopWatch("Cron next date calculations");
    CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(task.getCron(), getCurrentTimeZone());
    // if last start = 0 (task never has run) or to far in the past, we use (NOW - FRAME) timestamp for pivot time
    // this approach should work fine cause cron works with absolute time
    long pivotPreviousTime = Math.max(date, currentDate - frame);
    Date currentStart = null;
    Date nextDate = cronSequenceGenerator.next(new Date(pivotPreviousTime));
    while (nextDate.getTime() < currentDate) {
        // if next date is in past try to find next date nearest to now
        currentStart = nextDate;
        nextDate = cronSequenceGenerator.next(nextDate);
    }
    if (currentStart == null) {
        currentStart = nextDate;
    }
    log.trace("{}\n now={} frame={} currentStart={} lastStart={} cron={}", task, currentDate, frame, currentStart, task.getCron());
    sw.stop();
    return currentStart.getTime();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) CronSequenceGenerator(org.springframework.scheduling.support.CronSequenceGenerator) 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