Search in sources :

Example 51 with Watch

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;
}
Also used : Watch(sirius.kernel.commons.Watch)

Example 52 with Watch

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());
    });
}
Also used : Watch(sirius.kernel.commons.Watch)

Example 53 with Watch

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());
    });
}
Also used : Watch(sirius.kernel.commons.Watch)

Aggregations

Watch (sirius.kernel.commons.Watch)53 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)6 HandledException (sirius.kernel.health.HandledException)6 Document (org.bson.Document)5 ResultSet (java.sql.ResultSet)4 TaskContext (sirius.kernel.async.TaskContext)4 ArrayList (java.util.ArrayList)3 OMA (sirius.db.jdbc.OMA)3 Property (sirius.db.mixing.Property)3 BasicDBObject (com.mongodb.BasicDBObject)2 ProcessContext (sirius.biz.process.ProcessContext)2 ObjectStorageSpace (sirius.biz.storage.layer1.ObjectStorageSpace)2 Operator (sirius.db.jdbc.Operator)2 Operation (sirius.kernel.async.Operation)2 Context (sirius.kernel.commons.Context)2 Limit (sirius.kernel.commons.Limit)2 AS400 (com.ibm.as400.access.AS400)1 ProgramCall (com.ibm.as400.access.ProgramCall)1