当前位置: 首页>>代码示例>>Java>>正文


Java Timer.time方法代码示例

本文整理汇总了Java中com.codahale.metrics.Timer.time方法的典型用法代码示例。如果您正苦于以下问题:Java Timer.time方法的具体用法?Java Timer.time怎么用?Java Timer.time使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codahale.metrics.Timer的用法示例。


在下文中一共展示了Timer.time方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendHealthCheckRequest

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
public MatchingServiceHealthCheckResponseDto sendHealthCheckRequest(
        final Element matchingServiceHealthCheckRequest,
        final URI matchingServiceUri) {

    // Use a custom timer so that we get separate metrics for each matching service
    final String scope = matchingServiceUri.toString().replace(':','_').replace('/', '_');
    final Timer timer = metricsRegistry.timer(MetricRegistry.name(MatchingServiceHealthCheckClient.class, "sendHealthCheckRequest", scope));
    final Timer.Context context = timer.time();
    HealthCheckResponse healthCheckResponse;
    try {
        healthCheckResponse = client.makeSoapRequestForHealthCheck(matchingServiceHealthCheckRequest, matchingServiceUri);
    } catch(ApplicationException ex) {
        final String errorMessage = MessageFormat.format("Failed to complete matching service health check to {0}.", matchingServiceUri);
        LOG.warn(errorMessage, ex);
        return new MatchingServiceHealthCheckResponseDto(Optional.<String>absent(), Optional.<String>absent());
    } finally {
        context.stop();
    }

    return new MatchingServiceHealthCheckResponseDto(
                Optional.of(XmlUtils.writeToString(healthCheckResponse.getResponseElement())),
                healthCheckResponse.getVersionNumber());
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:24,代码来源:MatchingServiceHealthCheckClient.java

示例2: invoke

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {

    EnableMetricTimer annotation = methodInvocation.getThis().getClass().getAnnotation(EnableMetricTimer.class);

    String name = StringUtils.isBlank(annotation.value())
            ? methodInvocation.getThis().getClass().getName() + "." + methodInvocation.getMethod().getName()
            : annotation.value();

    Timer meter = Jboot.me().getMetric().timer(name);
    Timer.Context timerContext = meter.time();
    try {
        return methodInvocation.proceed();
    } finally {
        timerContext.stop();
    }

}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:19,代码来源:JbootMetricTimerAopInterceptor.java

示例3: allLinks

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@RequestMapping("/all-links")
public String allLinks(Model model) {
	Timer timer = metricRegistry.timer("all-links");
	Context context = timer.time();
	try {
		List<Link> asdex = linkRepo.findByNameContainingOrderByNameAsc("ASDE-X");
		model.addAttribute("asdex", asdex);
		List<Link> assc = linkRepo.findByNameContainingOrderByNameAsc("ASSC");
		model.addAttribute("assc", assc);
		List<Link> tdls = linkRepo.findByNameContainingOrderByNameAsc("TDLS");
		model.addAttribute("tdls", tdls);
		List<Link> efsts = linkRepo.findByNameContainingOrderByNameAsc("EFSTS");
		model.addAttribute("efsts", efsts);
		List<Link> stars = linkRepo.findByNameContainingOrderByNameAsc("STARS");
		model.addAttribute("stars", stars);
		List<Link> rvr = linkRepo.findByNameContainingOrderByNameAsc("RVR");
		model.addAttribute("rvr", rvr);

		return "all-links";
	} finally {
		context.stop();
	}
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:24,代码来源:STDDSController.java

示例4: apply

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
/**
 * Uses 2 timers to measure message processing rate. One for overall message processing rate and
 * another to measure rate by message type. The timers are re-used if they were previously created.
 *
 * <p>
 * {@link com.codahale.metrics.MetricRegistry} maintains a reservoir for different timers where
 * collected timings are kept. It exposes various metrics for each timer based on collected
 * data. Eg: count of messages, 99, 95, 50... percentiles, max, mean etc.
 *
 * <p>
 * These metrics are exposed as JMX bean.
 *
 * @see <a href="http://dropwizard.github.io/metrics/manual/core/#timers">
 *     http://dropwizard.github.io/metrics/manual/core/#timers</a>
 *
 * @param message the message to process
 * @throws Exception on message failure
 */
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void apply(final Object message) throws Exception {
    final String messageType = message.getClass().getSimpleName();

    final String msgProcessingTimeByMsgType =
            MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType);

    final Timer msgProcessingTimerByMsgType = metricRegistry.timer(msgProcessingTimeByMsgType);

    //start timers
    final Timer.Context context = msgProcessingTimer.time();
    final Timer.Context contextByMsgType = msgProcessingTimerByMsgType.time();

    try {
        meteredActor.onReceive(message);
    } catch (Throwable e) {
        Throwables.propagateIfPossible(e, Exception.class);
        throw new RuntimeException(e);
    } finally {
        //stop timers
        contextByMsgType.stop();
        context.stop();
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:44,代码来源:MeteringBehavior.java

示例5: metric

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
default <T> T metric(Timer timer, Meter meter, Supplier<T> supplier) {
  Timer.Context time = timer.time();
  try {
    meter.mark();
    return supplier.get();
  } finally {
    time.stop();
  }
}
 
开发者ID:dehora,项目名称:outland,代码行数:10,代码来源:MeterTimer.java

示例6: timed

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
default <T> T timed(Timer timer, Supplier<T> supplier) {
  Timer.Context time = timer.time();
  try {
    return supplier.get();
  } finally {
    time.stop();
  }
}
 
开发者ID:dehora,项目名称:outland,代码行数:9,代码来源:MetricsTimer.java

示例7: invoke

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@Override
public Object invoke(Object[] argv) throws Throwable {
    try {

        final Meter meter = this.meters.get(method);
        if (meter != null) {
            meter.mark();
        }

        final Timer timer = this.timers.get(method);
        if (timer != null) {
            this.context = timer.time();
        }

        return methodHandler.invoke(argv);

    } catch (Exception e) {

        final FeignOutboundMetricsDecorator.ExceptionMeterMetric metric =
                (method != null) ? this.exceptionMeters.get(method) : null;

        if (metric != null && (metric.cause.isAssignableFrom(e.getClass()) || (e.getCause() != null
                && metric.cause.isAssignableFrom(e.getCause().getClass())))) {
            metric.meter.mark();
        }

        throw e;
    } finally {
        if (this.context != null) {
            this.context.close();
        }
    }
}
 
开发者ID:mwiede,项目名称:metrics-feign,代码行数:34,代码来源:FeignOutboundMetricsDecorator.java

示例8: testTimerTime

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@Test
public void testTimerTime() throws Exception {
  Timer a = registry.timer("B");
  Context context = a.time();
  context.stop();
  assertEquals(a, updatedMetric);
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:8,代码来源:TracingMetricRegistryTest.java

示例9: index

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@RequestMapping("/index")
public String index(Model model) {
	Timer timer = metricRegistry.timer("index");
	Context context = timer.time();
	try {
		List<Tracon> tracons = traconRepo.findAllByOrderByNameAsc();
		model.addAttribute("tracons", tracons);
		return "index";
	} finally {
		context.stop();
	}
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:13,代码来源:STDDSController.java

示例10: allBuilds

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
@RequestMapping("/all-builds")
public String allBuilds(Model model) {
	Timer timer = metricRegistry.timer("all-builds");
	Context context = timer.time();
	try {
		List<SiteStatus> statuses = statusRepo.findAllByOrderByTraconAsc();
		model.addAttribute("statuses", statuses);
		return "all-builds";
	} finally {
		context.stop();
	}
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:13,代码来源:STDDSController.java

示例11: startTimer

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
/**
 * Initializes a specific timer for a given operation.
 *
 * @param op Specific operation being metered
 * @return timer context
 */
public Context startTimer(String op) {
    if (!activated) {
        return nullTimer;
    }
    // Check if timer exists, if it doesn't creates it
    final Timer currTimer = perObjOpTimers.computeIfAbsent(op, timer ->
            metricsService.createTimer(metricsComponent, metricsFeature, op));
    perOpTimers.computeIfAbsent(op, timer -> metricsService.createTimer(metricsComponent, wildcard, op));
    // Starts timer
    return new Context(currTimer.time(), op);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:MeteringAgent.java

示例12: refreshStatus

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
public GameServer refreshStatus(GameServer server) {
    if (server == null) {
        return null;
    }

    Timer timer = getDelayTimer(server);
    Timer.Context context = timer.time();
    int delay;
    try {
        SourceServer source = gameQueryService.getServerInfo(getInetSocketAddress(server)).join();
        delay = Long.valueOf(nanosToMillis(context.stop())).intValue();

        String mapName = source.getMapName();
        int players = source.getNumOfPlayers();
        int max = source.getMaxPlayers();
        String versionString = source.getGameVersion();
        int tvPort = source.getTvPort();

        Histogram histogram = getPlayerHistogram(server);
        histogram.update(players);

        server.setStatusCheckDate(ZonedDateTime.now());
        server.setMap(mapName);
        server.setPlayers(players);
        server.setMaxPlayers(max);
        server.setVersion(checkedParseInt(versionString));
        server.setTvPort(tvPort);

        playerCountMap.put(server, players);
    } catch (Exception e) {
        if (e.getCause() instanceof ReadTimeoutException) {
            log.info("[{}] Status check timed out", server);
        } else {
            log.warn("[{}] Failed to refresh status: {}", server, e.toString());
        }
        delay = Long.valueOf(nanosToMillis(context.stop())).intValue();
    }

    server.setPing(delay);
    if (getStatusMonitor(server).check(delay) != Monitor.State.BAD) {
        server.setLastValidPing(ZonedDateTime.now());
    }
    // clear cached data if last valid ping was at least 30 minutes ago
    if (server.getLastValidPing().plusMinutes(15).isBefore(ZonedDateTime.now())) {
        log.info("[{}] Clearing cached data from {}", server, formatRelative(server.getLastValidPing()));
        server.setMap("");
        server.setPlayers(0);
        server.setMaxPlayers(0);
        server.setTvPort(0);
    }
    return server;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:53,代码来源:GameServerService.java

示例13: testScanLibrary

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
/**
 * Tests the MediaScannerService by scanning the test media library into an empty database.
 */
@Test
public void testScanLibrary() {
    MusicFolderTestData.getTestMusicFolders().forEach(musicFolderDao::createMusicFolder);
    settingsService.clearMusicFolderCache();

    Timer globalTimer = metrics.timer(MetricRegistry.name(MediaScannerServiceTestCase.class, "Timer.global"));

    Timer.Context globalTimerContext = globalTimer.time();
    TestCaseUtils.execScan(mediaScannerService);
    globalTimerContext.stop();

    System.out.println("--- Report of records count per table ---");
    Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper);
    records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString()));
    System.out.println("--- *********************** ---");


    // Music Folder Music must have 3 children
    List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath());
    Assert.assertEquals(3, listeMusicChildren.size());
    // Music Folder Music2 must have 1 children
    List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath());
    Assert.assertEquals(1, listeMusic2Children.size());

    System.out.println("--- List of all artists ---");
    System.out.println("artistName#albumCount");
    List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders());
    allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount()));
    System.out.println("--- *********************** ---");

    System.out.println("--- List of all albums ---");
    System.out.println("name#artist");
    List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
    allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
    Assert.assertEquals(5, allAlbums.size());
    System.out.println("--- *********************** ---");

    List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders());
    Assert.assertEquals(2, listeSongs.size());

    // display out metrics report
    ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
            .convertRatesTo(TimeUnit.SECONDS.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
    reporter.report();

    System.out.print("End");
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:53,代码来源:MediaScannerServiceTestCase.java

示例14: startTimer

import com.codahale.metrics.Timer; //导入方法依赖的package包/类
/**
 * Starts the Metric Timer.
 * <p>
 * If the given timer was null, it will silently return null.
 * </p>
 *
 * @param timer timer to start
 * @return timing context, if timer was not null
 */
public static Context startTimer(Timer timer) {
    if (timer != null) {
        return timer.time();
    }
    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:MetricsUtil.java


注:本文中的com.codahale.metrics.Timer.time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。