本文整理汇总了Java中com.codahale.metrics.Timer.Context.stop方法的典型用法代码示例。如果您正苦于以下问题:Java Context.stop方法的具体用法?Java Context.stop怎么用?Java Context.stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codahale.metrics.Timer.Context
的用法示例。
在下文中一共展示了Context.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allLinks
import com.codahale.metrics.Timer.Context; //导入方法依赖的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();
}
}
示例2: onEvent
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Override
public void onEvent(final TSDBMetricMeta meta, final long sequence, final boolean endOfBatch) throws Exception {
final Context ctx = dispatchHandlerTimer.time();
try {
if(outQueueTextFormat) {
outQueue.acquireAppender().writeDocument(w -> w.write(MessageType.METRICMETA.shortName).marshallable(meta));
} else {
outQueue.acquireAppender().writeBytes(meta);
}
cacheDb.add(meta.getTsuid());
meta.recordTimer(endToEndTimer);
} finally {
meta.reset();
ctx.stop();
}
}
示例3: testRedisRateLimit
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Test
public void testRedisRateLimit() throws InterruptedException {
reporter.start(3, TimeUnit.SECONDS);
ApplicationContext ac = new ClassPathXmlApplicationContext("root-context.xml");
JedisPool pool = (JedisPool) ac.getBean("jedisPool");
RedisRateLimiter limiter = new RedisRateLimiter(pool, TimeUnit.MINUTES, 300);
while (true) {
boolean flag = false;
Context context = timer.time();
if(limiter.acquire("testMKey1")) {
flag = true;
}
context.stop();
if (flag) {
requests.mark();
}
Thread.sleep(1);
}
}
示例4: nextURL
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
public LinkRelevance nextURL(boolean asyncLoad) throws FrontierPersistentException, DataNotFoundException {
Context timerContext = selectTimer.time();
try {
LinkRelevance link = scheduler.nextLink(asyncLoad);
if (link == null) {
if (scheduler.hasPendingLinks()) {
throw new DataNotFoundException(false, "No links available for selection right now.");
} else {
throw new DataNotFoundException(true, "Frontier run out of links.");
}
}
frontier.delete(link);
schedulerLog.printf("%d\t%.5f\t%s\n", System.currentTimeMillis(),
link.getRelevance(), link.getURL().toString());
return link;
} finally {
timerContext.stop();
}
}
示例5: startTimer
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
private void startTimer(final MetricGroup metricGroup, final String infixValue, final Exchange exchange) {
Map<String, Context> timerContextMap = getTimerContextMap(exchange);
if (timerContextMap != null) {
String fullTimerName;
if (infixValue != null) {
fullTimerName = MetricRegistry.name(this.endpoint.getName(), infixValue, this.endpoint.getTimingName());
} else {
fullTimerName = MetricRegistry.name(this.endpoint.getName(), this.endpoint.getTimingName());
}
// stop previous context if it exists
Context timerContext = timerContextMap.get(fullTimerName);
if (timerContext != null) {
timerContext.stop();
}
// start new context
timerContext = metricGroup.getTimer().time();
timerContextMap.put(fullTimerName, timerContext);
} else {
LOGGER.warn(MARKER, "timerContextMap is null, timing will not be recorded correctly");
}
}
示例6: stopTimer
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
/**
* @param infixValue
* @param exchange
*/
private void stopTimer(final String infixValue, final Exchange exchange) {
Map<String, Context> timerContextMap = getTimerContextMap(exchange);
if (timerContextMap != null) {
String fullTimerName;
if (infixValue != null) {
fullTimerName = MetricRegistry.name(this.endpoint.getName(), infixValue, this.endpoint.getTimingName());
} else {
fullTimerName = MetricRegistry.name(this.endpoint.getName(), this.endpoint.getTimingName());
}
// stop previous context if it exists
Context timerContext = timerContextMap.get(fullTimerName);
if (timerContext != null) {
timerContext.stop();
}
} else {
LOGGER.warn(MARKER, "timerContextMap is null, timing will not be recorded correctly");
}
}
示例7: testTraversalPerformance
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Test
public void testTraversalPerformance() {
TinkerGraph t = TinkerGraphFactory.createTinkerGraph();
FramedGraph f = new FramedGraph(t);
Timer timer = metrics.timer("gremlin");
Context time = timer.time();
for (int count = 0; count < iterations; count++) {
GremlinPipeline g = new GremlinPipeline(t);
g.V().both().both().both().toList();
}
long nanoseconds = time.stop();
System.out.println("Iterate over all GremlinPipeline " + nanoseconds / 1000000);
time = timer.time();
for (int count = 0; count < iterations; count++) {
f.V().both().both().both().toList();
}
nanoseconds = time.stop();
System.out.println("Iterate over all Totorom " + nanoseconds / 1000000);
}
示例8: testOpenCloseConnections
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Test
public void testOpenCloseConnections() throws SQLException {
for (int i = 0; i < MAX_ITERATIONS; i++) {
Context context = timer.time();
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.executeQuery("select * from city");
conn.close();
context.stop();
}
logReporter.report();
}
示例9: testTimerTime
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Test
public void testTimerTime() throws Exception {
Timer a = registry.timer("B");
Context context = a.time();
context.stop();
assertEquals(a, updatedMetric);
}
示例10: index
import com.codahale.metrics.Timer.Context; //导入方法依赖的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();
}
}
示例11: allBuilds
import com.codahale.metrics.Timer.Context; //导入方法依赖的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();
}
}
示例12: reportTimer
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
/**
* A timer measures both the rate that a particular piece of code is called and the distribution
* of its duration. For example we want to measure the rate and handling duration of incoming
* requests.
*/
private static void reportTimer() {
// Create or fetch (if it is already created) the metric.
final Timer timer = registry.timer(
APP_PREFIX.tagged("what", "incoming-request-time").tagged("endpoint", "/v1/get_stuff"));
// Do this before starting to do the thing. This creates a measurement context object
// that you can pass around.
final Context context = timer.time();
// Do stuff that takes time (e.g., process the request)
try {
Thread.sleep(100);
} catch (final InterruptedException e) {
e.printStackTrace();
}
// Tell the context that it's done. This will register the duration and counts one
// occurrence.
context.stop();
// That's it! The rest will be automatically done inside semantic metrics library. The
// reported measurements will be kept in the registry.
// Every time the reporter wants to report, different stats and aggregations (all the
// stats that you would get from a meter and a histogram are included) will be calculated
// and
// datapoints will be created and reported.
}
示例13: accept
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Override
public void accept(Task task) {
checkPreconditions();
Timer executeTimer = metricRegistry
.timer(name(RedisTaskQueueConsumer.class, "execute"));
Context context = executeTimer.time();
TaskState taskState = task.getTaskState();
TaskConfiguration taskConfiguration = task.getTaskConfiguration();
BackgroundTask runningTask;
try {
runningTask = taskState.taskClass().newInstance();
runningTask.initialize(taskConfiguration, config, factory,
metricRegistry, postProcessor);
metricRegistry.meter(name(RedisTaskQueueConsumer.class, "initialized")).mark();
if (taskShouldResume(task)) {
// Not implemented
throw new NotImplementedException();
} else {
runningTask.start();
metricRegistry.meter(name(RedisTaskQueueConsumer.class, "run")).mark();
}
} catch (IllegalAccessException | InstantiationException e) {
metricRegistry.meter(name(RedisTaskQueueConsumer.class, "failed")).mark();
LOG.error("{} had an instantiantion exception", task.getTaskState().getId(), e);
throw new RuntimeException(e);
} catch (RuntimeException throwable) {
metricRegistry.meter(name(RedisTaskQueueConsumer.class, "failed")).mark();
LOG.error("{} could not be completed successfully", task.getTaskState().getId(), throwable);
throw new RuntimeException(throwable);
} finally {
context.stop();
}
}
示例14: timed
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
@Override
public <T, R> R timed(Function<T, R> f, T arg, String timerName) {
final Context context = getNamedTimer(timerName).time();
try {
return f.apply(arg);
}
finally {
context.stop();
}
}
示例15: time
import com.codahale.metrics.Timer.Context; //导入方法依赖的package包/类
protected Object time(Executable executable, Invocation invocation) throws Throwable {
Context context = getTimer(executable).time();
try {
return invocation.proceed();
} finally {
context.stop();
}
}