use of org.spf4j.base.ExecutionContext in project spf4j by zolyfarkas.
the class ProfiledExecutionContextFactory method startThreadRoot.
@Override
public ExecutionContext startThreadRoot(final String name, final ExecutionContext parent, final long startTimeNanos, final long deadlineNanos, final Runnable onClose) {
Thread currentThread = Thread.currentThread();
ExecutionContext ctx = wrapped.startThreadRoot(name, parent, startTimeNanos, deadlineNanos, () -> {
currentContexts.remove(currentThread);
onClose.run();
});
currentContexts.put(currentThread, ctx);
return ctx;
}
use of org.spf4j.base.ExecutionContext in project spf4j by zolyfarkas.
the class TracingExecutionContextStackCollector method sample.
@Override
public void sample() {
Iterable<Map.Entry<Thread, ExecutionContext>> currentThreads = execCtxSupplier.get();
int i = 0;
for (Map.Entry<Thread, ExecutionContext> entry : currentThreads) {
requestFor[i] = entry.getKey();
contexts[i++] = entry.getValue();
if (i >= requestFor.length) {
break;
}
}
Arrays.fill(requestFor, i, requestFor.length, null);
StackTraceElement[][] stackTraces = Threads.getStackTraces(requestFor);
for (int j = 0; j < i; j++) {
StackTraceElement[] stackTrace = stackTraces[j];
ExecutionContext context = contexts[j];
StackCollector c = collections.computeIfAbsent(context.getName(), (k) -> new StackCollectorImpl());
if (stackTrace != null && stackTrace.length > 0) {
c.collect(stackTrace);
context.compute("TSS", (String k, SampleNode v) -> {
if (v == null) {
return SampleNode.createSampleNode(stackTrace);
} else {
SampleNode.addToSampleNode(v, stackTrace);
return v;
}
});
} else {
c.collect(new StackTraceElement[] { new StackTraceElement("Thread", requestFor[j].getName(), "", 0) });
}
}
}
use of org.spf4j.base.ExecutionContext in project spf4j by zolyfarkas.
the class RetryAspect method retriedMethod.
@Around(value = "execution(@org.spf4j.annotations.Retry * *(..)) && @annotation(annot)", argNames = "pjp,annot")
public Object retriedMethod(final ProceedingJoinPoint pjp, final Retry annot) throws Throwable {
try (ExecutionContext ctx = ExecutionContexts.start(pjp.toShortString(), annot.timeout(), annot.units())) {
Callable c = () -> {
try {
return pjp.proceed();
} catch (Exception | Error e) {
throw e;
} catch (Throwable ex) {
throw new UncheckedExecutionException(ex);
}
};
String retryPolicyName = annot.retryPolicyName();
if ("".equals(retryPolicyName)) {
return RetryPolicy.defaultPolicy().call(c, Exception.class, ctx.getDeadlineNanos());
} else {
return POLICIES.get(retryPolicyName).call(c, Exception.class, ctx.getDeadlineNanos());
}
}
}
use of org.spf4j.base.ExecutionContext in project spf4j by zolyfarkas.
the class ObjectPoolBuilderTest method testBuildDisposeTimeout.
@Test(expected = IllegalStateException.class)
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public void testBuildDisposeTimeout() throws ObjectCreationException, ObjectBorrowException, InterruptedException, TimeoutException, ObjectReturnException, ObjectDisposeException {
RecyclingSupplier<ExpensiveTestObject> pool = new RecyclingSupplierBuilder(10, new ExpensiveTestObjectFactory()).build();
LOG.debug("pool = {}", pool);
pool.get();
pool.get();
LOG.debug("pool = {}", pool);
try (ExecutionContext start = ExecutionContexts.start(1, TimeUnit.SECONDS)) {
pool.dispose();
pool.get();
LOG.debug("pool = {}", pool);
}
}
Aggregations