Search in sources :

Example 26 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class Scripting method handleExecTask.

private void handleExecTask(JSONObject event) {
    String nodeName = event.getString(TASK_NODE);
    String jobNumber = event.getString(TASK_JOB);
    if (!ALL_NODES.equals(nodeName) && !Strings.areEqual(CallContext.getNodeName(), nodeName)) {
        return;
    }
    Watch watch = Watch.start();
    logInTranscript(jobNumber, Strings.apply("Starting execution on %s (Thread Id: %s / Thread Name: %s)", CallContext.getNodeName(), Thread.currentThread().getId(), Thread.currentThread().getName()));
    try {
        Callable callable = compileScript(event);
        TaskContext.get().setAdapter(new JobTaskContextAdapter(this, jobNumber));
        callable.call(new SimpleEnvironment());
    } catch (CompileException | ScriptingException | HandledException e) {
        logInTranscript(jobNumber, e.getMessage());
    } catch (Exception e) {
        logInTranscript(jobNumber, Exceptions.handle(Pasta.LOG, e).getMessage());
    }
    logInTranscript(jobNumber, Strings.apply("Execution completed (%s)", watch.duration()));
}
Also used : HandledException(sirius.kernel.health.HandledException) SimpleEnvironment(sirius.pasta.noodle.SimpleEnvironment) Watch(sirius.kernel.commons.Watch) CompileException(sirius.pasta.noodle.compiler.CompileException) Callable(sirius.pasta.noodle.Callable) HandledException(sirius.kernel.health.HandledException) ScriptingException(sirius.pasta.noodle.ScriptingException) CompileException(sirius.pasta.noodle.compiler.CompileException) ScriptingException(sirius.pasta.noodle.ScriptingException)

Example 27 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class I5Connection method call.

/**
 * Calls a program on the i5.
 *
 * @param pgm    the name of the program to call
 * @param params the parameters to pass
 */
public void call(String pgm, ProgramParameter... params) {
    Watch w = Watch.start();
    lastUse = System.currentTimeMillis();
    try {
        ProgramCall p = new ProgramCall(i5, pgm, params);
        String currentJob = getCurrentJob(pgm, p);
        lastJob = currentJob;
        executeProgramCall(p, currentJob);
        collectCPUUsed(p, pgm);
        if (I5Connector.LOG.isFINE()) {
            logProgramOutput(pgm, params);
        }
    } finally {
        w.submitMicroTiming("i5", "I5Connection.call#" + pgm);
        pool.i5Connector.calls.inc();
        pool.i5Connector.callDuration.addValue(w.elapsedMillis());
    }
}
Also used : Watch(sirius.kernel.commons.Watch) ProgramCall(com.ibm.as400.access.ProgramCall)

Example 28 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class I5ConnectionPool method makeObject.

@Override
@SuppressWarnings("squid:S2095")
@Explain("We cannot close the i5 connection here as it is returned as PooledObject")
public PooledObject<I5Connection> makeObject() throws Exception {
    try {
        Watch w = Watch.start();
        I5Connection result = new I5Connection();
        result.pool = this;
        result.i5 = new AS400(host, username, password);
        result.initialize();
        w.submitMicroTiming("UPOS", "I5ConnectionPool.makeObject");
        openConnections.add(new WeakReference<>(result));
        return new DefaultPooledObject<>(result);
    } catch (Exception e) {
        throw Exceptions.handle().to(I5Connector.LOG).error(e).withSystemErrorMessage("Cannot create connection to %s as %s: %s (%s)", host, username).handle();
    }
}
Also used : DefaultPooledObject(org.apache.commons.pool2.impl.DefaultPooledObject) Watch(sirius.kernel.commons.Watch) AS400(com.ibm.as400.access.AS400) Explain(sirius.kernel.commons.Explain)

Example 29 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class TouchWritebackLoop method doWork.

@Nullable
@Override
protected String doWork() throws Exception {
    Watch w = Watch.start();
    List<Tuple<String, String>> unitOfWork = new ArrayList<>();
    touchedBlobs.drainTo(unitOfWork);
    if (blobStorage == null) {
        return null;
    }
    Map<String, Set<String>> blobsPerSpace = unitOfWork.stream().collect(Collectors.groupingBy(Tuple::getFirst, Collectors.mapping(Tuple::getSecond, Collectors.toSet())));
    blobsPerSpace.forEach((space, keys) -> {
        blobStorage.getSpace(space).markTouched(keys);
    });
    if (blobsPerSpace.isEmpty()) {
        return null;
    } else {
        return Strings.apply("Touched %s blobs in %s spaces within %s", unitOfWork.size(), blobsPerSpace.entrySet().size(), w.duration());
    }
}
Also used : Set(java.util.Set) Watch(sirius.kernel.commons.Watch) ArrayList(java.util.ArrayList) Tuple(sirius.kernel.commons.Tuple) Nullable(javax.annotation.Nullable)

Example 30 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class ForceReplicationJob method execute.

@Override
protected void execute(ProcessContext process) throws Exception {
    String spaceName = process.getContext().get(PARAMETER_SPACE);
    LocalDate minModificationDate = process.getParameter(MIN_MODIFICATION_DATE_PARAMETER).orElse(null);
    ObjectStorageSpace space = objectStorage.getSpace(spaceName);
    space.iterateObjects(metadata -> {
        try {
            if (metadata.getSize() == 0) {
                // We cannot / do not want to backup empty files...
                process.incCounter("Skipped");
                process.debug(ProcessLog.info().withFormattedMessage("Skipped empty object: %s", metadata.getKey()));
            } else if (minModificationDate == null || !metadata.getLastModified().toLocalDate().isBefore(minModificationDate)) {
                Watch watch = Watch.start();
                replicationManager.notifyAboutUpdate(space, metadata.getKey(), metadata.getSize());
                process.addTiming("Scheduled", watch.elapsedMillis());
            } else {
                process.incCounter("Ignored");
                process.debug(ProcessLog.info().withFormattedMessage("Ignored unmodified object: %s", metadata.getKey()));
            }
        } catch (Exception e) {
            process.handle(e);
        }
        return true;
    });
}
Also used : Watch(sirius.kernel.commons.Watch) LocalDate(java.time.LocalDate) ObjectStorageSpace(sirius.biz.storage.layer1.ObjectStorageSpace)

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