本文整理汇总了Java中com.yammer.metrics.core.TimerContext类的典型用法代码示例。如果您正苦于以下问题:Java TimerContext类的具体用法?Java TimerContext怎么用?Java TimerContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimerContext类属于com.yammer.metrics.core包,在下文中一共展示了TimerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
/**
* Verify measure publication manually.
*/
public static void main(final String[] args) throws Exception {
final Run run = newRun("test-main");
for (int param = 0; param < 5; param++) {
final CaliperMeasure measure = new CaliperMeasure();
measure.variables().put("param", String.valueOf(param));
for (int step = 0; step < 5; step++) {
measure.rate().mark(50 + step);
final TimerContext time = measure.time().time();
Thread.sleep(15);
time.stop();
measure.size().value(50 + step);
measure.mark();
}
measure.appendTo(run);
}
final Result result = newResult(run);
publish(result);
System.out.println(json(result));
}
示例2: measureGetFuture
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public void measureGetFuture(CompletionStage<GetResult<byte[]>> future) {
final TimerContext ctx = gets.time();
future.whenComplete((result, t) -> {
ctx.stop();
if (t == null) {
getSuccesses.mark();
if (result != null) {
getHits.mark();
} else {
getMisses.mark();
}
} else {
getFailures.mark();
}
});
}
示例3: measureMultigetFuture
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public void measureMultigetFuture(CompletionStage<List<GetResult<byte[]>>> future) {
final TimerContext ctx = multigets.time();
future.whenComplete((result, t) -> {
ctx.stop();
if (t == null) {
multigetSuccesses.mark();
int hits = 0;
int total = result.size();
for (int i = 0; i < total; i++) {
if (result.get(i) != null) {
hits++;
}
}
getHits.mark(hits);
getMisses.mark(total - hits);
} else {
multigetFailures.mark();
}
});
}
示例4: commitTransaction
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public boolean commitTransaction() throws TException {
transactionInProgress = false;
requestMetric.mark();
if(isolationLevel.higherThan(IsolationLevel.NO_ISOLATION)) {
TimerContext timer = latencyBufferedXactMetric.time();
applyWritesInBuffer();
timer.stop();
}
transactionWriteBuffer.clear();
transactionReadBuffer.clear();
return true;
}
示例5: retrievePendingItem
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
public DataItem retrievePendingItem(String key, Version version) throws TException {
TimerContext context = retrievePendingTimer.time();
try {
if (!pendingTransactionsMap.containsKey(version)) {
return null;
}
for (PendingWrite pendingWrite : pendingTransactionsMap.get(version).pendingWrites) {
if (key.equals(pendingWrite.getKey())) {
return getPendingWrite(pendingWrite.getKey(), pendingWrite.getVersion());
}
}
return null;
} finally {
context.stop();
}
}
示例6: put_if_newer
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
/**
* Puts the given value for our key.
* Does not update the value if the key already exists with a later timestamp.
*/
@Override
public void put_if_newer(String key, DataItem value) {
TimerContext context = putsTimer.time();
try {
// TODO: Some form of synchronization is necessary
// synchronized (map) {
// If we already have this key, ensure new item is a more recent version
if (map.containsKey(key)) {
DataItem curItem = map.get(key);
if (curItem.getVersion().compareTo(value.getVersion()) > 0) {
return;
}
}
// New key or newer timestamp.
map.put(key, value);
// }
} finally {
context.stop();
}
}
示例7: get
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
public DataItem get(String key) throws TException {
getCount.mark();
TimerContext context = getLatencyTimer.time();
try {
byte[] byteRet = db.get(key.getBytes());
if(byteRet == null) {
nullGetCount.mark();
return null;
}
getSizeHistogram.update(byteRet.length);
ThriftDataItem tdrRet = new ThriftDataItem();
deserializer.get().deserialize(tdrRet, byteRet);
return new DataItem(tdrRet);
} finally {
context.stop();
}
}
示例8: createReference
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
public void createReference(String owner, String repository, String ref, String id)
throws GithubFailure.forReferenceCreation {
final URI uri = UriBuilder.
fromPath("/repos/{a}/{b}/git/refs").
build(owner, repository);
final ReferenceCreationRequest req = new ReferenceCreationRequest(ref, id);
final TimerContext time = referenceCreationTimer.time();
try {
/* Github wants a Content-Length, and Jersey doesn't fancy doing that */
final byte[] payload = mapper.writeValueAsBytes(req);
resource.uri(uri).
type(MediaType.APPLICATION_JSON_TYPE).
post(payload);
} catch (JsonProcessingException | UniformInterfaceException e) {
throw new GithubFailure.forReferenceCreation(e);
} finally {
time.stop();
}
}
示例9: download
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
public Path download(String owner, String repository, String id)
throws IOException, GithubFailure.forDownload {
final Path tempPath = Files.createTempFile("com.airbnb.chancery-githubdownload-", null);
tempPath.toFile().deleteOnExit();
final URI uri = UriBuilder.
fromPath("/repos/{a}/{b}/tarball/{c}").
build(owner, repository, id);
log.info("Downloading {}", uri);
final TimerContext time = downloadTimer.time();
try {
final InputStream inputStream = resource.uri(uri).
accept(MediaType.WILDCARD_TYPE).
get(InputStream.class);
Files.copy(inputStream, tempPath, StandardCopyOption.REPLACE_EXISTING);
log.info("Downloaded {}", uri);
return tempPath;
} catch (UniformInterfaceException e) {
throw new GithubFailure.forDownload(e);
} finally {
time.stop();
}
}
示例10: upload
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
private void upload(@NotNull File src, @NotNull String key, @NotNull CallbackPayload payload) {
log.info("Uploading {} to {} in {}", src, key, bucketName);
final PutObjectRequest request = new PutObjectRequest(bucketName, key, src);
final ObjectMetadata metadata = request.getMetadata();
final String commitId = payload.getAfter();
if (commitId != null) {
metadata.addUserMetadata("commit-id", commitId);
}
final DateTime timestamp = payload.getTimestamp();
if (timestamp != null) {
metadata.addUserMetadata("hook-timestamp",
ISODateTimeFormat.basicTime().print(timestamp));
}
final TimerContext time = uploadTimer.time();
try {
s3Client.putObject(request);
} catch (Exception e) {
log.error("Couldn't upload to {} in {}", key, bucketName, e);
throw e;
} finally {
time.stop();
}
log.info("Uploaded to {} in {}", key, bucketName);
}
示例11: submit
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public Future submit( final Collection<Count> counts ) {
return executor.submit( new Callable<Object>() {
final TimerContext timer = addTimer.time();
@Override
public Object call() throws Exception {
// TODO perhaps this could be pushed down further into CountProducer Impl?
// - this would leave generic submitter class
for ( Count c : counts ) {
logger.info( "found count {}", c );
}
timer.stop();
return true;
}
} );
}
示例12: handleMessage
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public void handleMessage(DeleteOccurrenceMessage message) {
final TimerContext context = processTimer.time();
// if the deletion reason is NOT_SEEN_IN_LAST_CRAWL, we need to ensure that the record hasn't changed since
final Integer targetedCrawlId = OccurrenceDeletionReason.NOT_SEEN_IN_LAST_CRAWL == message.getDeletionReason() ?
message.getCrawlAttemptLastSeen() : null;
try {
Occurrence deleted = occurrenceDeletionService.deleteOccurrence(message.getOccurrenceKey(), targetedCrawlId);
if (deleted != null) {
try {
messagePublisher.send(OccurrenceMutatedMessage
.buildDeleteMessage(deleted.getDatasetKey(), deleted, message.getDeletionReason(),
message.getCrawlAttemptLastSeen(), message.getLatestCrawlAttemptForDataset()));
} catch (IOException e) {
LOG.error("Unable to send OccurrenceDeletedMessage for key [{}] - ALL DOWNSTREAM COUNTS ARE NOW WRONG",
deleted.getKey(), e);
}
}
} finally {
context.stop();
}
}
示例13: generateKey
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
/**
* Hands off to the member KeyPersistenceService to generate a key for the given uniqueIds.
*
* @param uniqueIdentifiers the identifiers that all refer to the same occurrence
*
* @return a KeyLookupResult with the key for this occurrence
*
* @throws IllegalArgumentException if the uniqueIdentifiers set is empty
*/
@Override
public KeyLookupResult generateKey(Set<UniqueIdentifier> uniqueIdentifiers) {
checkArgument(!uniqueIdentifiers.isEmpty(), "uniqueIdentifiers can't be empty");
String datasetKey = uniqueIdentifiers.iterator().next().getDatasetKey().toString();
Set<String> uniqueStrings = Sets.newHashSetWithExpectedSize(uniqueIdentifiers.size());
for (UniqueIdentifier uniqueIdentifier : uniqueIdentifiers) {
uniqueStrings.add(uniqueIdentifier.getUnscopedUniqueString());
}
lockRequests.mark();
final TimerContext context = lockWaitTimer.time();
try {
return keyPersistenceService.generateKey(uniqueStrings, datasetKey);
} finally {
context.stop();
}
}
示例14: handleMessage
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
@Override
public void handleMessage(DeleteDatasetOccurrencesMessage message) {
if (message.getDeletionReason() == OccurrenceDeletionReason.NOT_SEEN_IN_LAST_CRAWL) {
LOG.warn("No support for deleting datasets because of NOT_SEEN_IN_LAST_CRAWL - ignoring message.");
return;
}
final TimerContext context = processTimer.time();
try {
LOG.info("Deleting dataset for key [{}]", message.getDatasetUuid());
Set<Integer> keys = occurrenceKeyService.findKeysByDataset(message.getDatasetUuid().toString());
for (Integer key : keys) {
try {
messagePublisher.send(new DeleteOccurrenceMessage(key, message.getDeletionReason(), null, null));
} catch (IOException e) {
LOG.warn("Could not send DeleteOccurrenceMessage for key [{}] while deleting dataset [{}]", key,
message.getDatasetUuid(), e);
}
}
} finally {
context.stop();
}
}
示例15: addCounter
import com.yammer.metrics.core.TimerContext; //导入依赖的package包/类
/**
* Atomically adds to the count for this dataset and counterName.
*
* @param datasetUuid the dataset key
* @param counterName the counterName representing a processing phase
*/
public void addCounter(UUID datasetUuid, CounterName counterName) {
checkNotNull(datasetUuid);
checkNotNull(counterName);
final TimerContext context = addTimer.time();
try {
try {
String path = CRAWL_PREFIX + datasetUuid.toString() + counterName.getPath();
LOG.debug("Updating DAL at path [{}]", path);
if (!ENSURED_PATHS.contains(path)) {
curator.newNamespaceAwareEnsurePath(path).ensure(curator.getZookeeperClient());
ENSURED_PATHS.add(path);
}
final TimerContext incContext = incrementTimer.time();
try {
dalWrapper.increment(path);
} finally {
incContext.stop();
}
} catch (Exception e) {
LOG.warn("Error updating zookeeper", e);
}
} finally {
context.stop();
}
}