Java 类com.codahale.metrics.annotation.Metered 实例源码

项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
@Audit(
    action="TICKET_GRANTING_TICKET",
    actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER",
    resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
@Counted(name="CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public TicketGrantingTicket createTicketGrantingTicket(final AuthenticationContext context)
        throws AuthenticationException, AbstractTicketException {

    final Authentication authentication = context.getAuthentication();
    final TicketGrantingTicketFactory factory = this.ticketFactory.get(TicketGrantingTicket.class);
    final TicketGrantingTicket ticketGrantingTicket = factory.create(authentication);

    this.ticketRegistry.addTicket(ticketGrantingTicket);

    doPublishEvent(new CasTicketGrantingTicketCreatedEvent(this, ticketGrantingTicket));

    return ticketGrantingTicket;
}
项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 * Destroy a TicketGrantingTicket and perform back channel logout. This has the effect of invalidating any
 * Ticket that was derived from the TicketGrantingTicket being destroyed. May throw an
 * {@link IllegalArgumentException} if the TicketGrantingTicket ID is null.
 *
 * @param ticketGrantingTicketId the id of the ticket we want to destroy
 * @return the logout requests.
 */
@Audit(
        action="TICKET_GRANTING_TICKET_DESTROYED",
        actionResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
@Metered(name="DESTROY_TICKET_GRANTING_TICKET_METER")
@Counted(name="DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public List<LogoutRequest> destroyTicketGrantingTicket(@NotNull final String ticketGrantingTicketId) {
    try {
        logger.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
        final TicketGrantingTicket ticket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        logger.debug("Ticket found. Processing logout requests and then deleting the ticket...");
        final List<LogoutRequest> logoutRequests = logoutManager.performLogout(ticket);
        this.ticketRegistry.deleteTicket(ticketGrantingTicketId);
        return logoutRequests;
    } catch (final InvalidTicketException e) {
        logger.debug("TicketGrantingTicket [{}] cannot be found in the ticket registry.", ticketGrantingTicketId);
    }
    return Collections.emptyList();
}
项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
@Audit(
    action="SERVICE_TICKET",
    actionResolverName="GRANT_SERVICE_TICKET_RESOLVER",
    resourceResolverName="GRANT_SERVICE_TICKET_RESOURCE_RESOLVER")
@Timed(name = "GRANT_SERVICE_TICKET_TIMER")
@Metered(name="GRANT_SERVICE_TICKET_METER")
@Counted(name="GRANT_SERVICE_TICKET_COUNTER", monotonic=true)
@Override
public ServiceTicket grantServiceTicket(final String ticketGrantingTicketId,
    final Service service) throws TicketException {
    try {
        return this.grantServiceTicket(ticketGrantingTicketId, service, (Credential[]) null);
    } catch (final AuthenticationException e) {
        throw new IllegalStateException("Unexpected authentication exception", e);
    }
}
项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 */
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name="GET_TICKET_COUNTER", monotonic=true)
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<? extends Ticket> clazz)
        throws InvalidTicketException {
    Assert.notNull(ticketId, "ticketId cannot be null");
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);

    if (ticket == null) {
        logger.debug("Ticket [{}] by type [{}] cannot be found in the ticket registry.", ticketId, clazz.getSimpleName());
        throw new InvalidTicketException(ticketId);
    }

    if (ticket instanceof TicketGrantingTicket) {
        synchronized (ticket) {
            if (ticket.isExpired()) {
                this.ticketRegistry.deleteTicket(ticketId);
                logger.debug("Ticket [{}] has expired and is now deleted from the ticket registry.", ticketId);
                throw new InvalidTicketException(ticketId);
            }
        }
    }
    return (T) ticket;
}
项目:cas-5.1.0    文件:AbstractAuthenticationManager.java   
@Override
@Audit(
        action = "AUTHENTICATION",
        actionResolverName = "AUTHENTICATION_RESOLVER",
        resourceResolverName = "AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name = "AUTHENTICATE_TIMER")
@Metered(name = "AUTHENTICATE_METER")
@Counted(name = "AUTHENTICATE_COUNT", monotonic = true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {
    AuthenticationCredentialsLocalBinder.bindCurrent(transaction.getCredentials());
    final AuthenticationBuilder builder = authenticateInternal(transaction);
    final Authentication authentication = builder.build();
    final Principal principal = authentication.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(authentication);
    }
    addAuthenticationMethodAttribute(builder, authentication);
    LOGGER.info("Authenticated principal [{}] with attributes [{}] via credentials [{}].",
            principal.getId(), principal.getAttributes(), transaction.getCredentials());
    populateAuthenticationMetadataAttributes(builder, transaction);
    final Authentication a = builder.build();
    AuthenticationCredentialsLocalBinder.bindCurrent(a);
    return a;
}
项目:cas-server-4.2.1    文件:PolicyBasedAuthenticationManager.java   
@Override
@Audit(
    action="AUTHENTICATION",
    actionResolverName="AUTHENTICATION_RESOLVER",
    resourceResolverName="AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name="AUTHENTICATE_TIMED")
@Metered(name="AUTHENTICATE_METER")
@Counted(name="AUTHENTICATE_COUNT", monotonic=true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {

    final AuthenticationBuilder builder = authenticateInternal(transaction.getCredentials());
    final Authentication authentication = builder.build();
    final Principal principal = authentication.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(authentication);
    }

    addAuthenticationMethodAttribute(builder, authentication);

    logger.info("Authenticated {} with credentials {}.", principal, transaction.getCredentials());
    logger.debug("Attribute map for {}: {}", principal.getId(), principal.getAttributes());

    populateAuthenticationMetadataAttributes(builder, transaction.getCredentials());

    return builder.build();
}
项目:cas-server-4.2.1    文件:AbstractCentralAuthenticationService.java   
/**
 * {@inheritDoc}
 *
 * Note:
 * Synchronization on ticket object in case of cache based registry doesn't serialize
 * access to critical section. The reason is that cache pulls serialized data and
 * builds new object, most likely for each pull. Is this synchronization needed here?
 */
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name="GET_TICKET_COUNTER", monotonic=true)
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<? extends Ticket> clazz)
        throws InvalidTicketException {
    Assert.notNull(ticketId, "ticketId cannot be null");
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);

    if (ticket == null) {
        logger.debug("Ticket [{}] by type [{}] cannot be found in the ticket registry.", ticketId, clazz.getSimpleName());
        throw new InvalidTicketException(ticketId);
    }

    if (ticket instanceof TicketGrantingTicket) {
        synchronized (ticket) {
            if (ticket.isExpired()) {
                this.ticketRegistry.deleteTicket(ticketId);
                logger.debug("Ticket [{}] has expired and is now deleted from the ticket registry.", ticketId);
                throw new InvalidTicketException(ticketId);
            }
        }
    }
    return (T) ticket;
}
项目:cas-server-4.2.1    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 * Destroy a TicketGrantingTicket and perform back channel logout. This has the effect of invalidating any
 * Ticket that was derived from the TicketGrantingTicket being destroyed. May throw an
 * {@link IllegalArgumentException} if the TicketGrantingTicket ID is null.
 *
 * @param ticketGrantingTicketId the id of the ticket we want to destroy
 * @return the logout requests.
 */
@Audit(
        action="TICKET_GRANTING_TICKET_DESTROYED",
        actionResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
@Metered(name="DESTROY_TICKET_GRANTING_TICKET_METER")
@Counted(name="DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public List<LogoutRequest> destroyTicketGrantingTicket(@NotNull final String ticketGrantingTicketId) {
    try {
        logger.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
        final TicketGrantingTicket ticket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        logger.debug("Ticket found. Processing logout requests and then deleting the ticket...");
        final List<LogoutRequest> logoutRequests = logoutManager.performLogout(ticket);
        this.ticketRegistry.deleteTicket(ticketGrantingTicketId);

        doPublishEvent(new CasTicketGrantingTicketDestroyedEvent(this, ticket));

        return logoutRequests;
    } catch (final InvalidTicketException e) {
        logger.debug("TicketGrantingTicket [{}] cannot be found in the ticket registry.", ticketGrantingTicketId);
    }
    return Collections.emptyList();
}
项目:cas-server-4.2.1    文件:CentralAuthenticationServiceImpl.java   
@Audit(
    action="TICKET_GRANTING_TICKET",
    actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER",
    resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
@Counted(name="CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public TicketGrantingTicket createTicketGrantingTicket(final AuthenticationContext context)
        throws AuthenticationException, AbstractTicketException {

    final Authentication authentication = context.getAuthentication();
    final TicketGrantingTicketFactory factory = this.ticketFactory.get(TicketGrantingTicket.class);
    final TicketGrantingTicket ticketGrantingTicket = factory.create(authentication);

    this.ticketRegistry.addTicket(ticketGrantingTicket);

    doPublishEvent(new CasTicketGrantingTicketCreatedEvent(this, ticketGrantingTicket));

    return ticketGrantingTicket;
}
项目:cas4.1.9    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 * Destroy a TicketGrantingTicket and perform back channel logout. This has the effect of invalidating any
 * Ticket that was derived from the TicketGrantingTicket being destroyed. May throw an
 * {@link IllegalArgumentException} if the TicketGrantingTicket ID is null.
 *
 * @param ticketGrantingTicketId the id of the ticket we want to destroy
 * @return the logout requests.
 */
@Audit(
        action="TICKET_GRANTING_TICKET_DESTROYED",
        actionResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
@Metered(name="DESTROY_TICKET_GRANTING_TICKET_METER")
@Counted(name="DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public List<LogoutRequest> destroyTicketGrantingTicket(@NotNull final String ticketGrantingTicketId) {
    try {
        logger.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
        final TicketGrantingTicket ticket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        logger.debug("Ticket found. Processing logout requests and then deleting the ticket...");
        final List<LogoutRequest> logoutRequests = logoutManager.performLogout(ticket);
        this.ticketRegistry.deleteTicket(ticketGrantingTicketId);

        return logoutRequests;
    } catch (final InvalidTicketException e) {
        logger.debug("TicketGrantingTicket [{}] cannot be found in the ticket registry.", ticketGrantingTicketId);
    }
    return Collections.emptyList();
}
项目:cas4.1.9    文件:CentralAuthenticationServiceImpl.java   
@Audit(
    action="SERVICE_TICKET",
    actionResolverName="GRANT_SERVICE_TICKET_RESOLVER",
    resourceResolverName="GRANT_SERVICE_TICKET_RESOURCE_RESOLVER")
@Timed(name = "GRANT_SERVICE_TICKET_TIMER")
@Metered(name="GRANT_SERVICE_TICKET_METER")
@Counted(name="GRANT_SERVICE_TICKET_COUNTER", monotonic=true)
@Override
public ServiceTicket grantServiceTicket(final String ticketGrantingTicketId,
    final Service service) throws TicketException {
    try {
        return this.grantServiceTicket(ticketGrantingTicketId, service, (Credential[]) null);
    } catch (final AuthenticationException e) {
        throw new IllegalStateException("Unexpected authentication exception", e);
    }
}
项目:cas4.1.9    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 *
 * Note:
 * Synchronization on ticket object in case of cache based registry doesn't serialize
 * access to critical section. The reason is that cache pulls serialized data and
 * builds new object, most likely for each pull. Is this synchronization needed here?
 */
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name="GET_TICKET_COUNTER", monotonic=true)
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<? extends Ticket> clazz)
        throws InvalidTicketException {
    Assert.notNull(ticketId, "ticketId cannot be null");
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);

    if (ticket == null) {
        logger.debug("Ticket [{}] by type [{}] cannot be found in the ticket registry.", ticketId, clazz.getSimpleName());
        throw new InvalidTicketException(ticketId);
    }

    if (ticket instanceof TicketGrantingTicket) {
        synchronized (ticket) {
            if (ticket.isExpired()) {
                this.ticketRegistry.deleteTicket(ticketId);
                logger.debug("Ticket [{}] has expired and is now deleted from the ticket registry.", ticketId);
                throw new InvalidTicketException(ticketId);
            }
        }
    }
    return (T) ticket;
}
项目:dropwizard-microservices-example    文件:ProductCatalogResource.java   
@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;
}
项目:dropwizard-microservices-example    文件:ProductReviewResource.java   
@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;
}
项目:dropwizard-microservices-example    文件:ProductResource.java   
@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;
}
项目:fili    文件:TestLoggingServlet.java   
/**
 * 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);
}
项目:fili    文件:TestLoggingServlet.java   
/**
 * 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
    }
}
项目:fili    文件:TestLoggingServlet.java   
/**
 * 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
    }
}
项目:fili    文件:TestFilterServlet.java   
/**
 * 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()));
    }
}
项目:codenvy    文件:SsoService.java   
@Metered(name = "auth.sso.service_delete_token")
@Path("{token}")
@DELETE
public void unregisterToken(
    @PathParam("token") String token, @QueryParam("clienturl") String clientUrl)
    throws AuthenticationException {
  LOG.debug("Un-register token {} and client {} ", token, clientUrl);
  if (clientUrl == null || clientUrl.isEmpty()) {
    ticketManager.removeTicket(token);
  } else {
    AccessTicket accessTicket = ticketManager.getAccessTicket(token);
    if (accessTicket != null) {
      accessTicket.unRegisterClientUrl(clientUrl);
    }
  }
}
项目:cfg4j-sample-apps    文件:MainController.java   
@Metered(name = "hello.run")
public void run(String... args) throws Exception {
  Boolean wasAwake = false;

  ReksioConfig reksioConfig = configurationProvider.bind("reksio", ReksioConfig.class);

  while (true) {
    if (wasAwake != reksioConfig.awake()) {
      System.out.println("Reksio is now " + (reksioConfig.awake() ? "awake" : "asleep"));

      wasAwake = reksioConfig.awake();
    }

    Thread.sleep(500);
  }
}
项目:dropwizard-websockets    文件:EventDriverMetrics.java   
public EventDriverMetrics(final Class<?> endpointClass, MetricRegistry metrics) {
    final Class<?> klass = endpointClass;
    Metered metered = klass.getAnnotation(Metered.class);
    Timed timed = klass.getAnnotation(Timed.class);
    ExceptionMetered em = klass.getAnnotation(ExceptionMetered.class);
    this.onTextMeter = metered != null
            ? Optional.of(metrics.meter(MetricRegistry.name(metered.name(), klass.getName(), OnMessage.class.getSimpleName())))
            : Optional.empty();
    this.countOpened = metered != null
            ? Optional.of(metrics.counter(MetricRegistry.name(metered.name(), klass.getName(), OPEN_CONNECTIONS)))
            : Optional.empty();
    this.timer = timed != null
            ? Optional.of(metrics.timer(MetricRegistry.name(timed.name(), klass.getName())))
            : Optional.empty();
    this.exceptionMetered = em != null
            ? Optional.of(metrics.meter(MetricRegistry.name(em.name(), klass.getName(), OnError.class.getSimpleName())))
            : Optional.empty();
}
项目:Metrics-POC    文件:HomeController.java   
@Timed(name = "home view Timer", absolute=true)
    @Metered(name = "home view Meter", absolute=true)
    @Counted(name = "homeCount",monotonic=true)
//  @Gauge(name = "home view Gauge", absolute = true)
    @ExceptionMetered(name = "home view Exception Meter", absolute = true)
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Locale locale, Model model) {
        logger.info("Welcome home! The client locale is {}.", locale);
        Counter count = new Counter();
        count.inc();
        Date date = new Date();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

        for(int i=0;i<500000;i++);

        String formattedDate = dateFormat.format(date);

        model.addAttribute("serverTime", formattedDate  + "    :    " + user.getUsername());

        return "home";
    }
项目:Kylin    文件:ProjectController.java   
@RequestMapping(value = "", method = { RequestMethod.POST })
@ResponseBody
@Metered(name = "saveProject")
public ProjectInstance saveProject(@RequestBody CreateProjectRequest projectRequest) {
    if (StringUtils.isEmpty(projectRequest.getName())) {
        throw new InternalErrorException("A project name must be given to create a project");
    }

    ProjectInstance createdProj = null;
    try {
        createdProj = projectService.createProject(projectRequest);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage());
    }

    return createdProj;
}
项目:Kylin    文件:ProjectController.java   
@RequestMapping(value = "", method = { RequestMethod.PUT })
@ResponseBody
@Metered(name = "updateProject")
public ProjectInstance updateProject(@RequestBody UpdateProjectRequest projectRequest) {
    if (StringUtils.isEmpty(projectRequest.getFormerProjectName())) {
        throw new InternalErrorException("A project name must be given to update a project");
    }

    ProjectInstance updatedProj = null;
    try {
        updatedProj = projectService.updateProject(projectRequest);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage());
    }

    return updatedProj;
}
项目:Kylin    文件:CubeController.java   
@RequestMapping(value = "/{cubeName}/disable", method = {RequestMethod.PUT})
@ResponseBody
@Metered(name = "disableCube")
public CubeInstance disableCube(@PathVariable String cubeName) {
    try {
        CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

        if (cube == null) {
            throw new InternalErrorException("Cannot find cube " + cubeName);
        }

        return cubeService.disableCube(cube);
    } catch (Exception e) {
        String message = "Failed to disable cube: " + cubeName;
        logger.error(message, e);
        throw new InternalErrorException(message + " Caused by: " + e.getMessage(), e);
    }
}
项目:Kylin    文件:CubeController.java   
@RequestMapping(value = "/{cubeName}/purge", method = {RequestMethod.PUT})
@ResponseBody
@Metered(name = "purgeCube")
public CubeInstance purgeCube(@PathVariable String cubeName) {
    try {
        CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

        if (cube == null) {
            throw new InternalErrorException("Cannot find cube " + cubeName);
        }

        return cubeService.purgeCube(cube);
    } catch (Exception e) {
        String message = "Failed to purge cube: " + cubeName;
        logger.error(message, e);
        throw new InternalErrorException(message + " Caused by: " + e.getMessage(), e);
    }
}
项目:Kylin    文件:CubeController.java   
@RequestMapping(value = "/{cubeName}/enable", method = {RequestMethod.PUT})
@ResponseBody
@Metered(name = "enableCube")
public CubeInstance enableCube(@PathVariable String cubeName) {
    try {
        CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
        if (null == cube) {
            throw new InternalErrorException("Cannot find cube " + cubeName);
        }

        return cubeService.enableCube(cube);
    } catch (Exception e) {
        String message = "Failed to enable cube: " + cubeName;
        logger.error(message, e);
        throw new InternalErrorException(message + " Caused by: " + e.getMessage(), e);
    }
}
项目:Kylin    文件:CubeController.java   
@RequestMapping(value = "/{cubeName}", method = {RequestMethod.DELETE})
@ResponseBody
@Metered(name = "deleteCube")
public void deleteCube(@PathVariable String cubeName) {
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (null == cube) {
        throw new NotFoundException("Cube with name " + cubeName + " not found..");
    }

    try {
        cubeService.deleteCube(cube);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete cube. " + " Caused by: " + e.getMessage(), e);
    }
}
项目:Kylin    文件:TableController.java   
/**
 * Get available table list of the input database
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "", method = {RequestMethod.GET})
@ResponseBody
@Metered(name = "listSourceTables")
public List<TableDesc> getHiveTables(@RequestParam(value = "ext", required = false) boolean withExt, @RequestParam(value = "project", required = false) String project) {
    long start = System.currentTimeMillis();
    List<TableDesc> tables = null;
    try {
        tables = cubeMgmtService.getProjectManager().listDefinedTables(project);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage());
    }

    if (withExt) {
        tables = cloneTableDesc(tables);
    }
    long end = System.currentTimeMillis();
    logger.info("Return all table metadata in " + (end - start) + " seconds");

    return tables;
}
项目:cas-mfa    文件:MultiFactorAwareCentralAuthenticationService.java   
@Override
@Audit(
        action="TICKET_GRANTING_TICKET",
        actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
@Counted(name="CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
public TicketGrantingTicket createTicketGrantingTicket(final Credential... credentials) throws TicketException {
    final MultiFactorCredentials mfaCredentials = (MultiFactorCredentials) credentials[0];
    final Authentication authentication = mfaCredentials.getAuthentication();

    if (authentication == null) {
        throw new TicketCreationException(new RuntimeException("Authentication cannot be null"));
    }
    final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(
            this.ticketGrantingTicketUniqueTicketIdGenerator.getNewTicketId(TicketGrantingTicket.PREFIX),
            authentication,
            this.ticketGrantingTicketExpirationPolicy);

    this.ticketRegistry.addTicket(ticketGrantingTicket);
    return ticketGrantingTicket;
}
项目:metrics-cdi    文件:MetricsInterceptor.java   
private <E extends Member & AnnotatedElement> void registerMetrics(Class<?> bean, E element) {
    MetricResolver.Of<Counted> counted = resolver.counted(bean, element);
    if (counted.isPresent())
        registry.counter(counted.metricName());

    MetricResolver.Of<ExceptionMetered> exceptionMetered = resolver.exceptionMetered(bean, element);
    if (exceptionMetered.isPresent())
        registry.meter(exceptionMetered.metricName());

    MetricResolver.Of<Metered> metered = resolver.metered(bean, element);
    if (metered.isPresent())
        registry.meter(metered.metricName());

    MetricResolver.Of<Timed> timed = resolver.timed(bean, element);
    if (timed.isPresent())
        registry.timer(timed.metricName());
}
项目:metrics-cdi    文件:MetricResolver.java   
private String metricName(Annotation annotation) {
    if (CachedGauge.class.isInstance(annotation))
        return ((CachedGauge) annotation).name();
    else if (Counted.class.isInstance(annotation))
        return ((Counted) annotation).name();
    else if (ExceptionMetered.class.isInstance(annotation))
        return ((ExceptionMetered) annotation).name();
    else if (Gauge.class.isInstance(annotation))
        return ((Gauge) annotation).name();
    else if (Metered.class.isInstance(annotation))
        return ((Metered) annotation).name();
    else if (Timed.class.isInstance(annotation))
        return ((Timed) annotation).name();
    else
        throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]");
}
项目:metrics-cdi    文件:MetricResolver.java   
private boolean isMetricAbsolute(Annotation annotation) {
    if (extension.getParameters().contains(MetricsParameter.useAbsoluteName))
        return true;

    if (CachedGauge.class.isInstance(annotation))
        return ((CachedGauge) annotation).absolute();
    else if (Counted.class.isInstance(annotation))
        return ((Counted) annotation).absolute();
    else if (ExceptionMetered.class.isInstance(annotation))
        return ((ExceptionMetered) annotation).absolute();
    else if (Gauge.class.isInstance(annotation))
        return ((Gauge) annotation).absolute();
    else if (Metered.class.isInstance(annotation))
        return ((Metered) annotation).absolute();
    else if (Timed.class.isInstance(annotation))
        return ((Timed) annotation).absolute();
    else
        throw new IllegalArgumentException("Unsupported Metrics forMethod [" + annotation.getClass().getName() + "]");
}
项目:springboot-shiro-cas-mybatis    文件:PolicyBasedAuthenticationManager.java   
@Override
@Audit(
    action="AUTHENTICATION",
    actionResolverName="AUTHENTICATION_RESOLVER",
    resourceResolverName="AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name="AUTHENTICATE_TIMED")
@Metered(name="AUTHENTICATE_METER")
@Counted(name="AUTHENTICATE_COUNT", monotonic=true)
public Authentication authenticate(final AuthenticationTransaction transaction) throws AuthenticationException {

    final AuthenticationBuilder builder = authenticateInternal(transaction.getCredentials());
    final Authentication authentication = builder.build();
    final Principal principal = authentication.getPrincipal();
    if (principal instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(authentication);
    }

    addAuthenticationMethodAttribute(builder, authentication);

    logger.info("Authenticated {} with credentials {}.", principal, transaction.getCredentials());
    logger.debug("Attribute map for {}: {}", principal.getId(), principal.getAttributes());

    populateAuthenticationMetadataAttributes(builder, transaction.getCredentials());

    return builder.build();
}
项目:springboot-shiro-cas-mybatis    文件:AbstractCentralAuthenticationService.java   
/**
 * {@inheritDoc}
 *
 * Note:
 * Synchronization on ticket object in case of cache based registry doesn't serialize
 * access to critical section. The reason is that cache pulls serialized data and
 * builds new object, most likely for each pull. Is this synchronization needed here?
 */
@Transactional(readOnly = true, transactionManager = "ticketTransactionManager")
@Timed(name = "GET_TICKET_TIMER")
@Metered(name = "GET_TICKET_METER")
@Counted(name="GET_TICKET_COUNTER", monotonic=true)
@Override
public <T extends Ticket> T getTicket(final String ticketId, final Class<? extends Ticket> clazz)
        throws InvalidTicketException {
    Assert.notNull(ticketId, "ticketId cannot be null");
    final Ticket ticket = this.ticketRegistry.getTicket(ticketId, clazz);

    if (ticket == null) {
        logger.debug("Ticket [{}] by type [{}] cannot be found in the ticket registry.", ticketId, clazz.getSimpleName());
        throw new InvalidTicketException(ticketId);
    }

    if (ticket instanceof TicketGrantingTicket) {
        synchronized (ticket) {
            if (ticket.isExpired()) {
                this.ticketRegistry.deleteTicket(ticketId);
                logger.debug("Ticket [{}] has expired and is now deleted from the ticket registry.", ticketId);
                throw new InvalidTicketException(ticketId);
            }
        }
    }
    return (T) ticket;
}
项目:springboot-shiro-cas-mybatis    文件:AbstractCentralAuthenticationService.java   
@Transactional(readOnly = true, transactionManager = "ticketTransactionManager")
@Timed(name = "GET_TICKETS_TIMER")
@Metered(name = "GET_TICKETS_METER")
@Counted(name="GET_TICKETS_COUNTER", monotonic=true)
@Override
public Collection<Ticket> getTickets(final Predicate<Ticket> predicate) {
    final Collection<Ticket> c = new HashSet<>(this.ticketRegistry.getTickets());
    final Iterator<Ticket> it = c.iterator();
    while (it.hasNext()) {
        if (!predicate.apply(it.next())) {
            it.remove();
        }
    }
    return c;
}
项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
/**
 * {@inheritDoc}
 * Destroy a TicketGrantingTicket and perform back channel logout. This has the effect of invalidating any
 * Ticket that was derived from the TicketGrantingTicket being destroyed. May throw an
 * {@link IllegalArgumentException} if the TicketGrantingTicket ID is null.
 *
 * @param ticketGrantingTicketId the id of the ticket we want to destroy
 * @return the logout requests.
 */
@Audit(
        action="TICKET_GRANTING_TICKET_DESTROYED",
        actionResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOLVER",
        resourceResolverName="DESTROY_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
@Metered(name="DESTROY_TICKET_GRANTING_TICKET_METER")
@Counted(name="DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public List<LogoutRequest> destroyTicketGrantingTicket(@NotNull final String ticketGrantingTicketId) {
    try {
        logger.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
        final TicketGrantingTicket ticket = getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
        logger.debug("Ticket found. Processing logout requests and then deleting the ticket...");
        final List<LogoutRequest> logoutRequests = logoutManager.performLogout(ticket);
        this.ticketRegistry.deleteTicket(ticketGrantingTicketId);

        doPublishEvent(new CasTicketGrantingTicketDestroyedEvent(this, ticket));

        return logoutRequests;
    } catch (final InvalidTicketException e) {
        logger.debug("TicketGrantingTicket [{}] cannot be found in the ticket registry.", ticketGrantingTicketId);
    }
    return Collections.emptyList();
}
项目:springboot-shiro-cas-mybatis    文件:CentralAuthenticationServiceImpl.java   
@Audit(
        action="PROXY_GRANTING_TICKET",
        actionResolverName="CREATE_PROXY_GRANTING_TICKET_RESOLVER",
        resourceResolverName="CREATE_PROXY_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name = "CREATE_PROXY_GRANTING_TICKET_TIMER")
@Metered(name = "CREATE_PROXY_GRANTING_TICKET_METER")
@Counted(name="CREATE_PROXY_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public ProxyGrantingTicket createProxyGrantingTicket(final String serviceTicketId, final AuthenticationContext context)
        throws AuthenticationException, AbstractTicketException {

    final ServiceTicket serviceTicket =  this.ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class);

    if (serviceTicket == null || serviceTicket.isExpired()) {
        logger.debug("ServiceTicket [{}] has expired or cannot be found in the ticket registry", serviceTicketId);
        throw new InvalidTicketException(serviceTicketId);
    }

    final RegisteredService registeredService = this.servicesManager
            .findServiceBy(serviceTicket.getService());

    verifyRegisteredServiceProperties(registeredService, serviceTicket.getService());

    if (!registeredService.getProxyPolicy().isAllowedToProxy()) {
        logger.warn("ServiceManagement: Service [{}] attempted to proxy, but is not allowed.", serviceTicket.getService().getId());
        throw new UnauthorizedProxyingException();
    }

    final Authentication authentication = context.getAuthentication();
    final ProxyGrantingTicketFactory factory = this.ticketFactory.get(ProxyGrantingTicket.class);
    final ProxyGrantingTicket proxyGrantingTicket = factory.create(serviceTicket, authentication);

    logger.debug("Generated proxy granting ticket [{}] based off of [{}]", proxyGrantingTicket, serviceTicketId);
    this.ticketRegistry.addTicket(proxyGrantingTicket);

    doPublishEvent(new CasProxyGrantingTicketCreatedEvent(this, proxyGrantingTicket));

    return proxyGrantingTicket;

}
项目:springboot-shiro-cas-mybatis    文件:PolicyBasedAuthenticationManager.java   
/**
 * {@inheritDoc}
 */
@Override
@Audit(
    action="AUTHENTICATION",
    actionResolverName="AUTHENTICATION_RESOLVER",
    resourceResolverName="AUTHENTICATION_RESOURCE_RESOLVER")
@Timed(name="AUTHENTICATE")
@Metered(name="AUTHENTICATE")
@Counted(name="AUTHENTICATE", monotonic=true)
public final Authentication authenticate(final Credential... credentials) throws AuthenticationException {

    final AuthenticationBuilder builder = authenticateInternal(credentials);
    final Authentication authentication = builder.build();
    final Principal principal = authentication.getPrincipal();
    if (principal  instanceof NullPrincipal) {
        throw new UnresolvedPrincipalException(authentication);
    }

    for (final HandlerResult result : authentication.getSuccesses().values()) {
        builder.addAttribute(AUTHENTICATION_METHOD_ATTRIBUTE, result.getHandlerName());
    }

    logger.info("Authenticated {} with credentials {}.", principal, Arrays.asList(credentials));
    logger.debug("Attribute map for {}: {}", principal.getId(), principal.getAttributes());

    for (final AuthenticationMetaDataPopulator populator : this.authenticationMetaDataPopulators) {
        for (final Credential credential : credentials) {
            if (populator.supports(credential)) {
                populator.populateAttributes(builder, credential);
            }
        }
    }

    return builder.build();
}