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

下面列出了怎么用com.codahale.metrics.annotation.Metered的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * {@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();
}
 
@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;
}
 
/**
 * {@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();
}
 
@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);
    }
}
 
/**
 * {@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;
}
 
源代码6 项目: 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);
    }
  }
}
 
源代码7 项目: 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);
  }
}
 
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();
}
 
源代码9 项目: 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;
}
 
源代码10 项目: 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;
}
 
源代码11 项目: 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);
    }
}
 
源代码12 项目: 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);
    }
}
 
源代码13 项目: 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);
    }
}
 
源代码14 项目: 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);
    }
}
 
源代码15 项目: 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;
}
 
@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;
}
 
源代码17 项目: metrics-cdi   文件: MetricsInterceptor.java
private void registerMetrics(Class<?> bean, Executable executable) {
    MetricResolver.Of<Counted> counted = resolver.counted(bean, executable);
    if (counted.isPresent())
        registry.counter(counted.metricName());

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

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

    MetricResolver.Of<Timed> timed = resolver.timed(bean, executable);
    if (timed.isPresent()) {
        extension.<BiFunction<String, Class<? extends Metric>, Optional<Reservoir>>>getParameter(ReservoirFunction)
            .flatMap(function -> function.apply(timed.metricName(), Timer.class))
            .map(reservoir -> registry.timer(timed.metricName(), () -> new Timer(reservoir)))
            .orElseGet(() -> registry.timer(timed.metricName()));
    }
}
 
源代码18 项目: 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() + "]");
}
 
源代码19 项目: metrics-cdi   文件: MetricResolver.java
private boolean isMetricAbsolute(Annotation annotation) {
    if (extension.<Boolean>getParameter(UseAbsoluteName).orElse(false))
        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() + "]");
}
 
源代码20 项目: taoshop   文件: 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;

}
 
/**
 * {@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();
}
 
@Audit(
    action="PROXY_GRANTING_TICKET",
    actionResolverName="GRANT_PROXY_GRANTING_TICKET_RESOLVER",
    resourceResolverName="GRANT_PROXY_GRANTING_TICKET_RESOURCE_RESOLVER")
@Timed(name="GRANT_PROXY_GRANTING_TICKET_TIMER")
@Metered(name="GRANT_PROXY_GRANTING_TICKET_METER")
@Counted(name="GRANT_PROXY_GRANTING_TICKET_COUNTER", monotonic=true)
@Override
public TicketGrantingTicket delegateTicketGrantingTicket(final String serviceTicketId, final Credential... credentials)
        throws AuthenticationException, TicketException {

    final ServiceTicket serviceTicket =  this.serviceTicketRegistry.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 = this.authenticationManager.authenticate(credentials);

    final String pgtId = this.ticketGrantingTicketUniqueTicketIdGenerator.getNewTicketId(
            TicketGrantingTicket.PROXY_GRANTING_TICKET_PREFIX);
    final TicketGrantingTicket proxyGrantingTicket = serviceTicket.grantTicketGrantingTicket(pgtId,
                                authentication, this.ticketGrantingTicketExpirationPolicy);

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

    return proxyGrantingTicket;
}
 
@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 Credential... credentials)
        throws AuthenticationException, TicketException {

    final Set<Credential> sanitizedCredentials = sanitizeCredentials(credentials);
    if (sanitizedCredentials.size() > 0) {
        final Authentication authentication = this.authenticationManager.authenticate(credentials);

        final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(
                this.ticketGrantingTicketUniqueTicketIdGenerator
                        .getNewTicketId(TicketGrantingTicket.PREFIX),
                authentication, this.ticketGrantingTicketExpirationPolicy);

        this.ticketRegistry.addTicket(ticketGrantingTicket);
        return ticketGrantingTicket;
    }
    final String msg = "No credentials were specified in the request for creating a new ticket-granting ticket";
    logger.warn(msg);
    throw new TicketCreationException(new IllegalArgumentException(msg));
}
 
/**
 * {@inheritDoc}
 */
@Timed(name = "GET_TICKETS_TIMER")
@Metered(name = "GET_TICKETS_METER")
@Counted(name="GET_TICKETS_COUNTER", monotonic=true)
@Override
public Collection<Ticket> getTickets(final Predicate predicate) {
    final Collection<Ticket> c = new HashSet<>(this.ticketRegistry.getTickets());
    final Iterator<Ticket> it = c.iterator();
    while (it.hasNext()) {
        if (!predicate.evaluate(it.next())) {
            it.remove();
        }
    }
    return c;
}
 
源代码25 项目: haven-platform   文件: MeterTest.java
@Metered(name = TEST_METHOD_METER, absolute = true)
// throughput in count per sec
@WatchdogRule(expression = "meter.meanRate < 10 and meter.count > 10", unit = TimeUnit.SECONDS)
public void method() throws InterruptedException {
    System.out.println("invoke 'method'");
    Thread.sleep(100);
}
 
源代码26 项目: codenvy   文件: SsoService.java
/**
 * Get principal with roles by token, and register user client on server.
 *
 * @throws AuthenticationException
 */
@Metered(name = "auth.sso.service_get_token")
@Produces(MediaType.APPLICATION_JSON)
@Path("{token}")
@GET
public SubjectDto getCurrentPrincipal(
    @PathParam("token") String token, @QueryParam("clienturl") String clientUrl)
    throws AuthenticationException, NotFoundException, ServerException {

  LOG.debug("Request user  with token {}", token);

  if (clientUrl == null || clientUrl.isEmpty()) {
    throw new AuthenticationException("Mandatory parameter client url is not found");
  }

  AccessTicket accessTicket = ticketManager.getAccessTicket(token);
  if (accessTicket == null) {
    throw new AuthenticationException("Access token not found or expired.");
  } else {
    accessTicket.registerClientUrl(clientUrl);
    User user = userManager.getById(accessTicket.getUserId());
    return DtoFactory.newDto(SubjectDto.class)
        .withName(user.getName())
        .withId(user.getId())
        .withToken(accessTicket.getAccessToken());
  }
}
 
源代码27 项目: codenvy   文件: SsoService.java
/**
 * Restore session cookie if persistent cookie is present, that allow re-login easily. If there is
 * no cookie user login as anonymous or gets error page if anonymous is restricted.
 *
 * @param redirectUrl - url for redirection after successful authentication.
 * @param tokenAccessCookie - cookie with authentication token
 */
@Metered(name = "auth.sso.service_refresh_token")
@Path("refresh")
@GET
public Response refresh(
    @QueryParam("redirect_url") String redirectUrl,
    @CookieParam("token-access-key") Cookie tokenAccessCookie,
    @Context UriInfo uriInfo)
    throws UnsupportedEncodingException {
  Response.ResponseBuilder builder;
  boolean isSecure = uriInfo.getRequestUri().getScheme().equals("https");
  try {
    if (tokenAccessCookie != null) {
      AccessTicket accessTicket = ticketManager.getAccessTicket(tokenAccessCookie.getValue());
      if (accessTicket != null) {

        UriBuilder destination = UriBuilder.fromUri(redirectUrl);
        destination.replaceQueryParam("cookiePresent", true);
        builder = Response.temporaryRedirect(destination.build());

        cookieBuilder.setCookies(builder, tokenAccessCookie.getValue(), isSecure);

        return builder.build();
      }
    }
    builder =
        Response.temporaryRedirect(
            new URI(loginPage + "?redirect_url=" + encode(redirectUrl, "UTF-8")));
  } catch (IOException | URISyntaxException e) {
    LOG.error(e.getLocalizedMessage(), e);
    builder = Response.serverError();
  }

  return builder.build();
}
 
源代码28 项目: Kylin   文件: ProjectController.java
@RequestMapping(value = "/{projectName}", method = { RequestMethod.DELETE })
@ResponseBody
@Metered(name = "deleteProject")
public void deleteProject(@PathVariable String projectName) {
    try {
        projectService.deleteProject(projectName);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete project. " + " Caused by: " + e.getMessage(), e);
    }
}
 
源代码29 项目: Kylin   文件: CubeController.java
@RequestMapping(value = "/{cubeName}/cost", method = {RequestMethod.PUT})
@ResponseBody
@Metered(name = "updateCubeCost")
public CubeInstance updateCubeCost(@PathVariable String cubeName, @RequestParam(value = "cost") int cost) {
    try {
        return cubeService.updateCubeCost(cubeName, cost);
    } catch (Exception e) {
        String message = "Failed to update cube cost: " + cubeName + " : " + cost;
        logger.error(message, e);
        throw new InternalErrorException(message + " Caused by: " + e.getMessage(), e);
    }
}
 
@ExceptionMetered(name = "exception")
@Gauge(name = "gauge")
@Metered(name = "meter")
@Timed(name = "timer")
public static String metricsMethod() {
    return "value";
}
 
 类所在包
 类方法
 同包方法