當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。