use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.
the class ProfilingContainerResponseFilter method filter.
@Override
public ContainerResponse filter(final ContainerRequest request, final ContainerResponse response) {
try {
final ProfilingData rawData = Profiling.getPerThreadProfilingData();
if (rawData != null) {
if (rawData.getProfileFeature().isProfilingJAXRS()) {
rawData.addEnd(ProfilingFeatureType.JAXRS, request.getPath());
}
final ProfilingDataJson profilingData = new ProfilingDataJson(rawData);
final String value;
try {
value = mapper.writeValueAsString(profilingData);
response.getHttpHeaders().add(PROFILING_HEADER_RESP, value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
} finally {
Profiling.resetPerThreadProfilingData();
}
return response;
}
use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.
the class ProfilingContainerResponseFilter method filter.
@Override
public ContainerRequest filter(final ContainerRequest request) {
final List<String> profilingHeaderRequests = request.getRequestHeader(PROFILING_HEADER_REQ);
final String profilingHeaderRequest = (profilingHeaderRequests == null || profilingHeaderRequests.isEmpty()) ? null : profilingHeaderRequests.get(0);
if (profilingHeaderRequest != null) {
try {
Profiling.setPerThreadProfilingData(profilingHeaderRequest);
// If we need to profile JAXRS let's do it...
final ProfilingData profilingData = Profiling.getPerThreadProfilingData();
if (profilingData.getProfileFeature().isProfilingJAXRS()) {
profilingData.addStart(ProfilingFeatureType.JAXRS, request.getPath());
}
} catch (IllegalArgumentException e) {
log.info("Profiling data output {} is not supported, profiling NOT enabled", profilingHeaderRequest);
}
}
return request;
}
use of org.killbill.commons.profiling.ProfilingData in project killbill by killbill.
the class PluginDispatcher method dispatchWithTimeout.
@VisibleForTesting
ReturnType dispatchWithTimeout(final Callable<PluginDispatcherReturnType<ReturnType>> task, final long timeout, final TimeUnit unit) throws TimeoutException, ExecutionException, InterruptedException {
final ExecutorService pluginExecutor = paymentExecutors.getPluginExecutorService();
// Wrap existing callable to keep the original requestId
final Callable<PluginDispatcherReturnType<ReturnType>> callableWithRequestData = new CallableWithRequestData(Request.getPerThreadRequestData(), UUIDs.getRandom(), ThreadContext.getSecurityManager(), ThreadContext.getSubject(), MDC.getCopyOfContextMap(), task);
final Future<PluginDispatcherReturnType<ReturnType>> future = pluginExecutor.submit(callableWithRequestData);
final PluginDispatcherReturnType<ReturnType> pluginDispatcherResult = future.get(timeout, unit);
if (pluginDispatcherResult instanceof WithProfilingPluginDispatcherReturnType) {
// Transfer state from dispatch thread into current one.
final ProfilingData currentThreadProfilingData = Profiling.getPerThreadProfilingData();
if (currentThreadProfilingData != null) {
currentThreadProfilingData.merge(((WithProfilingPluginDispatcherReturnType) pluginDispatcherResult).getProfilingData());
}
}
return pluginDispatcherResult.getReturnType();
}
Aggregations