net.sf.ehcache.management.resource.services.ElementsResourceServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
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.
/*
* 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.service.CacheService;
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.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/**
* A resource service interface for implementations interacting with cache elements.
*
* @author brandony
*/
@Path("/agents/cacheManagers/caches/elements")
public final class ElementsResourceServiceImpl {
private static final Logger LOG = LoggerFactory.getLogger(ElementsResourceServiceImpl.class);
private final CacheService cacheSvc;
private final RequestValidator validator;
public ElementsResourceServiceImpl() {
this.validator = ServiceLocator.locate(RequestValidator.class);
this.cacheSvc = ServiceLocator.locate(CacheService.class);
}
/**
* Remove elements from the cache.
*
* @param info
* for this resource request
*/
@DELETE
public void deleteElements(@Context UriInfo info) {
LOG.debug(String.format("Invoking ElementsResourceServiceImpl.deleteElements: %s", info.getRequestUri()));
validator.validate(info);
String cacheManagerName = info.getPathSegments().get(1).getMatrixParameters().getFirst("names");
String cacheName = info.getPathSegments().get(2).getMatrixParameters().getFirst("names");
try {
cacheSvc.clearCache(cacheManagerName, cacheName);
} catch (ServiceExecutionException e) {
throw new ResourceRuntimeException("Failed to delete element", e, Response.Status.BAD_REQUEST.getStatusCode());
}
}
}