Search in sources :

Example 1 with ResourceMethodStatistics

use of org.glassfish.jersey.server.monitoring.ResourceMethodStatistics in project jersey by jersey.

the class ResourceMxBeanImpl method updateResourceStatistics.

/**
     * Update the statistics of this MXBean and of nested MXBeans.
     * @param resourceStatistics New resource statistics.
     */
public void updateResourceStatistics(ResourceStatistics resourceStatistics) {
    this.methodsExecutionStatisticsBean.updateExecutionStatistics(resourceStatistics.getResourceMethodExecutionStatistics());
    this.requestExecutionStatisticsBean.updateExecutionStatistics(resourceStatistics.getRequestExecutionStatistics());
    for (Map.Entry<ResourceMethod, ResourceMethodStatistics> entry : resourceStatistics.getResourceMethodStatistics().entrySet()) {
        final ResourceMethodStatistics methodStats = entry.getValue();
        final ResourceMethod method = entry.getKey();
        final String methodId = MonitoringUtils.getMethodUniqueId(method);
        ResourceMethodMXBeanImpl methodMXBean = this.resourceMethods.get(methodId);
        if (methodMXBean == null) {
            methodMXBean = new ResourceMethodMXBeanImpl(methodStats, uriResource, mBeanExposer, resourcePropertyName, methodId);
            resourceMethods.put(methodId, methodMXBean);
        }
        methodMXBean.updateResourceMethodStatistics(methodStats);
    }
}
Also used : ResourceMethodStatistics(org.glassfish.jersey.server.monitoring.ResourceMethodStatistics) Map(java.util.Map) HashMap(java.util.HashMap) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod)

Example 2 with ResourceMethodStatistics

use of org.glassfish.jersey.server.monitoring.ResourceMethodStatistics in project jersey by jersey.

the class MonitoringStatisticsTest method testUrisWithProgrammaticResourcesAndExecution.

@Test
public void testUrisWithProgrammaticResourcesAndExecution() {
    final MonitoringStatisticsImpl.Builder statBuilder = getProgStats();
    final Resource.Builder resourceBuilder = Resource.builder();
    resourceBuilder.addMethod("GET").handledBy(MyInflector.class);
    resourceBuilder.addMethod("POST").handledBy(MyInflector.class);
    final Resource res = resourceBuilder.build();
    ResourceMethod getMethod;
    ResourceMethod postMethod;
    if (res.getResourceMethods().get(0).getHttpMethod().equals("GET")) {
        getMethod = res.getResourceMethods().get(0);
        postMethod = res.getResourceMethods().get(1);
    } else {
        getMethod = res.getResourceMethods().get(1);
        postMethod = res.getResourceMethods().get(0);
    }
    statBuilder.addExecution("/new/elefant", getMethod, 10, 5, 8, 8);
    statBuilder.addExecution("/new/elefant", getMethod, 20, 12, 18, 10);
    statBuilder.addExecution("/new/elefant", postMethod, 30, 2, 28, 4);
    final MonitoringStatisticsImpl stat = statBuilder.build();
    final Iterator<Map.Entry<String, ResourceStatistics>> it = stat.getUriStatistics().entrySet().iterator();
    check(it, "/hello", 2);
    check(it, "/hello/world", 1);
    check(it, "/new/elefant", 2);
    check(it, "/prog", 1);
    check(it, "/test-resource", 1);
    check(it, "/test-resource/child", 3);
    check(it, "/test-resource/prog-child", 1);
    final Map<ResourceMethod, ResourceMethodStatistics> resourceMethodStatistics = stat.getUriStatistics().get("/new/elefant").getResourceMethodStatistics();
    for (ResourceMethodStatistics methodStatistics : resourceMethodStatistics.values()) {
        final ResourceMethod method = methodStatistics.getResourceMethod();
        final ExecutionStatistics st = methodStatistics.getMethodStatistics();
        if (method.getHttpMethod().equals("GET")) {
            Assert.assertEquals(20, st.getLastStartTime().getTime());
        } else if (method.getHttpMethod().equals("POST")) {
            Assert.assertEquals(30, st.getLastStartTime().getTime());
        } else {
            Assert.fail();
        }
    }
}
Also used : ExecutionStatistics(org.glassfish.jersey.server.monitoring.ExecutionStatistics) ResourceMethodStatistics(org.glassfish.jersey.server.monitoring.ResourceMethodStatistics) Resource(org.glassfish.jersey.server.model.Resource) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) Test(org.junit.Test)

Aggregations

ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)2 ResourceMethodStatistics (org.glassfish.jersey.server.monitoring.ResourceMethodStatistics)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Resource (org.glassfish.jersey.server.model.Resource)1 ExecutionStatistics (org.glassfish.jersey.server.monitoring.ExecutionStatistics)1 Test (org.junit.Test)1