當前位置: 首頁>>代碼示例>>Java>>正文


Java Timer類代碼示例

本文整理匯總了Java中com.codahale.metrics.Timer的典型用法代碼示例。如果您正苦於以下問題:Java Timer類的具體用法?Java Timer怎麽用?Java Timer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Timer類屬於com.codahale.metrics包,在下文中一共展示了Timer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: TrainingFetcher

import com.codahale.metrics.Timer; //導入依賴的package包/類
TrainingFetcher(MetricSampler metricSampler,
                Cluster cluster,
                SampleStore sampleStore,
                Set<TopicPartition> assignedPartitions,
                long startTimeMs,
                long endTimeMs,
                Timer fetcherTimer,
                Meter fetcherFailureRate) {
  _cluster = cluster;
  _sampleStore = sampleStore;
  _metricSampler = metricSampler;
  _startTimeMs = startTimeMs;
  _endTimeMs = endTimeMs;
  _assignedPartitions = assignedPartitions;
  _fetcherTimer = fetcherTimer;
  _fetcherFailureRate = fetcherFailureRate;
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:18,代碼來源:TrainingFetcher.java

示例2: fetchMetricsForAssignedPartitions

import com.codahale.metrics.Timer; //導入依賴的package包/類
@Override
protected void fetchMetricsForAssignedPartitions() throws MetricSamplingException {
  final Timer.Context ctx = _fetcherTimer.time();

  try {
    MetricSampler.Samples samples =
        _metricSampler.getSamples(_cluster, _assignedPartitions, _startTimeMs, _endTimeMs, MetricSampler.SamplingMode.BROKER_METRICS_ONLY);
    ModelParameters.addMetricObservation(samples.brokerMetricSamples());

    _sampleStore.storeSamples(samples);
  } catch (Exception e) {
    _fetcherFailureRate.mark();
    throw e;
  } finally {
    ctx.stop();
  }
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:18,代碼來源:TrainingFetcher.java

示例3: ChangeLoader

import com.codahale.metrics.Timer; //導入依賴的package包/類
/**
 * Create a new {@code ChangeLoader}.
 *
 * @param cxt the Bireme Context
 * @param pipeLine the {@code PipeLine} belongs to
 * @param mappedTable the target table
 * @param taskIn a queue to get {@code LoadTask}
 */
public ChangeLoader(Context cxt, PipeLine pipeLine, String mappedTable,
    LinkedBlockingQueue<Future<LoadTask>> taskIn) {
  this.cxt = cxt;
  this.conf = cxt.conf;
  this.conn = null;
  this.mappedTable = mappedTable;
  this.table = cxt.tablesInfo.get(mappedTable);
  this.taskIn = taskIn;
  this.copyThread = Executors.newFixedThreadPool(1);

  // add statistics
  Timer[] timers = pipeLine.stat.addTimerForLoader(mappedTable);
  copyForDeleteTimer = timers[0];
  deleteTimer = timers[1];
  copyForInsertTimer = timers[2];

  logger = pipeLine.logger;
}
 
開發者ID:HashDataInc,項目名稱:bireme,代碼行數:27,代碼來源:ChangeLoader.java

示例4: 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

示例5: main

import com.codahale.metrics.Timer; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    Bench<JedisPool> bench = new JedisBench() {
        @Override
        public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            Jedis jedis = benchInstance.getResource();
            
            Timer.Context time = metrics.timer("incr").time();
            jedis.incr("incr_" + threadNumber + "_" + iteration);
            time.stop();
            
            jedis.close();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
開發者ID:redisson,項目名稱:redisson-benchmark,代碼行數:19,代碼來源:AtomicLongIncBenchmark.java

示例6: removeGraphRelation

import com.codahale.metrics.Timer; //導入依賴的package包/類
private void removeGraphRelation(
    Group group,
    String relation,
    String subjectType,
    String subjectKey,
    String objectType,
    String objectKey,
    Timer timer
) {
  final String rel = REL_MARK;
  final String inv = INV_MARK;

  final String relationHashKey = subjectType + "." + subjectKey;
  final String relationRangeKey = rel + relation + "." + objectType + "." + objectKey;
  timed(timer,
      () -> groupStorage.removeRelation(group, relationHashKey, relationRangeKey));

  final String inverseRelationHashKey = objectType + "." + objectKey;
  final String inverseRelationRangeKey = inv + relation + "." + subjectType + "." + subjectKey;
  timed(timer,
      () -> groupStorage.removeRelation(group, inverseRelationHashKey, inverseRelationRangeKey));
}
 
開發者ID:dehora,項目名稱:outland,代碼行數:23,代碼來源:DefaultGroupService.java

示例7: 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

示例8: main

import com.codahale.metrics.Timer; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    Bench<JedisPool> bench = new JedisBench() {
        @Override
        public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            Jedis jedis = benchInstance.getResource();

            Timer.Context time = metrics.timer("set").time();
            String key = "set_" + threadNumber;
            jedis.sadd(key, data);
            time.stop();

            jedis.close();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
開發者ID:redisson,項目名稱:redisson-benchmark,代碼行數:20,代碼來源:SetAddBenchmark.java

示例9: main

import com.codahale.metrics.Timer; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
    Bench<JedisPool> bench = new JedisBench() {
        @Override
        public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            Jedis jedis = benchInstance.getResource();

            Timer.Context time = metrics.timer("list").time();
            String key = "list_" + threadNumber;
            jedis.rpush(key, data);
            time.stop();

            jedis.close();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
開發者ID:redisson,項目名稱:redisson-benchmark,代碼行數:20,代碼來源:ListAddBenchmark.java

示例10: rxJava

import com.codahale.metrics.Timer; //導入依賴的package包/類
@Test
public void rxJava() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);

    RxJavaClient client = retrofit.create(RxJavaClient.class);
    client.timed()
            .subscribe(response -> {
                try {
                    assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_OK);
                    assertThat(response.body()).isEqualTo(RESPONSE_OBJECT);
                } finally {
                    latch.countDown();
                }
            }, error -> {
                throw new RuntimeException("Test failed");
            });
    latch.await(1L, TimeUnit.SECONDS);

    Timer timer = metrics.timer(TIMER_NAME);
    assertThat(timer).isNotNull();
    assertThat(timer.getCount()).isEqualTo(1);
    assertThat(timer.getMeanRate()).isGreaterThan(0);
}
 
開發者ID:cvent,項目名稱:retrofit-metrics,代碼行數:24,代碼來源:TimedCallAdapterFactoryTest.java

示例11: adjustRateLimit

import com.codahale.metrics.Timer; //導入依賴的package包/類
private void adjustRateLimit() {
    final long count = acquireCount.incrementAndGet();
    if (count >= pollOnCount) {
        final Timer commitTimer = actorContext.getOperationTimer(ActorContext.COMMIT);
        double newRateLimit = calculateNewRateLimit(commitTimer, commitTimeoutInSeconds);

        if (newRateLimit < 1.0) {
            newRateLimit = getRateLimitFromOtherDataStores();
        }

        if (newRateLimit >= 1.0) {
            txRateLimiter.setRate(newRateLimit);
            pollOnCount = count + (long) newRateLimit / 2;
        }
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:17,代碼來源:TransactionRateLimiter.java

示例12: setup

import com.codahale.metrics.Timer; //導入依賴的package包/類
@Before
public void setup() throws RpcCallException {
    handlerDictionary = new MethodHandlerDictionary();
    handlerDictionary.put("a", null);
    ServiceMethodHandlerUnderTest mockHandlerThrowsRpcCallEx = new ServiceMethodHandlerUnderTest();

    handlerDictionary.put("jsonRpcWithException", mockHandlerThrowsRpcCallEx);

    metricRegistry = mock(MetricRegistry.class);
    when(metricRegistry.counter(anyString())).thenReturn(mock(Counter.class));
    when(metricRegistry.timer(anyString())).thenReturn(mock(Timer.class));

    handlerMetrics = mock(RpcHandlerMetrics.class);
    when(handlerMetrics.getMethodTimer(any(), any(), any())).thenReturn(mock(GoTimer.class));

    servlet = new JsonHandler(handlerDictionary, metricRegistry, handlerMetrics, new ServiceProperties(), null);
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:18,代碼來源:JsonHandlerTest.java

示例13: assertMetrics

import com.codahale.metrics.Timer; //導入依賴的package包/類
private void assertMetrics() {
    Timer timer = metricRegistry.getTimers().values().iterator().next();
    assertEquals("wrong number of invocations in metric.", 1, timer.getCount());

    assertTrue("wrong value of mean in metric.", timer.getMeanRate() > 0);

    assertEquals("wrong number of meter metrics.", 2, metricRegistry.getMeters().values().size());

    Set<Map.Entry<String, Meter>> entries = metricRegistry.getMeters().entrySet();

    entries.forEach(entry -> {
        if (entry.getKey().endsWith("Metered")) {
            assertEquals(String.format("wrong number of invocations in metric %s", entry.getKey()), 1,
                    entry.getValue().getCount());
        }
    });

}
 
開發者ID:mwiede,項目名稱:metrics-feign,代碼行數:19,代碼來源:FeignOutboundMetricsMethodHandlerTest.java

示例14: onCallbackComplete

import com.codahale.metrics.Timer; //導入依賴的package包/類
public void onCallbackComplete(Operation operation) {
  Long startTime = removeObjectProperty(operation, OPERATION_PROPERTY_NAME);
  if (startTime == null) {
    return;//re-entrant
  }

  String op = Operations.getOperationName(operation);

  long t = clock.getTick() - startTime;
  Timer timer = opVsTimer.computeIfAbsent(op, s -> {
    String metricName = ROOT_NAME.withTags("command", op).toString();
    return RegistryService.getMetricRegistry().timer(metricName);
  });
  timer.update(t, TimeUnit.NANOSECONDS);

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:17,代碼來源:SpymemcachedRuleHelper.java

示例15: onResponseReceived

import com.codahale.metrics.Timer; //導入依賴的package包/類
public void onResponseReceived(HttpRequest request, HttpResponse response) {
  Long startTime = removeObjectProperty(request, START_TIME_PROPERTY_NAME);
  if (startTime == null) {
    return;
  }

  long t = Clock.defaultClock().getTick() - startTime;

  String method = request.getRequestLine().getMethod();
  int statusCode = response.getStatusLine().getStatusCode();

  String metricName = ROOT_NAME.withTags(
      "method", method,
      "status", "" + statusCode).toString();
  Timer timer = RegistryService.getMetricRegistry().timer(metricName);
  timer.update(t, TimeUnit.NANOSECONDS);

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:19,代碼來源:HttpAsyncClientRuleHelper.java


注:本文中的com.codahale.metrics.Timer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。