All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ge.snowizard.service.core.TimedResourceMethodDispatchProvider Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.ge.snowizard.service.core;

import com.sun.jersey.api.model.AbstractResourceMethod;
import com.sun.jersey.spi.container.ResourceMethodDispatchProvider;
import com.sun.jersey.spi.dispatch.RequestDispatcher;
import com.yammer.metrics.annotation.Timed;

public class TimedResourceMethodDispatchProvider implements
        ResourceMethodDispatchProvider {

    private final ResourceMethodDispatchProvider provider;

    /**
     * Constructor
     *
     * @param provider
     *            {@link ResourceMethodDispatchProvider}
     */
    public TimedResourceMethodDispatchProvider(
            final ResourceMethodDispatchProvider provider) {
        this.provider = provider;
    }

    @Override
    public RequestDispatcher create(
            final AbstractResourceMethod abstractResourceMethod) {
        final RequestDispatcher dispatcher = provider
                .create(abstractResourceMethod);
        final Timed timed = abstractResourceMethod.getMethod().getAnnotation(
                Timed.class);

        if (timed != null) {
            final String resourceName = abstractResourceMethod
                    .getDeclaringResource().getResourceClass().getSimpleName();
            final String methodName = abstractResourceMethod.getMethod()
                    .getName();
            return new TimedRequestDispatcher(dispatcher, String.format(
                    "%s/%s", resourceName, methodName));
        }
        return dispatcher;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy