use of org.sonatype.nexus.blobstore.BlobSupport in project nexus-public by sonatype.
the class BlobStoreAnalyticsInterceptor method invoke.
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
String clazz = invocation.getThis().getClass().getSimpleName();
Method method = invocation.getMethod();
String methodName = method.getName();
MonitoringBlobStoreMetrics metricsAnnotation = method.getAnnotation(MonitoringBlobStoreMetrics.class);
checkState(metricsAnnotation != null);
OperationType operationType = metricsAnnotation.operationType();
BlobStore blobStore;
OperationMetrics operationMetrics;
if (invocation.getThis() instanceof BlobStore) {
blobStore = (BlobStore) invocation.getThis();
operationMetrics = blobStore.getOperationMetricsDelta().get(operationType);
} else {
log.info("Can't monitor operation metrics for class={}, methodName={}", clazz, methodName);
return invocation.proceed();
}
long start = System.currentTimeMillis();
try {
Object result = invocation.proceed();
// record metrics only in case of successful processing.
operationMetrics.addSuccessfulRequest();
operationMetrics.addTimeOnRequests(System.currentTimeMillis() - start);
if (result instanceof BlobSupport) {
long totalSize = ((BlobSupport) result).getMetrics().getContentSize();
operationMetrics.addBlobSize(totalSize);
}
return result;
} catch (Exception e) {
operationMetrics.addErrorRequest();
throw e;
}
}
Aggregations