当前位置: 首页>>代码示例>>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;未经允许,请勿转载。