本文整理汇总了Java中com.codahale.metrics.annotation.ExceptionMetered类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionMetered类的具体用法?Java ExceptionMetered怎么用?Java ExceptionMetered使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionMetered类属于com.codahale.metrics.annotation包,在下文中一共展示了ExceptionMetered类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerExceptionMeteredAnnotations
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
private void registerExceptionMeteredAnnotations(final Method method,
final ExceptionMetered classLevelExceptionMetered) {
if (classLevelExceptionMetered != null) {
exceptionMeters.putIfAbsent(method,
new FeignOutboundMetricsDecorator.ExceptionMeterMetric(metricRegistry, method,
classLevelExceptionMetered));
return;
}
final ExceptionMetered annotation = method.getAnnotation(ExceptionMetered.class);
if (annotation != null) {
exceptionMeters.putIfAbsent(method,
new FeignOutboundMetricsDecorator.ExceptionMeterMetric(metricRegistry, method, annotation));
}
}
示例2: exception
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@Test(expected = FeignException.class)
public void exception() {
stubFor(post(anyUrl()).willReturn(aResponse().withStatus(400)));
MyClientWithAnnotationOnMethodLevel target = Feign.builder().invocationHandlerFactory(
new FeignOutboundMetricsDecorator(new InvocationHandlerFactory.Default(), metricRegistry))
.target(MyClientWithAnnotationOnMethodLevel.class,
String.format("http://localhost:%d", wireMockRule.port()));
try {
target.myMethod();
} finally {
assertMetrics();
Set<Map.Entry<String, Meter>> entries = metricRegistry.getMeters().entrySet();
entries.forEach(entry -> {
if (entry.getKey().endsWith(ExceptionMetered.DEFAULT_NAME_SUFFIX)) {
assertEquals(String.format("wrong number of invocations in metric %s", entry.getKey()), 1,
entry.getValue().getCount());
}
});
}
}
示例3: dcParseRecord
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@Timed
@ExceptionMetered
public void dcParseRecord(String url) throws IOException, URISyntaxException, InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
HttpGet httpGet = new HttpGet(url);
try (CloseableHttpClient closeableHttpClient = HttpClients.createDefault()) {
log.info("Send fetch list request {}", url);
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpGet);
JAXBElement<OAIPMHtype> records = (JAXBElement<OAIPMHtype>) unmarshaller.unmarshal(new StreamSource(closeableHttpResponse.getEntity().getContent()));
ListRecordsType list = records.getValue().getListRecords();
log.info("Submit {} record", list.getRecord().size());
recordListQueue.offer(list.getRecord());
if (list.getResumptionToken() != null && list.getResumptionToken().getValue().length() > 0) {
URIBuilder uriBuilder = new URIBuilder(url);
uriBuilder.setParameter("resumptionToken", list.getResumptionToken().getValue());
url = uriBuilder.build().toString();
log.info("Queue new url: {}, {}", list.getResumptionToken().getValue(), url);
urlQueue.put(url);
}
}
log.info("fetchListRecords() took {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
示例4: fetchListRecords
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@Timed
@ExceptionMetered
public void fetchListRecords(String url) throws IOException, URISyntaxException, InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
HttpGet httpGet = new HttpGet(url);
try (CloseableHttpClient closeableHttpClient = HttpClients.createDefault()) {
log.info("Send fetch list request {}", url);
CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpGet);
JAXBElement<OAIPMHtype> records = (JAXBElement<OAIPMHtype>) unmarshaller.unmarshal(new StreamSource(closeableHttpResponse.getEntity().getContent()));
ListRecordsType list = records.getValue().getListRecords();
log.info("Submit {} record", list.getRecord().size());
recordListQueue.offer(list.getRecord());
if (list.getResumptionToken() != null && list.getResumptionToken().getValue().length() > 0) {
URIBuilder uriBuilder = new URIBuilder(url);
uriBuilder.setParameter("resumptionToken", list.getResumptionToken().getValue());
url = uriBuilder.build().toString();
log.info("Queue new url: {}, {}", list.getResumptionToken().getValue(), url);
urlQueue.put(url);
}
}
log.info("fetchListRecords() took {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
示例5: getAllProductCatalog
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@GET
@Timed(name = "showAll-timed-get")
@Metered(name = "showAll-metered-get")
@ExceptionMetered
@CacheControl(maxAge = 12, maxAgeUnit = TimeUnit.HOURS)
public List<ProductCatalogRepresentation> getAllProductCatalog() {
LOGGER.info("Retrieving all product catalog details of the product");
List<ProductCatalog> details = productCatalogService.getAllProductDetails();
if (details == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
LOGGER.debug("Product details:" + details.toString());
List<ProductCatalogRepresentation> representations = new ArrayList<>();
for (ProductCatalog detail : details) {
representations.add(ProductRepresentationDomainConverter.toRepresentation(detail));
}
return representations;
}
示例6: getAllProductReviews
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@GET
@Path("/{skuId}")
@Timed(name = "showAll-timed-get")
@Metered(name = "showAll-metered-get")
@ExceptionMetered
@CacheControl(maxAge = 12, maxAgeUnit = TimeUnit.HOURS)
public List<ProductReviewRepresentation> getAllProductReviews(@PathParam("skuId") String skuId) {
LOGGER.info("Retrieving all product reviews of the product:" + skuId);
List<ProductReview> reviews = productReviewService.getAllProductReviews(skuId);
if (reviews == null || reviews.isEmpty()) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
List<ProductReviewRepresentation> representations = new ArrayList<>();
for (ProductReview review : reviews) {
representations.add(ProductReviewRepresentationDomainConverter.toRepresentation(review));
}
return representations;
}
示例7: getProductCatalog
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@GET
@Path("/{id}")
@Timed(name = "showAll-timed-get")
@Metered(name = "showAll-metered-get")
@ExceptionMetered
@CacheControl(maxAge = 12, maxAgeUnit = TimeUnit.SECONDS)
@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })
public ProductRepresentation getProductCatalog(@Auth User user, @PathParam("id") String id) throws Exception {
LOGGER.info("Fetching the product catalog for the product with id:" + id);
ProductRepresentation product = new ProductRepresentation();
JSONObject productCatalog = productCatalogClient.getProductCatalog(id);
if (productCatalog == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
product.setProductCatalog((HashMap<String, Object>) productCatalog.toMap());
List<HashMap<String, Object>> reviewList = new ArrayList<>();
List<Object> reviews = productReviewClient.getProductReviews(id).toList();
for (Object review : reviews) {
reviewList.add((HashMap<String, Object>) review);
}
product.setProductReviews(reviewList);
return product;
}
示例8: delete
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* This method will delete the {@link Customer} with the id provided.
*
* @param id
* the unique identifier for this customer
* @return {@link ResponseEntity} containing the HTTP headers and the HTTP
* status code
*/
@RequestMapping(value = "/customer/{id}", method = RequestMethod.DELETE, produces = JSON_MIME_TYPE)
@ResponseBody
@Timed
@ExceptionMetered
public ResponseEntity<String> delete(@PathVariable Long id, HttpServletRequest request) {
logApiCalls(request);
try {
Customer customer = customerService.findById(id);
System.out.println(customer.toString() + " found and will be deleted");
} catch (NoSuchElementException e) {
// Nothing to delete.
}
customerService.delete(id);
return new ResponseEntity<String>(createHeaders(request.getMethod()), HttpStatus.NO_CONTENT);
}
示例9: getSucceed
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Accept request and reply with OK.
*
* @param uriInfo Information about the URL for the request
* @param asyncResponse The response object to send the final response to
*/
@GET
@Timed(name = "logTimed")
@Metered(name = "logMetered")
@ExceptionMetered(name = "logException")
@Produces(MediaType.APPLICATION_JSON)
@Path("/log")
public void getSucceed(@Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
RequestLog.startTiming(this);
try {
Thread.sleep(200);
} catch (InterruptedException ignore) {
// Do nothing
}
RequestLog.stopTiming(this);
Response response = Response.status(Response.Status.OK).build();
asyncResponse.resume(response);
}
示例10: getFailWithWebAppException
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Accept request and reply with webapp exception and a simple string message.
*
* @param uriInfo Information about the URL for the request
*/
@GET
@Timed(name = "logTimed")
@Metered(name = "logMetered")
@ExceptionMetered(name = "logException")
@Produces(MediaType.APPLICATION_JSON)
@Path("/webbug")
public void getFailWithWebAppException(@Context UriInfo uriInfo) {
RequestLog.startTiming(this);
try {
Thread.sleep(200);
throw new WebApplicationException(
Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Oops! Web App Exception").build()
);
} catch (InterruptedException ignore) {
// Do nothing
}
}
示例11: getFailWithRuntimeException
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Accept request and reply with a generic runtime exception and a simple string message.
*
* @param uriInfo Information about the URL for the request
*/
@GET
@Timed(name = "logTimed")
@Metered(name = "logMetered")
@ExceptionMetered(name = "logException")
@Produces(MediaType.APPLICATION_JSON)
@Path("/genericbug")
public void getFailWithRuntimeException(@Context UriInfo uriInfo) {
RequestLog.startTiming(this);
try {
Thread.sleep(200);
throw new RuntimeException("Oops! Generic Exception");
} catch (InterruptedException ignore) {
// Do nothing
}
}
示例12: getData
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Collect async responses in list then respond to all 1 second later. This keeps Grizzly happy.
*
* @param uriInfo Information about the URL for the request
* @param asyncResponse The response object to send the final response to
*/
@GET
@Timed(name = "testTimed")
@Metered(name = "testMetered")
@ExceptionMetered(name = "testExc")
@Produces(MediaType.APPLICATION_JSON)
@Path("/data")
public void getData(@Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
synchronized (responses) {
if (responses.size() == 0) {
// start release thread
new Thread(this).start();
}
responses.add(new Pair<>(asyncResponse, RequestLog.dump()));
}
}
示例13: authenticate
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
@DirectMethod
@Timed
@ExceptionMetered
@Validate
public UserXO authenticate(@NotEmpty final String base64Username, @NotEmpty final String base64Password)
throws Exception
{
Subject subject = securitySystem.getSubject();
// FIXME: Subject is not nullable, but we have code that checks for nulls, likely from testing setups, verify and simplify
checkState(subject != null);
try {
subject.login(new UsernamePasswordToken(
Strings2.decodeBase64(base64Username),
Strings2.decodeBase64(base64Password),
false
));
}
catch (Exception e) {
throw new Exception("Authentication failed", e);
}
return getUser();
}
示例14: logout
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Logout and remove any session cookies
*
* @description Log out and remove any session cookies
* @responseMessage 200 Logged out successfully
*/
@Timed @ExceptionMetered
@POST
@Produces(APPLICATION_JSON)
public Response logout(@Nullable @CookieParam(value = "session") Cookie sessionCookie) {
if (sessionCookie != null) {
Optional<User> user = cookieAuthenticator.authenticate(sessionCookie);
if (user.isPresent()) {
logger.info("User logged out: {}", user.get().getName());
} else {
logger.warn("Invalid user cookie on logout.");
}
}
NewCookie expiredCookie = cookieFactory.getExpiredSessionCookie();
return Response.ok()
.header(HttpHeaders.SET_COOKIE, expiredCookie.toString())
.build();
}
示例15: deleteClient
import com.codahale.metrics.annotation.ExceptionMetered; //导入依赖的package包/类
/**
* Delete Client by ID
*
* @excludeParams user
* @param clientId the ID of the Client to be deleted
*
* @description Deletes a single Client if found.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Found and deleted Client with given ID
* @responseMessage 404 Client with given ID not Found
*/
@Path("{clientId}")
@Timed @ExceptionMetered
@DELETE
public Response deleteClient(@Auth User user, @PathParam("clientId") LongParam clientId) {
logger.info("User '{}' deleting client id={}.", user, clientId);
Optional<Client> client = clientDAO.getClientById(clientId.get());
if (!client.isPresent()) {
throw new NotFoundException("Client not found.");
}
clientDAO.deleteClient(client.get());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_DELETE, user.getName(), client.get().getName()));
return Response.noContent().build();
}