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

net.sf.ehcache.management.resource.services.QueryResourceServiceImpl 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
package net.sf.ehcache.management.resource.services;

import java.util.Collection;
import java.util.List;

import javax.ws.rs.Path;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import net.sf.ehcache.management.resource.QueryResultsEntity;
import net.sf.ehcache.management.service.CacheManagerService;

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

/**
 * 

An implementation of {@link QueryResourceService}.

* * @author gkeim */ @Path("/agents/cacheManagers/query") public final class QueryResourceServiceImpl implements QueryResourceService { private static final Logger LOG = LoggerFactory.getLogger(QueryResourceServiceImpl.class); private final RequestValidator validator; private final CacheManagerService cacheMgrSvc; public QueryResourceServiceImpl() { this.validator = ServiceLocator.locate(RequestValidator.class); this.cacheMgrSvc = ServiceLocator.locate(CacheManagerService.class); } /** * {@inheritDoc} */ @Override public Collection executeQuery(UriInfo info) { LOG.debug(String.format("Invoking executeQuery: %s", info.getRequestUri())); validator.validateSafe(info); String cacheManagerName = info.getPathSegments().get(1).getMatrixParameters().getFirst("names"); MultivaluedMap qParams = info.getQueryParameters(); List querys = qParams.get(ATTR_QUERY_KEY); String queryString = querys.size() > 0 ? querys.get(0) : null; try { return cacheMgrSvc.executeQuery(cacheManagerName, queryString); } catch (ServiceExecutionException e) { Throwable t = ExceptionUtils.getRootCause(e); throw new ResourceRuntimeException("Failed to execute query", t, Response.Status.BAD_REQUEST.getStatusCode()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy