use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class VirtualFile method resolveOrLoadChildFromURL.
/**
* Attempts to resolve the file from the given URL or performs a download if the file does not exist.
* <p>
* Uses the path of the given URL relative to this directory and tries to resolve the child file. If this file
* does not exist, or has been modified since its last download, a download will be attempted.
* <p>
* As a result, the resolved file will be returned (which was either already there or has been downloaded).
* <p>
* In order to determine the effective filename/path within the given URL we attempt the following steps:
* <ol>
* <li>
* Check all parameters in the query string, if one contains a path with an accepted file extension,
* we use this.
* </li>
* <li>
* Otherwise, we check the path in the URL. If it has an accepted file extension, we use this as path.
* </li>
* <li>
* If the two attempts above fail, we emit a HEAD request and try to determine the filename/path by checking
* the <tt>content-disposition</tt> header.
* </li>
* </ol>
* <p>
* This will increment one of the timings (downloaded or download skipped) and also directly report IO
* errors to the process without spamming the system logs.
*
* @param url the url to fetch
* @param mode determines under which conditions the data from the given URL should be fetched
* @param fileExtensionVerifier specifies which extensions are accepted. This should be used to prevent using
* ".php" or the like as effective file name. When in doubt, use
* {@link #notServerSidedScripting(String)} to at least exclude common server-sided
* scripting languages like PHP.
* @return the file which has been resolved (and downloaded if necessary) along with a flag which indicates if an
* update (download) has been performed
* @throws HandledException in case of an any error during the download (or if the effective file path cannot be
* determined)
*/
public Tuple<VirtualFile, Boolean> resolveOrLoadChildFromURL(URI url, FetchFromUrlMode mode, Predicate<String> fileExtensionVerifier) {
Watch watch = Watch.start();
Tuple<VirtualFile, Boolean> fileAndFlag = performResolveOrLoadChildFromURL(url, mode, fileExtensionVerifier);
if (Boolean.TRUE.equals(fileAndFlag.getSecond())) {
TaskContext.get().addTiming(NLS.get("VirtualFile.fileDownloaded"), watch.elapsedMillis());
} else {
TaskContext.get().addTiming(NLS.get("VirtualFile.fileDownloadSkipped"), watch.elapsedMillis());
}
return fileAndFlag;
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class DeleteSQLEntitiesTask method execute.
@Override
public void execute(ProcessContext processContext, Tenant<?> tenant) throws Exception {
getQuery(tenant).iterateAll(entity -> {
Watch watch = Watch.start();
beforeDelete(entity);
oma.delete(entity);
afterDelete(entity);
processContext.addTiming(DeleteTenantJobFactory.TIMING_DELETED_ITEMS, watch.elapsedMillis());
});
}
use of sirius.kernel.commons.Watch in project sirius-biz by scireum.
the class DeleteMongoEntitiesTask method execute.
@Override
public void execute(ProcessContext processContext, Tenant<?> tenant) {
getQuery(tenant).iterateAll(entity -> {
Watch watch = Watch.start();
beforeDelete(entity);
mango.delete(entity);
afterDelete(entity);
processContext.addTiming(DeleteTenantJobFactory.TIMING_DELETED_ITEMS, watch.elapsedMillis());
});
}
Aggregations