use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class ConversionEngine method performConversion.
/**
* Invokes the {@link Converter} which has been configured for the given variant to perform the actual conversion.
*
* @param conversionProcess the conversion to perform
* @return a future which is fulfilled once the conversion is completed
*/
public Future performConversion(ConversionProcess conversionProcess) {
Future result = new Future();
Watch queueWatch = Watch.start();
tasks.executor(EXECUTOR_STORAGE_CONVERSION).dropOnOverload(() -> result.fail(new IllegalStateException("Conversion subsystem overloaded!"))).fork(() -> doConversion(conversionProcess, result, queueWatch));
return result;
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class BasePageHelper method asPage.
/**
* Wraps the given data into a {@link Page} which can be used to render a table, filterbox and support pagination.
* <p>
* This can only be done if a web context has been provided via {@link #withContext(WebContext)}.
*
* @return the given data wrapped as <tt>Page</tt>
*/
public Page<E> asPage() {
Objects.requireNonNull(webContext);
Watch w = Watch.start();
Page<E> result = new Page<E>().withStart(1).withPageSize(pageSize);
result.bindToRequest(webContext);
applyQuery(result.getQuery());
applyFacets(result);
try {
setupPaging(result);
List<E> items = executeQuery();
enforcePaging(result, items);
fillPage(w, result, items);
if (debugging) {
UserContext.message(Message.info().withTextMessage(Strings.apply("Effective Query: %s (Matches: %s, Duration: %s ms)", baseQuery, baseQuery.count(), w.elapsedMillis())));
}
} catch (Exception e) {
UserContext.handle(e);
}
return result;
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class EntityExportJob method handleTemplateRow.
/**
* Enhances a data row read from the template.
*
* @param row the row data to process
*/
private void handleTemplateRow(Values row) {
Watch w = Watch.start();
errorContext.handle(() -> {
Context data = dictionary.load(row, false);
if (contextExtender != null) {
contextExtender.accept(data);
}
Optional<E> entity = importer.tryFind(type, data);
if (entity.isPresent()) {
export.addRow(exportAsRow(row, entity.get()));
} else {
export.addRow(row.asList());
}
});
process.addTiming(descriptor.getPluralLabel(), w.elapsedMillis());
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class RelationalEntityImportJob method commitImportTransaction.
/**
* Commits the import transaction by deleting all untouched entities.
*/
@SuppressWarnings("unchecked")
protected void commitImportTransaction() {
if (mode != SyncMode.SYNC) {
return;
}
Watch watch = Watch.start();
importTransactionHelper.deleteUnmarked(type, query -> tuneImportTransactionDeleteQuery((Q) query), entity -> {
process.addTiming(NLS.get("EntityImportJob.entityDeleted"), watch.elapsed(TimeUnit.MILLISECONDS, true));
});
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class QueryController method executeQuery.
@SuppressWarnings("unchecked")
private <C extends Constraint, Q extends Query<Q, ?, C>> List<BaseEntity<?>> executeQuery(EntityDescriptor descriptor, String queryString, int limit) {
try {
// As Query is a self-referential type, we have to use a custom generic type here...
Q baseQuery = (Q) descriptor.getMapper().select((Class<BaseEntity<?>>) descriptor.getType());
// Compile the query string and extract the debug flag...
Tuple<Constraint, Boolean> constraintAndDebugFlag = descriptor.getMapper().filters().compileString(descriptor, queryString, Collections.emptyList());
baseQuery.where((C) constraintAndDebugFlag.getFirst());
// Log effective query if desired...
if (Boolean.TRUE.equals(constraintAndDebugFlag.getSecond())) {
UserContext.message(Message.info().withTextMessage("Effective Query: " + baseQuery));
}
// Elastic entities might be routed - we ignore this here and access all shards anyway...
if (baseQuery instanceof ElasticQuery) {
((ElasticQuery<?>) baseQuery).deliberatelyUnrouted();
}
long numberOfEntities = getTotalCount(limit, baseQuery);
// Actually perform the query...
List<BaseEntity<?>> result = new ArrayList<>();
if (numberOfEntities > 0) {
Watch watch = Watch.start();
baseQuery.limit(limit).iterateAll(result::add);
UserContext.message(Message.info().withTextMessage(Strings.apply("Showing %s of %s results - Query took %sms", result.size(), numberOfEntities, watch.elapsedMillis())));
}
return result;
} catch (IllegalArgumentException e) {
// The QueryCompiler generates an IllegalArgumentException for invalid fields and tokens.
// In our case we don't want to write them into the syslog but just output the message...
UserContext.message(Message.error().withTextMessage(e.getMessage()));
} catch (Exception e) {
handle(e);
}
return Collections.emptyList();
}
Aggregations