net.sf.ehcache.management.resource.services.AgentsResourceServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of management-ehcache-impl Show documentation
Show all versions of management-ehcache-impl Show documentation
A product library implementing the ehcache management resource service interfaces and integrating with ehcache to construct the relevant management resource entities.
/* 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terracotta.management.ServiceExecutionException;
import org.terracotta.management.ServiceLocator;
import org.terracotta.management.resource.AgentEntity;
import org.terracotta.management.resource.AgentMetadataEntity;
import org.terracotta.management.resource.exceptions.ResourceRuntimeException;
import org.terracotta.management.resource.services.AgentService;
import org.terracotta.management.resource.services.AgentsResourceService;
import org.terracotta.management.resource.services.validator.RequestValidator;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/**
* An embedded implementation of {@link org.terracotta.management.resource.services.AgentsResourceService}.
*
*
* @author brandony
*/
@Path("/agents")
public final class AgentsResourceServiceImpl implements AgentsResourceService {
private static final Logger LOG = LoggerFactory.getLogger(AgentsResourceServiceImpl.class);
private final AgentService agentService;
private final RequestValidator validator;
public AgentsResourceServiceImpl() {
this.agentService = ServiceLocator.locate(AgentService.class);
this.validator = ServiceLocator.locate(RequestValidator.class);
}
/**
* {@inheritDoc}
*/
public Collection getAgents(UriInfo info) {
LOG.debug(String.format("Invoking AgentsResourceServiceImpl.getAgents: %s", info.getRequestUri()));
String ids = info.getPathSegments().get(0).getMatrixParameters().getFirst("ids");
Set idSet;
if (ids == null) {
idSet = Collections.emptySet();
} else {
idSet = new HashSet(Arrays.asList(ids.split(",")));
}
try {
return agentService.getAgents(idSet);
} catch (ServiceExecutionException see) {
throw new ResourceRuntimeException("Failed to get agents", see, Response.Status.BAD_REQUEST.getStatusCode());
}
}
/**
* {@inheritDoc}
*/
@Override
public Collection getAgentsMetadata(UriInfo info) {
LOG.debug(String.format("Invoking AgentsResourceServiceImpl.getAgentsMetadata: %s", info.getRequestUri()));
validator.validateSafe(info);
String ids = info.getPathSegments().get(0).getMatrixParameters().getFirst("ids");
Set idSet;
if (ids == null) {
idSet = Collections.emptySet();
} else {
idSet = new HashSet(Arrays.asList(ids.split(",")));
}
try {
return agentService.getAgentsMetadata(idSet);
} catch (ServiceExecutionException see) {
throw new ResourceRuntimeException("Failed to get agents metadata", see, Response.Status.BAD_REQUEST.getStatusCode());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy