本文整理了Java中org.apache.brooklyn.util.time.Time.hasElapsedSince()
方法的一些代码示例,展示了Time.hasElapsedSince()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Time.hasElapsedSince()
方法的具体详情如下:
包路径:org.apache.brooklyn.util.time.Time
类名称:Time
方法名:hasElapsedSince
[英]true iff it has been longer than the given duration since the given timestamp
[中]如果为true,则自给定时间戳以来,它已超过给定的持续时间
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static boolean isSudoAllowed() {
if (Time.hasElapsedSince(lastSudoCheckTime, Duration.FIVE_MINUTES))
checkIfNeeded();
return lastSudoResult;
}
private static synchronized void checkIfNeeded() {
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
private static synchronized void checkIfNeeded() {
if (Time.hasElapsedSince(lastSudoCheckTime, Duration.FIVE_MINUTES)) {
try {
lastSudoResult = new ProcessTool().execCommands(MutableMap.<String,Object>of(), Arrays.asList(
BashCommands.sudo("date"))) == 0;
} catch (Exception e) {
lastSudoResult = false;
LOG.debug("Error checking sudo at localhost: "+e, e);
}
lastSudoCheckTime = System.currentTimeMillis();
}
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
@Test
public void testElapsedSince() {
long aFewSecondsAgo = System.currentTimeMillis() - 7*1000;
Duration aFewSeconds = Time.elapsedSince(aFewSecondsAgo);
Assert.assertTrue(aFewSeconds.toMilliseconds() > 5*1000);
Assert.assertTrue(10*1000 > aFewSeconds.toMilliseconds());
Assert.assertTrue(Time.hasElapsedSince(aFewSecondsAgo, Duration.FIVE_SECONDS));
Assert.assertFalse(Time.hasElapsedSince(aFewSecondsAgo, Duration.TEN_SECONDS));
Assert.assertTrue(Time.hasElapsedSince(-1, Duration.TEN_SECONDS));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp
protected void refreshGroupMembership() {
try {
if (log.isDebugEnabled()) log.debug("GeoDns {} refreshing targets", this);
if (targetEntityProvider == null)
return;
if (targetEntityProvider instanceof DynamicGroup)
((DynamicGroup) targetEntityProvider).rescanEntities();
Set<Entity> pool = MutableSet.copyOf(targetEntityProvider instanceof Group ? targetEntityProvider.getMembers(): targetEntityProvider.getChildren());
if (log.isDebugEnabled()) log.debug("GeoDns {} refreshing targets, pool now {}", this, pool);
boolean changed = false;
boolean filterForRunning = Boolean.TRUE.equals(config().get(FILTER_FOR_RUNNING));
Set<Entity> previousOnes = MutableSet.copyOf(targetHosts.keySet());
for (Entity e: pool) {
if (!filterForRunning || Lifecycle.RUNNING.equals(e.sensors().get(Attributes.SERVICE_STATE_ACTUAL))) {
previousOnes.remove(e);
changed |= addTargetHost(e);
}
}
// anything left in previousOnes is no longer applicable
for (Entity e: previousOnes) {
changed |= removeTargetHost(e, false);
}
// do a periodic full update hourly once we are active (the latter is probably not needed)
if (changed || (lastUpdate > 0 && Time.hasElapsedSince(lastUpdate, Duration.ONE_HOUR))) {
update();
}
} catch (Exception e) {
log.error("Problem refreshing group membership: "+e, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!