Search in sources :

Example 1 with BlobSupport

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;
    }
}
Also used : OperationMetrics(org.sonatype.nexus.blobstore.api.OperationMetrics) Method(java.lang.reflect.Method) OperationType(org.sonatype.nexus.blobstore.api.OperationType) BlobStore(org.sonatype.nexus.blobstore.api.BlobStore) BlobSupport(org.sonatype.nexus.blobstore.BlobSupport)

Aggregations

Method (java.lang.reflect.Method)1 BlobSupport (org.sonatype.nexus.blobstore.BlobSupport)1 BlobStore (org.sonatype.nexus.blobstore.api.BlobStore)1 OperationMetrics (org.sonatype.nexus.blobstore.api.OperationMetrics)1 OperationType (org.sonatype.nexus.blobstore.api.OperationType)1