application/randompublish-quarkus/src/main/java/webapp/tier/resource/RandomResource.java
package webapp.tier.resource;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.metrics.MetricUnits;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Timed;
import webapp.tier.service.RandomService;
@ApplicationScoped
@Path("/random")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class RandomResource {
@Inject
RandomService randomsvc;
@GET
@Counted(name = "performedChecks", description = "How many primality checks have been performed.")
@Timed(name = "checksTimer", description = "A measure of how long it takes to perform the primality test.", unit = MetricUnits.MILLISECONDS)
public Response random() {
try {
return Response.ok().entity(randomsvc.deliverrandom(randomsvc.getNum(6)))
.build();
} catch (Exception e) {
return Response.status(500).entity(e.getMessage()).build();
}
}
}