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