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

net.sf.ehcache.management.resource.services.CacheStatisticSamplesResourceServiceImpl Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
/*
 * All content copyright (c) 2003-2012 Terracotta, Inc., except as may otherwise be noted in a separate copyright
 * notice. All rights reserved.
 */
package net.sf.ehcache.management.resource.services;

import net.sf.ehcache.management.resource.CacheStatisticSampleEntity;
import net.sf.ehcache.management.service.EntityResourceFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terracotta.management.ServiceExecutionException;
import org.terracotta.management.ServiceLocator;
import org.terracotta.management.resource.exceptions.ResourceRuntimeException;
import org.terracotta.management.resource.services.validator.RequestValidator;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author brandony
 */
@Path("/agents/cacheManagers/caches/statistics/samples")
public final class CacheStatisticSamplesResourceServiceImpl {
  private static final Logger LOG = LoggerFactory.getLogger(CacheStatisticSamplesResourceServiceImpl.class);
  private final EntityResourceFactory entityResourceFactory;

  private final RequestValidator validator;

  public CacheStatisticSamplesResourceServiceImpl() {
    this.entityResourceFactory = ServiceLocator.locate(EntityResourceFactory.class);
    this.validator = ServiceLocator.locate(RequestValidator.class);
  }

  /**
   *
   * @param info
   * @return
   */
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Collection getCacheStatisticSamples(@Context UriInfo info) {
    LOG.debug(String.format("Invoking CacheStatisticSamplesResourceServiceImpl.getCacheStatisticSamples: %s",
        info.getRequestUri()));

    validator.validateSafe(info);

    String cacheManagerNames = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");
    Set cmNames = cacheManagerNames == null ? null : new HashSet(
        Arrays.asList(cacheManagerNames.split(",")));

    String cacheNames = info.getPathSegments().get(2).getMatrixParameters().getFirst("names");
    Set cNames = cacheNames == null ? null : new HashSet(Arrays.asList(cacheNames.split(",")));

    String sampleNames = info.getPathSegments().get(4).getMatrixParameters().getFirst("names");
    Set sNames = sampleNames == null ? null : new HashSet(Arrays.asList(sampleNames.split(",")));

    try {
      return entityResourceFactory.createCacheStatisticSampleEntity(cmNames, cNames, sNames);
    } catch (ServiceExecutionException e) {
      throw new ResourceRuntimeException("Failed to get cache statistics sample", e,
          Response.Status.BAD_REQUEST.getStatusCode());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy