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();
}
}
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();
}
}
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();
}
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());
}
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();
}
Aggregations