本文整理汇总了Java中com.google.common.base.Stopwatch.createStarted方法的典型用法代码示例。如果您正苦于以下问题:Java Stopwatch.createStarted方法的具体用法?Java Stopwatch.createStarted怎么用?Java Stopwatch.createStarted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Stopwatch
的用法示例。
在下文中一共展示了Stopwatch.createStarted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unlockMapping
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Unlocks the specified mapping
*
* @param mapping
* Input range mapping.
* @param mappingLockToken
* An instance of <see cref="MappingLockToken"/>
*/
public void unlockMapping(RangeMapping mapping,
MappingLockToken mappingLockToken) {
ExceptionUtils.disallowNullArgument(mapping, "mapping");
ExceptionUtils.disallowNullArgument(mappingLockToken, "mappingLockToken");
try (ActivityIdScope activityIdScope = new ActivityIdScope(UUID.randomUUID())) {
UUID lockOwnerId = mappingLockToken.getLockOwnerId();
log.info("Unlock Start; LockOwnerId: {}", lockOwnerId);
Stopwatch stopwatch = Stopwatch.createStarted();
this.rsm.lockOrUnlockMappings(mapping, lockOwnerId, LockOwnerIdOpType.UnlockMappingForId);
stopwatch.stop();
log.info("UnLock Complete; Duration: {}; StoreLockOwnerId: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS), lockOwnerId);
}
}
示例2: createRangeShardMap
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Create a range based <see cref="RangeShardMap{KeyT}"/>. <typeparam name="KeyT">Type of keys.</typeparam>
*
* @param shardMapName
* Name of shard map.
* @return Range shard map with the specified name.
*/
public <KeyT> RangeShardMap<KeyT> createRangeShardMap(String shardMapName,
ShardKeyType keyType) {
ShardMapManager.validateShardMapName(shardMapName);
try (ActivityIdScope activityIdScope = new ActivityIdScope(UUID.randomUUID())) {
StoreShardMap dssm = new StoreShardMap(UUID.randomUUID(), shardMapName, ShardMapType.Range, keyType);
log.info("ShardMapManager CreateRangeShardMap Start; ShardMap: {}", shardMapName);
Stopwatch stopwatch = Stopwatch.createStarted();
this.addShardMapToStore("CreateRangeShardMap", dssm);
stopwatch.stop();
log.info("ShardMapManager CreateRangeShardMap Added ShardMap to Store; ShardMap: {}; Duration: {}", shardMapName,
stopwatch.elapsed(TimeUnit.MILLISECONDS));
log.info("ShardMapManager CreateRangeShardMap Complete; ShardMap: {} Duration: {}", shardMapName,
stopwatch.elapsed(TimeUnit.MILLISECONDS));
return new RangeShardMap<>(this, dssm);
}
}
示例3: lockMapping
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Locks the mapping for the specified owner The state of a locked mapping can only be modified by the lock owner.
*
* @param mapping
* Input range mapping.
* @param mappingLockToken
* An instance of <see cref="MappingLockToken"/>
*/
public void lockMapping(RangeMapping mapping,
MappingLockToken mappingLockToken) {
ExceptionUtils.disallowNullArgument(mapping, "mapping");
ExceptionUtils.disallowNullArgument(mappingLockToken, "mappingLockToken");
try (ActivityIdScope activityIdScope = new ActivityIdScope(UUID.randomUUID())) {
// Generate a lock owner id
UUID lockOwnerId = mappingLockToken.getLockOwnerId();
log.info("Lock Start; LockOwnerId: {}", lockOwnerId);
Stopwatch stopwatch = Stopwatch.createStarted();
this.rsm.lockOrUnlockMappings(mapping, lockOwnerId, LockOwnerIdOpType.Lock);
stopwatch.stop();
log.info("Lock Complete; Duration: {}; StoreLockOwnerId: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS), lockOwnerId);
}
}
示例4: tryGetMappingForKey
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Tries to looks up the key value and place the corresponding mapping in <paramref name="rangeMapping"/>.
*
* @param key
* Input key value.
* @param lookupOptions
* Whether to search in the cache and/or store.
* @param rangeMapping
* Mapping that contains the key value.
* @return <c>true</c> if mapping is found, <c>false</c> otherwise.
*/
public boolean tryGetMappingForKey(KeyT key,
LookupOptions lookupOptions,
ReferenceObjectHelper<RangeMapping> rangeMapping) {
try (ActivityIdScope activityIdScope = new ActivityIdScope(UUID.randomUUID())) {
log.info("TryLookupRangeMapping Start; ShardMap name: {}; Range Mapping Key Type: {}; Lookup " + "Options: {}", this.getName(),
key.getClass(), lookupOptions);
Stopwatch stopwatch = Stopwatch.createStarted();
boolean result = this.rsm.tryLookup(key, lookupOptions, rangeMapping);
stopwatch.stop();
log.info("TryLookupRangeMapping Complete; ShardMap name: {}; Range Mapping Key Type: {}; " + "Lookup Options: {}; Duration: {}",
this.getName(), key.getClass(), lookupOptions, stopwatch.elapsed(TimeUnit.MILLISECONDS));
return result;
}
}
示例5: checkCandidates
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
private List<SimpleInd> checkCandidates(List<SimpleInd> candidates) {
Stopwatch sw = Stopwatch.createStarted();
List<SimpleInd> result = new ArrayList<>();
logger.info("checking: {} candidates on level {}", candidates.size(),
candidates.get(0).size());
int candidateCount = 0;
for (SimpleInd candidate : candidates) {
if (inclusionTester.isIncludedIn(candidate.left, candidate.right)) {
result.add(candidate); // add result
}
candidateCount++;
if ((candidates.size() > 1000 && candidateCount % (candidates.size() / 20) == 0) ||
(candidates.size() <= 1000 && candidateCount % 100 == 0)) {
logger.info("{}/{} candidates checked", candidateCount, candidates.size());
}
}
logger.info("Time checking candidates on level {}: {}ms, INDs found: {}",
candidates.get(0).size(),
sw.elapsed(TimeUnit.MILLISECONDS), result.size());
return result;
}
示例6: getMappings
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Gets all the range mappings that exist for the given shard.
*
* @param shard
* Shard for which the mappings will be returned.
* @param lookupOptions
* Whether to search in the cache and/or store.
* @return Read-only collection of mappings that satisfy the given shard constraint.
*/
public List<RangeMapping> getMappings(Shard shard,
LookupOptions lookupOptions) {
ExceptionUtils.disallowNullArgument(shard, "shard");
try (ActivityIdScope activityIdScope = new ActivityIdScope(UUID.randomUUID())) {
log.info("GetMappings Start; Shard: {}; Lookup Options: {}", shard.getLocation(), lookupOptions);
Stopwatch stopwatch = Stopwatch.createStarted();
List<RangeMapping> rangeMappings = this.rsm.getMappingsForRange(null, shard, lookupOptions);
stopwatch.stop();
log.info("GetMappings Complete; Shard: {}; Lookup Options: {}; Duration: {}", shard.getLocation(), lookupOptions,
stopwatch.elapsed(TimeUnit.MILLISECONDS));
return rangeMappings;
}
}
示例7: verifyCandidates
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
private static void verifyCandidates(final AbstractDataStore dataStore, final DOMEntity entity,
final String... expCandidates) throws Exception {
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.MILLISECONDS) <= 10000) {
Optional<NormalizedNode<?, ?>> possible = dataStore.newReadOnlyTransaction()
.read(entityPath(entity.getType(), entity.getIdentifier()).node(Candidate.QNAME))
.get(5, TimeUnit.SECONDS);
try {
assertEquals("Candidates not found for " + entity, true, possible.isPresent());
Collection<String> actual = new ArrayList<>();
for (MapEntryNode candidate: ((MapNode)possible.get()).getValue()) {
actual.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
}
assertEquals("Candidates for " + entity, Arrays.asList(expCandidates), actual);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
示例8: waitForMembersUp
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
public void waitForMembersUp(final String... otherMembers) {
Set<String> otherMembersSet = Sets.newHashSet(otherMembers);
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
CurrentClusterState state = Cluster.get(getSystem()).state();
for (Member m: state.getMembers()) {
if (m.status() == MemberStatus.up() && otherMembersSet.remove(m.getRoles().iterator().next())
&& otherMembersSet.isEmpty()) {
return;
}
}
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
fail("Member(s) " + otherMembersSet + " are not Up");
}
示例9: executeMapOperations
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
private static <T> Result executeMapOperations(String message,
List<T> items,
Func1Param<T, T> keySelector,
Action1Param<T> a) {
Result result = new Result();
int latestWrittenCount = Integer.MIN_VALUE;
int maxCount = items.size();
Stopwatch sw;
for (T item : items) {
int percentComplete = (result.count * 100) / maxCount;
if (percentComplete / 10 > latestWrittenCount / 10) {
latestWrittenCount = percentComplete;
System.out.printf("%1$s %2$s/%3$s (%4$s)%%" + "\r\n", message, item, Collections.max(items, null), percentComplete);
}
T key = keySelector.invoke(item);
sw = Stopwatch.createStarted();
a.invoke(key);
sw.stop();
result.count++;
result.totalTicks += sw.elapsed(TimeUnit.MILLISECONDS);
}
return result;
}
示例10: lookupShardMapByName
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Finds a shard map from cache if requested and if necessary from global shard map.
*
* @param operationName
* Operation name, useful for diagnostics.
* @param shardMapName
* Name of shard map.
* @param lookInCacheFirst
* Whether to skip first lookup in cache.
* @return Shard map object corresponding to one being searched.
*/
public ShardMap lookupShardMapByName(String operationName,
String shardMapName,
boolean lookInCacheFirst) {
StoreShardMap ssm = null;
if (lookInCacheFirst) {
// Typical scenario will result in immediate lookup succeeding.
ssm = this.getCache().lookupShardMapByName(shardMapName);
}
ShardMap shardMap;
// Cache miss. Go to store and add entry to cache.
if (ssm == null) {
Stopwatch stopwatch = Stopwatch.createStarted();
shardMap = this.lookupShardMapByNameInStore(operationName, shardMapName);
stopwatch.stop();
log.info("Lookup ShardMap: {} in store complete; Duration: {}", shardMapName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
else {
shardMap = ShardMapUtils.createShardMapFromStoreShardMap(this, ssm);
}
return shardMap;
}
示例11: writeCsv
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
public void writeCsv(Writer writer, char separator, ZoneId zoneId) {
Objects.requireNonNull(writer);
Objects.requireNonNull(zoneId);
Stopwatch stopWatch = Stopwatch.createStarted();
try {
CsvConfig config = new CsvConfig(separator, DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(zoneId));
writeHeader(writer, config);
// read time series in the doubleBuffer per 10 points chunk to avoid cache missed and improve performances
CsvCache cache = new CsvCache();
// write data
for (int version = fromVersion; version <= toVersion; version++) {
for (int point = 0; point < tableIndex.getPointCount(); point += CsvCache.CACHE_SIZE) {
int cachedPoints = Math.min(CsvCache.CACHE_SIZE, tableIndex.getPointCount() - point);
// copy from doubleBuffer to cache
fillCache(point, cache, cachedPoints, version);
// then write cache to CSV
dumpCache(writer, config, point, cache, cachedPoints, version);
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
LOGGER.info("Csv written in {} ms", stopWatch.elapsed(TimeUnit.MILLISECONDS));
}
示例12: testOldCallWithTimeout_badCallableWithNotEnoughTime
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
@Deprecated
public void testOldCallWithTimeout_badCallableWithNotEnoughTime() throws Exception {
Stopwatch stopwatch = Stopwatch.createStarted();
try {
service.callWithTimeout(BAD_CALLABLE, NOT_ENOUGH_MS, MILLISECONDS, true /* interruptible */);
fail("no exception thrown");
} catch (UncheckedTimeoutException expected) {
}
assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(NOT_ENOUGH_MS, DELAY_MS * 2));
}
示例13: deriveKey
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
* Generate AES key.
*
* This is a very slow operation compared to encrypt/ decrypt so it is normally worth caching the result.
*
* @param password The password to use in key generation
* @return The KeyParameter containing the created AES key
* @throws KeyCrypterException
*/
@Override
public KeyParameter deriveKey(CharSequence password) throws KeyCrypterException {
byte[] passwordBytes = null;
try {
passwordBytes = convertToByteArray(password);
byte[] salt = new byte[0];
if ( scryptParameters.getSalt() != null) {
salt = scryptParameters.getSalt().toByteArray();
} else {
// Warn the user that they are not using a salt.
// (Some early MultiBit wallets had a blank salt).
log.warn("You are using a ScryptParameters with no salt. Your encryption may be vulnerable to a dictionary attack.");
}
final Stopwatch watch = Stopwatch.createStarted();
byte[] keyBytes = SCrypt.scrypt(passwordBytes, salt, (int) scryptParameters.getN(), scryptParameters.getR(), scryptParameters.getP(), KEY_LENGTH);
watch.stop();
log.info("Deriving key took {} for {} scrypt iterations.", watch, scryptParameters.getN());
return new KeyParameter(keyBytes);
} catch (Exception e) {
throw new KeyCrypterException("Could not generate key from password and salt.", e);
} finally {
// Zero the password bytes.
if (passwordBytes != null) {
java.util.Arrays.fill(passwordBytes, (byte) 0);
}
}
}
示例14: queryApi
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
protected JSONObject queryApi() {
String baseUrl = apiAccess.getApiUrl() + requestUrl;
log.info("Sending API request [ Method: " + requestMethod + " ] [ URL: " + baseUrl + " ] [ Arguments: " + requiredArgs + " ]");
JSONObject responseJson = null;
Stopwatch timer = Stopwatch.createStarted();
try {
HttpResponse response = null;
if(requestMethod == ERequestMethod.GET) {
String url = HttpHelpers.appendUrlParameters(baseUrl, requiredArgs);
response = httpClient.doGet(url);
} else if(requestMethod == ERequestMethod.POST) {
JSONObject postBody = new JSONObject(requiredArgs);
response = httpClient.doPost(baseUrl, MediaType.JSON_UTF_8, postBody.toString(), null);
}
responseJson = HttpClient.getResponseAsJson(response);
} catch (HttpClientRequestFailedException e) {
log.error("Failed to send request! Error - " + e.getMessage(), e);
responseJson = new JSONObject()
.put("success", false)
.put("exception", e.getMessage());
}
log.info("API response received [ Method: " + requestMethod + " ] [ URL: " + baseUrl + " ] [ In Flight: " + timer.stop() + " ]");
return responseJson;
}
示例15: run
import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
public void run() {
File file = new File(filename);
Stopwatch stopwatch = Stopwatch.createStarted();
Multimap<Long, Long> wayByRelations = ArrayListMultimap.create();
Multimap<Long, Integer> borderNodeTargets = ArrayListMultimap.create();
firstPass(file, wayByRelations, borderNodeTargets);
finalPass(wayByRelations, borderNodeTargets, file);
kml.close();
log.info("time: {}s", stopwatch.elapsed(SECONDS));
}